Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

rgb to grayscale using jet colormap intensity

191 views
Skip to first unread message

Troy

unread,
Dec 20, 2010, 3:14:06 PM12/20/10
to
Hello,
I am trying to convert an RGB image to grayscale. I'd like the grayscale image to reflect the jet colormap, i.e. dark red regions of the RGB image show up as the more intense (lighter) regions of the greyscale image. Is there an easy way to do this?

Thanks,
Troy

ImageAnalyst

unread,
Dec 20, 2010, 3:33:07 PM12/20/10
to
Troy:
Yes with the rgb2ind() function. See this demo:


% IMPORTANT: The newsreader may break long lines into multiple lines.
% Be sure to join any long lines that got split into multiple single
lines.
% These can be found by the red lines on the left side of your
% text editor, which indicate syntax errors, or else just run the
% code and it will stop at the split lines with an error.


clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 20;

% Change the current folder to the folder of this m-file.
if(~isdeployed)
cd(fileparts(which(mfilename)));
end

% Read in a standard MATLAB color demo image.
folder = 'C:\Program Files\MATLAB\R2010a\toolbox\images\imdemos';
baseFileName = 'peppers.png';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
rgbImage = imread(fullFileName);
[indexedImage, map] = rgb2ind(rgbImage, 256);
imshow(indexedImage);
% Enlarge figure to full screen.
set(gcf, 'Position', get(0,'Screensize'));
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
% Set up the jet colormap.
colormap(map);
colorbar;
title('Gray Image with Custom Color Map', ...
'FontSize', fontSize);

Troy

unread,
Dec 20, 2010, 4:24:11 PM12/20/10
to
Thanks for the quick response. I'm still having some trouble though. My original image is a thermal image that has the "hottest" areas saturated in dark red, and coolest areas in blue. My end goal is to generate contours of color increasing with the jet colormap. I've included some code to demonstrate the issue using the peppers image:

RGB = imread('peppers.png');
[X,map] = rgb2ind(RGB,256);
figure, imshow(X,map);
J = ind2gray(X,map);
figure, imshow(J,jet);
imcontour(J,6);

This still seems to assign the most intense colors to the lighter regions of the grayscale image, the onions in this case. I'd like the contours to show the most intense regions as red from the original RGB image, i.e. the red bell peppers.

Thanks

ImageAnalyst <imagea...@mailinator.com> wrote in message <7da5817b-e425-48c1...@k30g2000vbn.googlegroups.com>...

ImageAnalyst

unread,
Dec 20, 2010, 5:06:45 PM12/20/10
to
It seems like you have a pseudocolored thermal image and you want to
"undo" the colormap to get back the original grayscale (monochrome)
image. First of all, is it possible to get the grayscale image
directly? Most or all thermal cameras will allow you to get the
grayscale thermal image directly, without any colormap being applied.
If not, can you get the colormap that was applied? If you can, then
you can undo the colormap with ind2gray() and get back the original
gray image. Once you have the gray image back again, then you can put
up meaningful contours.

Can you upload (somewhere) an actual thermal image?

0 new messages