From 18659d0dcf74987dff7e6656ec42280b32d2abf5 Mon Sep 17 00:00:00 2001 From: Andy Sweet Date: Fri, 29 Mar 2024 16:04:10 -0700 Subject: [PATCH] Use image scale for points annotations --- src/napari_cryoet_data_portal/_open_widget.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/napari_cryoet_data_portal/_open_widget.py b/src/napari_cryoet_data_portal/_open_widget.py index 0f43f48..40db883 100644 --- a/src/napari_cryoet_data_portal/_open_widget.py +++ b/src/napari_cryoet_data_portal/_open_widget.py @@ -146,8 +146,10 @@ def _loadTomogram( # Materialize low resolution immediately on this thread to prevent napari blocking. if resolution is LOW_RESOLUTION: image_data = np.asarray(image_data) + # Get scale before resolution scaling for annotations. + image_scale = image_attrs["scale"] image_attrs["scale"] = tuple( - resolution.scale * s for s in image_attrs["scale"] + resolution.scale * s for s in image_scale ) image_translate = image_attrs.get("translate", (0,) * len(image_attrs["scale"])) image_attrs["translate"] = tuple( @@ -171,7 +173,13 @@ def _loadTomogram( if f.shape_type == "Point" ) if len(point_paths) > 0: - yield read_annotation(annotation, tomogram=tomogram) + anno_data, anno_attrs, anno_type = read_annotation(annotation, tomogram=tomogram) + # Inherit scale from full resolution image so that we can pick up + # that scale when it changes. + anno_attrs["scale"] = image_scale + # Scaling points also changes the size, so adjust accordingly. + anno_attrs["size"] /= np.mean(image_scale) + yield anno_data, anno_attrs, anno_type else: logger.warn("Found no points annotations. Skipping.")