How to get the RBG values from a matlab figure?
21 ビュー (過去 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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/163391/image.png)
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
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.
回答 (1 件)
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 件のコメント
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 Center および File Exchange で Blue についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!