Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jet colormap to grayscale

I have a jet colormap:

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.

like image 973
PerroNoob Avatar asked Sep 16 '11 05:09

PerroNoob


People also ask

How do I convert a color image to grayscale?

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.

What is colormap gray in Matlab?

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.

How do you convert to grayscale in Matlab?

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.


1 Answers

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)

jet

The straightforward conversion using IND2GRAY produces the following:

J = ind2gray(img,cmap);
imshow(J)

jet_to_gray

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)

hue_sorted

like image 113
Amro Avatar answered Sep 27 '22 19:09

Amro