@@ -12,7 +12,8 @@ def _run_segmentation(
12
12
foreground , boundaries , verbose , min_size ,
13
13
# blocking shapes for parallel computation
14
14
block_shape = (128 , 256 , 256 ),
15
- halo = (48 , 48 , 48 )
15
+ halo = (48 , 48 , 48 ),
16
+ seed_distance = 6
16
17
):
17
18
t0 = time .time ()
18
19
boundary_threshold = 0.25
@@ -24,19 +25,11 @@ def _run_segmentation(
24
25
25
26
# Get the segmentation via seeded watershed.
26
27
t0 = time .time ()
27
- seed_distance = 6
28
28
seeds = np .logical_and (foreground > 0.5 , dist > seed_distance )
29
29
seeds = parallel .label (seeds , block_shape = block_shape , verbose = verbose )
30
30
if verbose :
31
31
print ("Compute connected components in" , time .time () - t0 , "s" )
32
32
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
-
40
33
t0 = time .time ()
41
34
hmap = boundaries + ((dist .max () - dist ) / dist .max ())
42
35
mask = (foreground + boundaries ) > 0.5
@@ -65,6 +58,9 @@ def segment_mitochondria(
65
58
return_predictions : bool = False ,
66
59
scale : Optional [List [float ]] = None ,
67
60
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 ),
68
64
) -> Union [np .ndarray , Tuple [np .ndarray , np .ndarray ]]:
69
65
"""Segment mitochondria in an input volume.
70
66
@@ -79,6 +75,9 @@ def segment_mitochondria(
79
75
return_predictions: Whether to return the predictions (foreground, boundaries) alongside the segmentation.
80
76
scale: The scale factor to use for rescaling the input volume before prediction.
81
77
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.
82
81
83
82
Returns:
84
83
The segmentation mask as a numpy array, or a tuple containing the segmentation mask
@@ -97,7 +96,8 @@ def segment_mitochondria(
97
96
98
97
# Run segmentation and rescale the result if necessary.
99
98
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 )
101
101
seg = scaler .rescale_output (seg , is_segmentation = True )
102
102
103
103
if return_predictions :
0 commit comments