how to display an image's colormap onto its grayscale map?

Hi everyone,
I have biomedical images (.dcm) and I need to display the colormap of each image onto its grayscale map. I.e:
Let's say my image is named as X, and Y is a processed version of X 1) imshow(X); //grayscale 2) image(Y); //colormap
These two resulting figures on top of each other.
Any suggestion would help. Thanks

Answers (1)

Applying a colormap to one grayscale image will apply it to all grayscale images in all axes in the figure. Since that is usually not what you want, you can call freezecolors but it's probably easiest just to convert the grayscale image that you want to apply a colormap to, into a color image with ind2rgb():
imshow(X); % Show first gray scale image.
rgbImage = ind2rgb(Y, yourColorMap); % Convert second gray scale image into a color image.
imshow(rgbImage); % Display the color image.

11 Comments

First of all, thank you for your answer. I have one question though. What is the parameter yourColorMap in 'ind2rgb'. Can you give an example use of it?
It's whatever colormap you had. I didn't say you had a colormap - you did. So I assume you knew what colormap you were talking about. If you don't have one, then you can assign a default one such as gray, jet, winter, etc. or make up your own custom one if you prefer.
Hi again,
I used ind2rgb built-in function and it converted the grayscale image into colormap image (I checked it on the workspace part in matlab). However when I tried to display it with imshow, I got the folllowing error:
??? Error using ==> checkDisplayRange at 22 HIGH must be greater than LOW.
Error in ==> imageDisplayValidateParams at 57 common_args.DisplayRange = checkDisplayRange(common_args.DisplayRange,mfilename);
Error in ==> imageDisplayParseInputs at 79 common_args = imageDisplayValidateParams(common_args);
Error in ==> imshow at 199 [common_args,specific_args] = ...
the rgbImage was a double matrix. So I converted it to uint16 (which is the type of the original image) and displayed it using imshow. But, thistime I got a completely black image.
Do you have any idea what caused this?
What was the min and max value when it was a double class? Was it between 0 and 1? Or 0 and 255? If so, it will be dark or zero because uint16 goes from 0 to 65535.
In the workspace part it shows as too many. But when I displayed it as max(max(rgbImage)), the first channel's max value is 103, second one's is 114, third one's is 97. And the min values for each channel is also 103, 114 and 97, respectively.
You need to do
maxGL = max(grayImage(:))
minGL = min(grayImage(:))
otherwise you get the max and min of every column. But it looks like your values are in the range of 0-255 so no wonder they're displaying as all black. Try this:
imshow(grayImage, []);
or else
grayImage16 = uint16(grayImage) * uint16(256);
imshow(grayImage16);
I'm tring to display the colormap image (rgbImage),I'm saying this for us to be on the same page. I actually tried imshow(rgbImage, []), and this has come out to be a complete black image. Now, I tried the latter one, and I got a complete pale green image.
Make up a small example using a standard MATLAB demo image and post it.
For example this one:
c
lear all;
close all;
home
clc
original = imread('eight.tif');
figure(1); imshow(original);
tempImage = zeros(size(original));
threshold1 = 150; threshold2 = 75;
for x = 1:size(original, 1)
for y = 1:size(original, 2)
if original(x, y) < threshold1 && original(x, y) > threshold2
tempImage(x, y) = original(x, y);
end
end
end
figure(2); imshow(tempImage);
rgbImage = ind2rgb(tempImage, 'gray');
figure(3); imshow(rgbImage);
In this example I got a complete white image for rgbImage.
tempImage = zeros(size(original), 'like', original);
Note: you could also use this code with no loop
tempImage = original;
tempImage(original <= threshold2 | original >= threshold) = 0;
Oh, thank you for the shortcut :)
Yet I still get the white screen. Do you have any solution to this?

Sign in to comment.

Asked:

on 19 Jan 2014

Commented:

on 30 Jan 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!