- 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
- 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
- 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
- #2 or #3 but caxis has been used to restrict to a smaller portion of the colormap
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!
0 个评论
回答(2 个)
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:
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.
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
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
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 Center 和 File Exchange 中查找有关 Blue 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!