@@ -146,6 +146,19 @@ def patched_segment_ROI_overlapping_organoids(
146
146
return mask .astype (label_dtype )
147
147
148
148
149
+ def patched_cellpose_eval (self , x , ** kwargs ):
150
+ assert x .ndim == 4
151
+ # Actual labeling: segment_ROI returns a 3D mask with the same shape as x,
152
+ # except for the first dimension
153
+ mask = np .zeros_like (x [0 , :, :, :])
154
+ nz , ny , nx = mask .shape
155
+ indices = np .arange (0 , nx // 2 )
156
+ mask [:, indices , indices ] = 1 # noqa
157
+ mask [:, indices + 10 , indices + 20 ] = 2 # noqa
158
+
159
+ return mask , 0 , 0
160
+
161
+
149
162
def patched_cellpose_core_use_gpu (* args , ** kwargs ):
150
163
debug ("WARNING: using patched_cellpose_core_use_gpu" )
151
164
return False
@@ -632,9 +645,12 @@ def test_cellpose_within_masked_bb_with_overlap(
632
645
patched_cellpose_core_use_gpu ,
633
646
)
634
647
648
+ from cellpose import models
649
+
635
650
monkeypatch .setattr (
636
- "fractal_tasks_core.tasks.cellpose_segmentation.segment_ROI" ,
637
- patched_segment_ROI_overlapping_organoids ,
651
+ models .CellposeModel ,
652
+ "eval" ,
653
+ patched_cellpose_eval ,
638
654
)
639
655
640
656
# Setup caplog fixture, see
@@ -690,11 +706,16 @@ def test_cellpose_within_masked_bb_with_overlap(
690
706
# within the mask => should be 1 segmentation output per initial object
691
707
# If relabeling works correctly, there will be 4 objects in
692
708
# secondary_segmentation and they will be 1, 2, 3, 4
693
- initial_segmentation = da .from_zarr (
709
+ secondary_segmentation = da .from_zarr (
694
710
f"{ zarr_urls [0 ]} /labels/secondary_segmentation/0"
695
711
).compute ()
696
- assert len (np .unique (initial_segmentation )) == 5
697
- assert np .max (initial_segmentation ) == 4
712
+ assert len (np .unique (secondary_segmentation )) == 5
713
+ # Current approach doesn't 100% guarantee consecutive labels. Within the
714
+ # cellpose task, there could be labels that are taken into account for
715
+ # relabeling but are masked away afterwards. That's very unlikely to be an
716
+ # issue, because we set the background to 0 in the input image. But the
717
+ # mock testing ignores the input
718
+ # assert np.max(secondary_segmentation) == 4
698
719
699
720
700
721
def test_workflow_with_per_FOV_labeling_via_script (
0 commit comments