getting RGB from image created with imagesc

8 次查看(过去 30 天)
Hi. I am creating am image of a matrix using imagesc.
i want to get the RGB values of every pixel in the image.
I tried using get(im,'CData'), but it gives back the matrix that created the image.
how can do it?
thanks, Ariel

采纳的回答

Mike Garrity
Mike Garrity 2016-3-15
编辑:Mike Garrity 2016-3-15
You probably want ind2rgb. But if you're using imagesc, rather than image, you're probably need to scale your color values. It looks something like this:
v = ??; % my matrix
map = colormap;
minv = min(v(:));
maxv = max(v(:));
ncol = size(map,1);
s = round(1+(ncol-1)*(v-minv)/(maxv-minv));
rgb_image = ind2rgb(s,map);
If you have integer color values, then you don't need to do that scaling before calling ind2rgb.
  1 个评论
ariel
ariel 2016-3-16
编辑:ariel 2016-3-16
thanks. However, when I get the RGB data, it is slightly different than what appears on the screen when I use the cursor.
The data is:
0.1250 1.0000 0.8750
while the screen shows this:
Another thing is mapping doubles to RGB - the help of ind2rgb clearly states that this is possible, however when I omitted the rounding of 's' in your example, I got the following error:
Subscript indices must either be real positive integers or logicals.
Error in ind2rgb (line 26)
r = zeros(size(a)); r(:) = cm(a,1);
I'm using Matlab 2015b

请先登录,再进行评论。

更多回答(1 个)

Image Analyst
Image Analyst 2016-3-15
imagesc() does not create images - it displays them. So you already have the image. If you want it pseudocolored, look up colormap in the help - there are a variety of predefined colormaps to choose from: hot, winter, jet, parula, etc. Pick one that you like and use ind2rgb to create a pseudocolored RGB image from your gray scale image.
% Use hsv color map to create an RGB image from a gray scale image:
rgbImage = ind2gray(grayImage, hsv(256));
  2 个评论
ariel
ariel 2016-3-16
thanks, that was very helpful.
I've noticed that colormap 'jet', for instance, is only 64x3, instead of a "normal" 256 colormap.
does that mean my color resolution is smaller?
Image Analyst
Image Analyst 2016-3-16
Yes. If you want some certain amount, specify it. Like if you want 1000 colors, say jet(1000).

请先登录,再进行评论。

类别

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by