필터 지우기
필터 지우기

How to get the RBG values from a matlab figure?

조회 수: 14 (최근 30일)
ArthurHB
ArthurHB 2017년 4월 26일
댓글: Adam 2017년 6월 7일
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