@@ -13,10 +13,11 @@ def _run_segmentation(
1313    # blocking shapes for parallel computation 
1414    block_shape = (128 , 256 , 256 ),
1515    halo = (48 , 48 , 48 ),
16-     seed_distance = 6 
16+     seed_distance = 6 ,
17+     boundary_threshold = 0.25 ,
18+     area_threshold = 5000 ,
1719):
1820    t0  =  time .time ()
19-     boundary_threshold  =  0.25 
2021    dist  =  parallel .distance_transform (
2122        boundaries  <  boundary_threshold , halo = halo , verbose = verbose , block_shape = block_shape 
2223    )
@@ -43,7 +44,7 @@ def _run_segmentation(
4344        print ("Compute watershed in" , time .time () -  t0 , "s" )
4445
4546    seg  =  apply_size_filter (seg , min_size , verbose = verbose , block_shape = block_shape )
46-     seg  =  _postprocess_seg_3d (seg , area_threshold = 5000 )
47+     seg  =  _postprocess_seg_3d (seg , area_threshold = area_threshold )
4748    return  seg 
4849
4950
@@ -61,6 +62,8 @@ def segment_mitochondria(
6162    seed_distance : int  =  6 ,
6263    ws_block_shape : Tuple [int , ...] =  (128 , 256 , 256 ),
6364    ws_halo : Tuple [int , ...] =  (48 , 48 , 48 ),
65+     boundary_threshold : float  =  0.25 ,
66+     area_threshold : int  =  5000 ,
6467) ->  Union [np .ndarray , Tuple [np .ndarray , np .ndarray ]]:
6568    """Segment mitochondria in an input volume. 
6669
@@ -78,6 +81,9 @@ def segment_mitochondria(
7881        seed_distance: The distance threshold for the seeded watershed. 
7982        ws_block_shape: The block shape for the seeded watershed. 
8083        ws_halo: The halo for the seeded watershed. 
84+         boundary_threshold: The boundary threshold distance calculation. 
85+         area_threshold: The maximum area (in pixels) of holes to be removed or filled in the segmentation. 
86+             This parameter is passed to `skimage.morphology.remove_small_holes`. 
8187
8288    Returns: 
8389        The segmentation mask as a numpy array, or a tuple containing the segmentation mask 
@@ -97,7 +103,8 @@ def segment_mitochondria(
97103    # Run segmentation and rescale the result if necessary. 
98104    foreground , boundaries  =  pred [:2 ]
99105    seg  =  _run_segmentation (foreground , boundaries , verbose = verbose , min_size = min_size , seed_distance = seed_distance ,
100-                             block_shape = ws_block_shape , halo = ws_halo )
106+                             block_shape = ws_block_shape , halo = ws_halo , boundary_threshold = boundary_threshold ,
107+                             area_threshold = area_threshold )
101108    seg  =  scaler .rescale_output (seg , is_segmentation = True )
102109
103110    if  return_predictions :
0 commit comments