diff --git a/bec_widgets/utils/crosshair.py b/bec_widgets/utils/crosshair.py index adfb21d5..f7a3d10d 100644 --- a/bec_widgets/utils/crosshair.py +++ b/bec_widgets/utils/crosshair.py @@ -917,6 +917,8 @@ class Crosshair(QObject): image = item.image if image is None: continue + if image.ndim > 2: + continue if item.image_transform is not None: inv_transform, _ = item.image_transform.inverted() diff --git a/tests/unit_tests/test_crosshair.py b/tests/unit_tests/test_crosshair.py index fe9ceff6..05f1a4db 100644 --- a/tests/unit_tests/test_crosshair.py +++ b/tests/unit_tests/test_crosshair.py @@ -260,6 +260,22 @@ def test_update_coord_label_2D(image_widget_with_crosshair): assert crosshair.coord_label.isVisible() +def test_rgb_image_labels_omit_scalar_intensity(image_widget_with_crosshair): + """RGB pixels are arrays, so live and pinned labels only show coordinates.""" + crosshair, plot_item = image_widget_with_crosshair + rgb_image = np.arange(12).reshape(2, 2, 3) + + for item in plot_item.items: + if isinstance(item, pg.ImageItem): + item.setImage(rgb_image) + + crosshair.update_coord_label((0.5, 1.2)) + assert crosshair.coord_label.toPlainText() == "(0.500, 1.200)" + + crosshair.set_pin(0.0, 1.0) + assert crosshair.pinned_label.toPlainText() == "pin (0.500, 1.500)" + + def test_update_markers_on_image_change_accepts_image_without_transform( image_widget_with_crosshair, ): diff --git a/tests/unit_tests/test_image_view_next_gen.py b/tests/unit_tests/test_image_view_next_gen.py index 7b1878e1..e7920156 100644 --- a/tests/unit_tests/test_image_view_next_gen.py +++ b/tests/unit_tests/test_image_view_next_gen.py @@ -1459,6 +1459,19 @@ def test_detached_pin_label_intensity_updates_on_image_update(qtbot, mocked_clie ) +def test_detached_pin_label_omits_scalar_intensity_for_rgb_image(qtbot, mocked_client): + """Detached RGB pin labels only show coordinates because a pixel is an array.""" + bec_image_view = create_widget(qtbot, Image, client=mocked_client) + bec_image_view.on_image_update_2d({"data": np.zeros((5, 5, 3))}, {}) + bec_image_view.hook_crosshair() + bec_image_view.crosshair.set_pin(2.0, 3.0) + bec_image_view.unhook_crosshair() + + assert bec_image_view.crosshair is None + assert bec_image_view._detached_pin is not None + assert bec_image_view._detached_pin["label"].toPlainText() == "pin (2.500, 3.500)" + + ############################################## # Device selection toolbar sync ##############################################