How to get the RBG values from a matlab figure?

14 次查看(过去 30 天)
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 个评论
Jan
Jan 2017-4-26
"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 2017-4-27
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.

请先登录,再进行评论。

回答(1 个)

Adam
Adam 2017-4-26
编辑:Adam 2017-4-26
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 个评论
ArthurHB
ArthurHB 2017-6-7
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 2017-6-7
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.

请先登录,再进行评论。

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by