Question about rgb image

2 次查看(过去 30 天)
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.

采纳的回答

Image Analyst
Image Analyst 2014-6-5
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 个评论
Elsie
Elsie 2014-6-13
Hi, Image Analyst, is it possible to get the image after colomap? i want the colomapped image...
Image Analyst
Image Analyst 2014-6-13
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().

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Blue 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by