Clear Filters
Clear Filters

How to get the RBG values from a matlab figure?

14 views (last 30 days)
ArthurHB
ArthurHB on 26 Apr 2017
Commented: Adam on 7 Jun 2017
Hi, I am with a problem and I couldn't find a solution so far. I generated some figures from previous data and now I want to extract some information about the figures.
Here is an example:
So I have a random data with 10 different values, each values may be represented by 3 values (R,G,B). I just want to get the RGB value for all the 10 values.
For instance: RGB for the 4th sample = [0.06275 0.4706 0.8549].
How to proceed this without using the data cursor?
Thanks,
  2 Comments
Jan
Jan on 26 Apr 2017
"without using the data cursor" is not exactly enough: Why don't you wnt to use this simple tool? Should this happen without using the mouse, perhaps because you have to process 10'000 images automatically?
It might be much easier to extract the data from the axes objects instead of parsing the RGB colors.
ArthurHB
ArthurHB on 27 Apr 2017
Hi Jan,
I want to proceed with this automatically instead of use the data cursor because I will have to do it a lot of times for larger figures.

Sign in to comment.

Answers (1)

Adam
Adam on 26 Apr 2017
Edited: Adam on 26 Apr 2017
If you have the handle to your image, hImage, then
hImage.CData
will give you the data (if you don't then use hImage = get( gca, 'Children' ) to get the image handle );
However, your image looks like it is just an indexed image where the colour is coming from the colourmap (Parula) being applied. So if you really want the RGB images you will have to create a parula colourmap e.g.
cmap = parula(512);
and index into it after scaling your CData from 1 to 512 and rounding to the nearest integer (or whatever size of colourmap you wish)
  6 Comments
ArthurHB
ArthurHB on 7 Jun 2017
But it is possible that I receive some .fig file. In this case I don't have access to the original vector that created the colormap. However, I can access RGB values using the data cursor.
And that's what I want, to get these values. Thanks in advance.
Adam
Adam on 7 Jun 2017
There's always a colourmap with a figure, especially if it is not true RGB. The fig file just saves what was there at the time it was saved, it doesn't map the data onto the colourmap and then save it.
get( hFig, 'colormap' )
will give you the colourmap for the figure with handle hFig.

Sign in to comment.

Categories

Find more on Colormaps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!