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.
Right-click the picture that you want to change, and then click Format Picture on the shortcut menu. Click the Picture tab. Under Image control, in the Color list, click Grayscale or Black and White.
c = gray returns the gray colormap as a three-column array with the same number of rows as the colormap for the current figure. If no figure exists, then the number of rows is equal to the default length of 256. Each row in the array contains the red, green, and blue intensities for a specific color.
I = rgb2gray( RGB ) converts the truecolor image RGB to the grayscale image I . The rgb2gray function converts RGB images to grayscale by eliminating the hue and saturation information while retaining the luminance. If you have Parallel Computing Toolbox™ installed, rgb2gray can perform this conversion on a GPU.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With