diff --git a/cellpose_napari/_dock_widget.py b/cellpose_napari/_dock_widget.py index 87723f8..043a62f 100644 --- a/cellpose_napari/_dock_widget.py +++ b/cellpose_napari/_dock_widget.py @@ -279,7 +279,15 @@ def update_masks(masks): widget.masks_orig = masks logger.debug('masks updated') - + @widget.image_layer.changed.connect + def check_dims(image_layer): + if image_layer.ndim == 4 and not image_layer.rgb: + widget.process_3D.value = True + elif image_layer.ndim==3 and not image_layer.rgb: + widget.process_3D.value = True + else: + widget.process_3D.value = False + @widget.compute_masks_button.changed.connect def _compute_masks(e: Any): diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 748f028..ff5d4e9 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -69,10 +69,13 @@ def test_compute_diameter(qtbot, viewer_widget): def test_3D_segmentation(qtbot, viewer_widget): viewer, widget = viewer_widget + # by default the widget loads with `process_3D` set to False + assert widget.process_3D.value == False viewer.open_sample(PLUGIN_NAME, 'rgb_3D') - # set 3D processing - widget.process_3D.value = True + # check that 3D processing is set correctly after opening a 3D image + assert widget.process_3D.value == True + widget.model_type.value = "cyto3" widget() # run segmentation with all default parameters