How can I access the RGB data in this figure

2 次查看(过去 30 天)
I have a 61x1 array. From the picture I can see exactly what I want, which is the RGB values for each X. I want to use this data in another part of my code. How can I extract this RGB data?
Thank you!

回答(2 个)

Walter Roberson
Walter Roberson 2014-1-21
61 x 1 arrays do not have RGB values. You would need 61 x 1 x 3 to have an RGB value.
Unless:
  1. The values stored in the arrays are one of the integer datatypes and are acting as indices into a colormap that you have defined; or
  2. The values stored in the arrays are floating point numbers in the range 0 to 1 that are acting to indicate locations into a colormap based upon "fraction of the colormap length"; or
  3. The values stored in the arrays are floating point numbers and you have used imagesc() or imshow([]) to map the minimum value in the array to the beginning of the color map and the maximum value in the array is to be mapped to the highest location in the colormap; or
  4. #2 or #3 but caxis has been used to restrict to a smaller portion of the colormap
Notice that in each of these 4 cases, there is no absolute RGB value defined by the data directly, only indexing into a colormap that defines the colors to use.
  1 个评论
Kenneth Morley
Kenneth Morley 2014-1-21
编辑:Kenneth Morley 2014-1-21
Yes #1 is correct. The data I have is acting as an index in the image. My final goal is to use this indexed number to color various counties on a map based on their value. That is why I was trying to get RGB values. Is there some other way to do this?

请先登录,再进行评论。


ArthurHB
ArthurHB 2017-4-26
I'm with the same problem now.
I have generated a colormap figure and I want to get the RGB values from each element of the figure.
  2 个评论
Walter Roberson
Walter Roberson 2017-4-26
cmap = copper(10);
r = 5; c = 7;
img = randi(10, r, c);
rgbimg = reshape( cmap(img,:), size(img,1), size(img,2), 3);
Image Analyst
Image Analyst 2017-4-26
If you have an indexed image, and you applied a colormap to it,
imshow(indexedImage);
colormap(yourColorMap);
colorbar;
and you want the RGB color of every pixel in the image, you can use ind2rgb() to make an RGB image.
rgbImage = ind2rgb(indexedImage, yourColorMap);
That gives you the RGB values of every pixel the whole image. If you want the RGB values of a particular pixel (a row and column) in that image, you can do
rgbThisPixel = rgbImage(row, column, :);
You can also get it from the original indexed image:
index = indexedImage(row, column); % Get the index.
rgbThisPixel = yourColorMap(index,:); % Retrieve the RGB value from the colormap.

请先登录,再进行评论。

类别

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