Borrar filtros
Borrar filtros

How to get the RBG values from a matlab figure?

14 visualizaciones (últimos 30 días)
ArthurHB
ArthurHB el 26 de Abr. de 2017
Comentada: Adam el 7 de Jun. de 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 comentarios
Jan
Jan el 26 de Abr. de 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 el 27 de Abr. de 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.

Iniciar sesión para comentar.

Respuestas (1)

Adam
Adam el 26 de Abr. de 2017
Editada: Adam el 26 de Abr. de 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 comentarios
ArthurHB
ArthurHB el 7 de Jun. de 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 el 7 de Jun. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Colormaps en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by