Continuous color scale with distinct colors for under/oversaturated pixels

I would like to visualise under/oversatured pixels with continuous color scale (e.g. pixels with value 0 to be blue, pixels with value 255 to be red, the rest in gray). Is it possible? There are LUTs for this in ImageJ but I could not find the way for plotly in python. Thanks!

HI @Madrigallo welcome to the forums.

Do you want the gray to be grayscale ranging from 1 to 254 or just one color?

Grayscale, not a single color.

This should get you there, you are searching for a custom colorbar

Thank you, but does that mean I need to specify the gray hue for each value explicitly? I was hoping there was a way that I start with gray scale and selectively modify the color for certain values. How would explicit list of grey hues work for different bit depths in images?

The solution was to design custom continuous color scale with specified ratios for individual colors. The resulting code which does what I want looks like this:

custom_colors2 = [[0, "#ff0000"], [0.000001, "#000000"], [0.999999, "#ffffff"], [1, "#0000ff"]]
px.imshow(image, color_continuous_scale=custom_colors2)

Setting the ratio for second colour (black here) low enough practically makes the first colour (red) applied to only one pixel value, e. i. zero. So in this way one can combine qualitative and continuous scales, though in a limited way.

1 Like

Perfect, glad you figured it out.