@@ -140,20 +140,20 @@ def decode_binary_thresholding(
140140
141141 # Apply morphological opening (erosion + dilation) - removes small objects
142142 if opening_iterations > 0 :
143- binary_mask = ndimage .binary_opening (
144- binary_mask , iterations = opening_iterations
145- ). astype ( np . uint8 )
143+ binary_mask = ndimage .binary_opening (binary_mask , iterations = opening_iterations ). astype (
144+ np . uint8
145+ )
146146
147147 # Apply morphological closing (dilation + erosion) - fills small holes
148148 if closing_iterations > 0 :
149- binary_mask = ndimage .binary_closing (
150- binary_mask , iterations = closing_iterations
151- ). astype ( np . uint8 )
149+ binary_mask = ndimage .binary_closing (binary_mask , iterations = closing_iterations ). astype (
150+ np . uint8
151+ )
152152
153153 # Apply connected components filtering
154- if connected_components and connected_components .get (' enabled' , False ):
155- remove_small = connected_components .get (' remove_small' , 0 )
156- connectivity = connected_components .get (' connectivity' , 26 )
154+ if connected_components and connected_components .get (" enabled" , False ):
155+ remove_small = connected_components .get (" remove_small" , 0 )
156+ connectivity = connected_components .get (" connectivity" , 26 )
157157
158158 if remove_small > 0 :
159159 # Label connected components
@@ -359,7 +359,7 @@ def decode_binary_contour_distance_watershed(
359359 min_seed_size : int = 32 ,
360360 return_seed : bool = False ,
361361 precomputed_seed : Optional [np .ndarray ] = None ,
362- prediction_scale : int = 255 ,
362+ prediction_scale : int = 1 ,
363363 binary_channels : Optional [List [int ]] = None ,
364364 contour_channels : Optional [List [int ]] = None ,
365365 distance_channels : Optional [List [int ]] = None ,
@@ -456,15 +456,19 @@ def decode_binary_contour_distance_watershed(
456456 else :
457457 # Position-based fallback (legacy behavior)
458458 if use_contour :
459- assert predictions .shape [0 ] >= 3 , f"Expected at least 3 channels (binary, contour, distance), got { predictions .shape [0 ]} "
459+ assert (
460+ predictions .shape [0 ] >= 3
461+ ), f"Expected at least 3 channels (binary, contour, distance), got { predictions .shape [0 ]} "
460462 # If more than 3 channels, first N-2 channels are binary (average them)
461463 if predictions .shape [0 ] > 3 :
462464 binary = predictions [:- 2 ].mean (axis = 0 )
463465 contour , distance = predictions [- 2 ], predictions [- 1 ]
464466 else :
465467 binary , contour , distance = predictions [0 ], predictions [1 ], predictions [2 ]
466468 else :
467- assert predictions .shape [0 ] >= 2 , f"Expected at least 2 channels (binary, distance) when contour disabled, got { predictions .shape [0 ]} "
469+ assert (
470+ predictions .shape [0 ] >= 2
471+ ), f"Expected at least 2 channels (binary, distance) when contour disabled, got { predictions .shape [0 ]} "
468472 # If more than 2 channels, first N-1 channels are binary (average them)
469473 if predictions .shape [0 ] > 2 :
470474 binary = predictions [:- 1 ].mean (axis = 0 )
@@ -476,10 +480,19 @@ def decode_binary_contour_distance_watershed(
476480 # Convert thresholds based on prediction scale
477481 if prediction_scale == 255 :
478482 distance = (distance / prediction_scale ) * 2.0 - 1.0
479- binary_threshold = (binary_threshold [0 ] * prediction_scale , binary_threshold [1 ] * prediction_scale )
483+ binary_threshold = (
484+ binary_threshold [0 ] * prediction_scale ,
485+ binary_threshold [1 ] * prediction_scale ,
486+ )
480487 if use_contour :
481- contour_threshold = (contour_threshold [0 ] * prediction_scale , contour_threshold [1 ] * prediction_scale )
482- distance_threshold = (distance_threshold [0 ] * prediction_scale , distance_threshold [1 ] * prediction_scale )
488+ contour_threshold = (
489+ contour_threshold [0 ] * prediction_scale ,
490+ contour_threshold [1 ] * prediction_scale ,
491+ )
492+ distance_threshold = (
493+ distance_threshold [0 ] * prediction_scale ,
494+ distance_threshold [1 ] * prediction_scale ,
495+ )
483496
484497 if precomputed_seed is not None :
485498 seed = precomputed_seed
@@ -492,10 +505,7 @@ def decode_binary_contour_distance_watershed(
492505 )
493506 else :
494507 # No contour constraint - only binary and distance
495- seed_map = (
496- (binary > binary_threshold [0 ])
497- * (distance > distance_threshold [0 ])
498- )
508+ seed_map = (binary > binary_threshold [0 ]) * (distance > distance_threshold [0 ])
499509 seed = cc3d .connected_components (seed_map )
500510 seed = remove_small_objects (seed , min_seed_size )
501511
@@ -507,10 +517,7 @@ def decode_binary_contour_distance_watershed(
507517 )
508518 else :
509519 # No contour constraint - only binary and distance
510- foreground = (
511- (binary > binary_threshold [1 ])
512- * (distance > distance_threshold [1 ])
513- )
520+ foreground = (binary > binary_threshold [1 ]) * (distance > distance_threshold [1 ])
514521
515522 segmentation = mahotas .cwatershed (- distance .astype (np .float64 ), seed )
516523 segmentation [~ foreground ] = (
0 commit comments