Skip to content

Commit 07b4e7e

Browse files
added seed_distance to parameters of mitochondria segmentation (#93)
Add seed_distance and block_shape to parameters of mitochondria segmentation --------- Co-authored-by: Constantin Pape <constantin.pape@informatik.uni-goettingen.de>
1 parent 9847f1b commit 07b4e7e

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

environment.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ dependencies:
1515
- torch_em
1616
- torchvision
1717
- trimesh
18+
- zarr < 3
1819
- pip:
1920
- napari-skimage-regionprops

synapse_net/inference/mitochondria.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ def _run_segmentation(
1212
foreground, boundaries, verbose, min_size,
1313
# blocking shapes for parallel computation
1414
block_shape=(128, 256, 256),
15-
halo=(48, 48, 48)
15+
halo=(48, 48, 48),
16+
seed_distance=6
1617
):
1718
t0 = time.time()
1819
boundary_threshold = 0.25
@@ -24,19 +25,11 @@ def _run_segmentation(
2425

2526
# Get the segmentation via seeded watershed.
2627
t0 = time.time()
27-
seed_distance = 6
2828
seeds = np.logical_and(foreground > 0.5, dist > seed_distance)
2929
seeds = parallel.label(seeds, block_shape=block_shape, verbose=verbose)
3030
if verbose:
3131
print("Compute connected components in", time.time() - t0, "s")
3232

33-
# import napari
34-
# v = napari.Viewer()
35-
# v.add_image(boundaries)
36-
# v.add_image(dist)
37-
# v.add_labels(seeds)
38-
# napari.run()
39-
4033
t0 = time.time()
4134
hmap = boundaries + ((dist.max() - dist) / dist.max())
4235
mask = (foreground + boundaries) > 0.5
@@ -65,6 +58,9 @@ def segment_mitochondria(
6558
return_predictions: bool = False,
6659
scale: Optional[List[float]] = None,
6760
mask: Optional[np.ndarray] = None,
61+
seed_distance: int = 6,
62+
ws_block_shape: Tuple[int, ...] = (128, 256, 256),
63+
ws_halo: Tuple[int, ...] = (48, 48, 48),
6864
) -> Union[np.ndarray, Tuple[np.ndarray, np.ndarray]]:
6965
"""Segment mitochondria in an input volume.
7066
@@ -79,6 +75,9 @@ def segment_mitochondria(
7975
return_predictions: Whether to return the predictions (foreground, boundaries) alongside the segmentation.
8076
scale: The scale factor to use for rescaling the input volume before prediction.
8177
mask: An optional mask that is used to restrict the segmentation.
78+
seed_distance: The distance threshold for the seeded watershed.
79+
ws_block_shape: The block shape for the seeded watershed.
80+
ws_halo: The halo for the seeded watershed.
8281
8382
Returns:
8483
The segmentation mask as a numpy array, or a tuple containing the segmentation mask
@@ -97,7 +96,8 @@ def segment_mitochondria(
9796

9897
# Run segmentation and rescale the result if necessary.
9998
foreground, boundaries = pred[:2]
100-
seg = _run_segmentation(foreground, boundaries, verbose=verbose, min_size=min_size)
99+
seg = _run_segmentation(foreground, boundaries, verbose=verbose, min_size=min_size, seed_distance=seed_distance,
100+
block_shape=ws_block_shape, halo=ws_halo)
101101
seg = scaler.rescale_output(seg, is_segmentation=True)
102102

103103
if return_predictions:

0 commit comments

Comments
 (0)