mirror of
https://github.com/bec-project/bec_widgets.git
synced 2026-07-21 02:33:04 +02:00
fix(crosshair): fix crosshair label for rgb
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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,
|
||||
):
|
||||
|
||||
@@ -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
|
||||
##############################################
|
||||
|
||||
Reference in New Issue
Block a user