Labels layer with autogenerated pyramid levels shows artifacts
See original GitHub issue🐛 Bug
When loading a label layer with multiscale pyramids (e.g. from ome-zarr), randomly colored pixels can occur at the contours of labeled regions. This indicates additional label values differing from the labeled region’s value, which might be caused by downsampling with interpolation or antialiasing.
In my case I originally used skimage.transform.rescale(array, scale=0.5, order=0, anti_aliasing=False, preserve_range=True).astype(np.uint)
. I could confirm that all my multiscale levels were all uint images with the same set of values.
This seems to be caused when Napari autogenerates additional multiscale levels (the ome-zarr file might contain just as many levels as considered sufficient by the generator, but may still be valid). The downscaling method does maybe not visually impact normal image layers, but for labels layers it does, since arbitrary colors can be assigned to regions.
To Reproduce
Steps to reproduce the behavior:
import napari
import numpy as np
from skimage.draw import circle
# Draw a curved segmentation with a label value greater 1. Due to varying boundary
# direction, incorrect downsampling will produce a range of intensity values.
label_image_0 = np.zeros((2048, 2048), dtype=np.uint)
label_image_0[circle(r=1024, c=1024, radius=1000)] = 10
label_image_1 = np.zeros((1024, 1024), dtype=np.uint)
label_image_1[circle(r=512, c=512, radius=500)] = 10
pyramid = [label_image_0, label_image_1]
viewer = napari.Viewer()
viewer.add_labels(pyramid, name="label_image")
napari.run()
Expected behavior
When zooming in and out, a each region should be displayed with a single color without that boundary pixels change color.
Environment
napari: 0.4.9 Platform: Linux-5.4.0-74-generic-x86_64-with-glibc2.10 System: Ubuntu 18.04.5 LTS Python: 3.8.5 (default, Sep 4 2020, 07:30:14) [GCC 7.3.0] Qt: 5.15.2 PyQt5: 5.15.2 NumPy: 1.20.1 SciPy: 1.6.1 Dask: 2021.01.1 VisPy: 0.6.6
OpenGL:
- GL version: 4.6.0 NVIDIA 390.143
- MAX_TEXTURE_SIZE: 16384
Screens:
- screen 1: resolution 1920x1200, scale 1.0
- screen 2: resolution 1920x1200, scale 1.0
Plugins:
- console: 0.0.3
- napari-ome-zarr: 0.1.1
- scikit-image: 0.4.9
- svg: 0.1.4
Additional context
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:7 (7 by maintainers)
ah. I’ll take a look.
I tried again and I noticed that an environment variable was set, namely
NAPARI_OCTREE=1
as workaround for https://github.com/napari/napari/issues/1942.When set to
0
, the issue does not occur. So it seems not to be a bug in the default code, but probably only in the octree code.