I have a jet colormap:
and I would like to know if there's some way to convert to a grayscale. I can't use average because maximum and minimum value goes to the same gray color. Or if there's some way to convert to another color palette.
I can't find on Google a function to convert it. MATLAB uses some thing called rgb2ind
but I would like to know the formula.
rgb2ind
converts the RGB values for each pixel into indices within a color map. If you use the 2 input version with a color map input, then it will look-up the closest color in the color map that matches each pixel. This will basically give you a single number for each pixel, rather than an RGB value.For example, if you load your image
then, since the Jet color map is returned by
jet
, then you can get the indexed data usingYou can then display the image using any color map
Don't use imagesc because it may stretch the dynamic range of your image unacceptably.
Python implementation of the answer given by teng (assuming a default matplotlib jetmap).
First let me create an indexed image using the Jet colormap:
The straightforward conversion using IND2GRAY produces the following:
As you expressed, the min/max converge to the same value. From what I understood, you are looking to map the jet colormap to linearly go from dark to light shades of gray. For this, we can reorder using the hue value which we get with the RGB2HSV function. Compare the following against the original colormap:
create the image in MATLAB
save the image as tiff, crop out the borders with Paintbrush and save as '\directorypath\jetmage.tiff'.
load the image in MATLAB
get image size
get a row of image for each color, red, green and blue.
plot the intensity profile for each color for that row.
The plot should be something like so:
you can use array
[r,g,b]
as the look-up-table or base on that figure out a way to get the 'formula' from array[r,g,b]