Question about rgb image

2 views (last 30 days)
Elsie
Elsie on 5 Jun 2014
Commented: Image Analyst on 13 Jun 2014
Hi, i have question regarding to imshow a rgb image:
rect =[ ...];
i=image_newC+abs(min(min(image_newC))); % i is a grayscale image
i=imcrop(i,rect);
n = size(unique(reshape(i,size(i,1)*size(i,2),size(i,3))),1);
rgb = ind2rgb(gray2ind(i,n),jet(n));
imshow(rgb,[]); *???why output image is entirely red?*
The purpose is to convert grayscale image to rgb image, i don't know why outcome is not expected. One more thing, is i tried to show it in this way:
imshow(i,[]);
colormap(jet(255));
but i don't know how to access the rgb image if i want to further perform some operations on it. Any way to store it in a variable? Sorry, i am new to Matlab.
Thanks a lot for your help.

Accepted Answer

Image Analyst
Image Analyst on 5 Jun 2014
Wow! That's about the most complicated, convoluted way of converting a gray scale image to RGB I've ever seen. If image_newC is a unint8 gray scale image, you can simply do
rgbImage = cat(3, image_newC, image_newC, image_newC);
If you want an RGB image with some colormap applied, just as jet(256), do this:
rgbImage = ind2rgb(image_newC, jet(256));
Please see my attached demos if you want to colorize a portion of the image but not the whole image.
  3 Comments
Elsie
Elsie on 13 Jun 2014
Hi, Image Analyst, is it possible to get the image after colomap? i want the colomapped image...
Image Analyst
Image Analyst on 13 Jun 2014
With the demos I posted, you know the color map in advance. You specified it so of course you already know it.
For RGB images there is no color map - it simply does not apply or make sense.
If you want to convert an RGB image to an indexed image, you can use rgb2ind() and it will give you a color map. There is no guarantee that the color map it applies will be anything like the color map you specified when you created the RGB image with ind2rgb().

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!