napari / napari

napari: a fast, interactive, multi-dimensional image viewer for python
https://napari.org
BSD 3-Clause "New" or "Revised" License
2.07k stars 410 forks source link

HiLO LUT #6878

Open melonora opened 2 weeks ago

melonora commented 2 weeks ago

🚀 Feature

Implement the HiLo LUT that is also present in FIJI for the purpose of intensity clipping as shown below:

m51-histogram-hilo

Motivation

(https://forum.image.sc/t/add-hilo-colormap-to-napari/95601/4)

GenevieveBuckley commented 1 week ago

This seems pretty easy to do:

from napari.utils.colormaps import AVAILABLE_COLORMAPS

hilo = AVAILABLE_COLORMAPS['gray']
hilo.colors[0] = [0, 0, 1, 1]   # blue (lowest pixel values)
hilo.colors[-1] = [1, 0, 0, 1]  # red  (highest pixel values)

And checking that it works:

# check with uint8 data
import napari
import skimage.data

viewer = napari.Viewer()
camera = skimage.data.camera()
viewer.add_image(camera, colormap=hilo)
# check with float data
import napari
import numpy as np

viewer = napari.Viewer()
data = np.random.random((20, 20))
viewer.add_image(data, colormap=hilo)
melonora commented 1 week ago

Thought so too but @Czaki and I checked this and this does not seem to be correct. We had the same approach, but due to conversion to uint8 in vispy for a 16 bit image for example the intensity values are binned. This means that if you have intensity values of both 0 and 1 in your 16 bit image, both will be blue, which should not be the case.

A shader is required

melonora commented 1 week ago

We also tried with by adjusting the controls of a custom color map, but same issue.

melonora commented 6 days ago
import napari
from skimage.data import cells3d

data=cells3d()

viewer = napari.Viewer()
data[:,1, 90:110, 90:110] = 65535
data[:,1, 110:130, 110:130] = 65534
data[:,1, 140:160, 140:160] = 0
data[:,1, 170:190, 170:190] = 1
viewer.add_image(data, channel_axis=1)

napari.run()

If you run this you will see that when switching to HiLo LUT that values 1 are blue and 65534 are red which should not happen. The image itself is 16bit