Colormap issue with 3D data


I am experiencing an issue with colormaps applied to a 3D data set.

If I display the full data (a distance map) all works as expected: the intensity values (distances) a nicely colored. Then I set the last z-slice to zero. If I render this changed data set the colormap becomes binary: the whole area of the distance map gets the same (“maximal”) color.
If I zero the second-last slice instead of the last all is fine. All this is independent of the particular colormap chosen.
To demonstrate I include a test script and an image.
If you reduce the size of the image (commented code) all three cases render fine. (1.1 MB)

Hi there @Gucki!

What’s happening is that if you don’t pass in a contrast_limits=(lo, hi) argument to add_image, napari computes them automatically. It does this by finding the min and max of the first, middle, and last slice. In your case, both the first and middle slices are empty, so when you empty the last one, napari has nothing to do, and it reverts to the default range for floating point images, which is [0, 1].

You have two options to fix this:

  • manually, in the GUI, if you right click on the contrast limit slider, you can actually set the values of the full range by typing them in, so you can set whatever range you want. (we are working to make this more discoverable…)
  • programmatically, in the code: call add_image with appropriate values for contrast_limits=.

I hope this helps!


Hi @jni,

thank you for the quick reply! I will then go the programmatic way and keep the GUI option in mind. Just for the record: with this great napari tool and the power of the python libraries image analysis is a lot of fun!