Skip to content

Commit 1bbc7e6

Browse files
committed
merge nucleus_detector
1 parent 87a8265 commit 1bbc7e6

File tree

1 file changed

+1
-50
lines changed

1 file changed

+1
-50
lines changed

tiatoolbox/models/engine/nucleus_detector.py

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,19 @@
5050
import tempfile
5151
from pathlib import Path
5252
from typing import TYPE_CHECKING
53-
import tempfile
5453

5554
import dask.array as da
5655
import numpy as np
5756
from dask import compute
5857
from dask.diagnostics.progress import ProgressBar
5958
from shapely.geometry import Point
60-
import zarr
6159

6260
from tiatoolbox import logger
6361
from tiatoolbox.annotation.storage import Annotation, SQLiteStore
6462
from tiatoolbox.models.engine.semantic_segmentor import (
6563
SemanticSegmentor,
6664
SemanticSegmentorRunParams,
6765
)
68-
from dask import compute, delayed
69-
from dask.diagnostics.progress import ProgressBar
7066
from tiatoolbox.utils.misc import get_tqdm
7167

7268
if TYPE_CHECKING: # pragma: no cover
@@ -121,8 +117,6 @@ class NucleusDetectorRunParams(SemanticSegmentorRunParams, total=False):
121117
postproc_tile_shape (tuple[int, int]):
122118
Tile shape (height, width) used during post-processing
123119
(in pixels) to control rechunking behavior.
124-
cache_dir (str or os.PathLike):
125-
Directory for caching intermediate results during WSI processing.
126120
return_labels (bool):
127121
Whether to return labels with predictions.
128122
return_probabilities (bool):
@@ -141,7 +135,6 @@ class NucleusDetectorRunParams(SemanticSegmentorRunParams, total=False):
141135
threshold_abs: float
142136
threshold_rel: float
143137
postproc_tile_shape: IntPair
144-
cache_dir: str | os.PathLike
145138

146139

147140
class NucleusDetector(SemanticSegmentor):
@@ -718,48 +711,6 @@ def _save_predictions_annotation_store(
718711
save_path=save_path,
719712
class_dict=class_dict,
720713
)
721-
722-
@staticmethod
723-
def _extract_nonzero(block:np.ndarray, block_info: dict| None = None):
724-
"""Extract non-zero detections from a block with global coordinates.
725-
726-
Args:
727-
block: Input block array of shape (H, W, C).
728-
block_info: Dask block information containing array location.
729-
730-
Returns:
731-
2D array of shape (N, 4) where each row is [y, x, class, prob].
732-
If no detections, returns array of shape (0, 4).
733-
734-
"""
735-
# Local indices within this chunk
736-
ys, xs, classes = np.nonzero(block)
737-
probs = block[ys, xs, classes]
738-
739-
# Get chunk offset from block_info
740-
if block_info is not None:
741-
info = block_info[0]
742-
locs = info["array-location"]
743-
y_offset = locs[0][0]
744-
x_offset = locs[1][0]
745-
746-
# Adjust to global coordinates
747-
ys = ys + y_offset
748-
xs = xs + x_offset
749-
750-
# Stack into (N, 4) array: [y, x, class, prob]
751-
if len(ys) > 0:
752-
result = np.column_stack([
753-
ys.astype(np.uint32),
754-
xs.astype(np.uint32),
755-
classes.astype(np.uint32),
756-
probs.astype(np.float32)
757-
])
758-
else:
759-
# Return empty array with correct shape
760-
result = np.empty((0, 4), dtype=np.float32)
761-
762-
return result
763714

764715
@staticmethod
765716
def _centroid_maps_to_detection_arrays(
@@ -1189,4 +1140,4 @@ class names.
11891140
"Temporary zarr directory %s has been removed.", item
11901141
)
11911142

1192-
return output
1143+
return output

0 commit comments

Comments
 (0)