napari
napari copied to clipboard
Bounding box has wrong extent for non-base level of multi-scale images
🐛 Bug Report
When showing the bounding box for a multi-scale image at some resolution other than its highest (i.e. other than level 0), it is too large.
💡 Steps to Reproduce
One way to reproduce this issue is to show a multi-scale image in 3D since that always uses the lowest resolution image.
import napari
import numpy as np
from skimage.transform import pyramid_gaussian
image = np.random.rand(8, 8, 8)
ms_image = list(pyramid_gaussian(image, downscale=2, max_layer=3))
scale = 3 * (2,)
viewer = napari.Viewer(ndisplay=3)
layer = viewer.add_image(ms_image, scale=scale)
layer.bounding_box.visible = True
napari.run()
There are ways to write tests with non-public APIs to force similar behavior for 2D. Or you can force the multi-scale image slicing code to use a specific level to see the effect in 2D.
💡 Expected Behavior
I expect the bounding-box to always show the correct extent of the image, regardless of the scale being viewed.
🌎 Environment
napari: 0.4.17rc4.dev804+g1bcbbf885.d20240625 Platform: macOS-14.5-arm64-arm-64bit System: MacOS 14.5 Python: 3.10.14 | packaged by conda-forge | (main, Mar 20 2024, 12:51:49) [Clang 16.0.6 ] Qt: 5.15.11 PyQt5: 5.15.10 NumPy: 1.26.4 SciPy: 1.13.1 Dask: 2024.5.1 VisPy: 0.14.2 magicgui: 0.8.2 superqt: 0.6.6 in-n-out: 0.2.1 app-model: 0.2.7 npe2: 0.7.5
OpenGL:
- GL version: 2.1 Metal - 88.1
- MAX_TEXTURE_SIZE: 16384
- GL_MAX_3D_TEXTURE_SIZE: 2048
Screens:
- screen 1: resolution 2560x1440, scale 1.0
- screen 2: resolution 1512x982, scale 2.0
Optional:
- numba: 0.59.1
- triangle not installed
Settings path:
- /Users/asweet/Library/Application Support/napari/napari-dev_bed8b9b3d61b11a9560a577ec715d63283498f35/settings.yaml Plugins:
- napari: 0.4.17rc4.dev804+g1bcbbf885.d20240625 (81 contributions)
- napari-console: 0.0.9 (0 contributions)
- napari-ome-zarr: 0.5.2 (2 contributions)
- napari-svg: 0.1.10 (2 contributions)
💡 Additional Context
This issue comes from a similar fix: https://github.com/napari/napari/pull/6319#issuecomment-2192432547
I think this can be fixed by modifying the child transform so that it also factors in the scale component of tile2data, not just the offsets.
Also note that toggling the visibility of the node or taking several other actions seems to fix this, so this may not be directly related to tile2data after all, and instead may be related to the bounding box transform being updated at the right time.
Thanks for opening this, I've run into it before "live" while doing something and then forgotten to track it down because it wasn't consistent.
This was fixed by https://github.com/napari/napari/pull/7545