- 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
1 view (last 30 days)
Show older comments
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/155399/image.jpeg)
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 Comments
Answers (2)
Walter Roberson
on 21 Jan 2014
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
on 26 Apr 2017
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 Comments
Walter Roberson
on 26 Apr 2017
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
on 26 Apr 2017
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.
See Also
Categories
Find more on Red in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!