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.
First let me create an indexed image using the Jet colormap:
img = repmat(uint8(0:255), 100, 1);
cmap = jet(256);
imshow(img, 'Colormap',cmap)
The straightforward conversion using IND2GRAY produces the following:
J = ind2gray(img,cmap);
imshow(J)
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:
[~,idx] = sortrows(rgb2hsv(cmap), -1); %# sort by Hue
C = gray(256);
C = C(idx,:);
imshow(img, 'Colormap',C)