Skip to content

Commit

Permalink
Fix translation handling & detection of clicks when translation is pr…
Browse files Browse the repository at this point in the history
…esent
  • Loading branch information
jluethi committed Jul 19, 2024
1 parent 751634f commit ab869bb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/napari_feature_classifier/annotator_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,17 +215,22 @@ def toggle_label(self, labels_layer, event):
Callback for when a label is clicked. It then updates the color of that
label in the annotation layer.
"""
# Need to scale position that event.position returns by the
# Need to translate & scale position that event.position returns by the
# label_layer scale.
# If scale is (1, 1, 1), nothing changes
# If translate is (0, 0, 0)
# If scale is anything else, this makes the click still match the
# correct label
# translate before scale
scaled_position = tuple(
pos / scale for pos, scale in zip(event.position, labels_layer.scale)
(pos - trans) / scale
for pos, trans, scale in zip(
event.position, labels_layer.translate, labels_layer.scale
)
)
label = labels_layer.get_value(scaled_position)
if label == 0 or not label:
napari_info("No label clicked.")
napari_info(f"No label clicked on the {labels_layer} label layer.")
return

# Left click: add annotation
Expand Down Expand Up @@ -269,6 +274,8 @@ def _init_annotation(self, label_layer: napari.layers.Labels):
# label_layer.opacity = 0.4
self._annotations_layer.data = label_layer.data
self._annotations_layer.scale = label_layer.scale
self._annotations_layer.translate = label_layer.translate

reset_display_colormaps(
label_layer,
feature_col="annotations",
Expand Down
1 change: 1 addition & 0 deletions src/napari_feature_classifier/classifier_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ def _init_prediction_layer(self, label_layer: napari.layers.Labels):
# Update the label data in the prediction layer
self._prediction_layer.data = label_layer.data
self._prediction_layer.scale = label_layer.scale
self._prediction_layer.translate = label_layer.translate

# Update the colormap of the prediction layer
reset_display_colormaps(
Expand Down

0 comments on commit ab869bb

Please sign in to comment.