フィルターのクリア

Extract Color from Grayscale Image not Index

2 ビュー (過去 30 日間)
Jason Bond
Jason Bond 2017 年 6 月 6 日
コメント済み: Jason Bond 2017 年 6 月 7 日
Hello. I am trying to extract the color value from a grayscale image but my program currently gives the indexes. For example for color white, I get 0.53, for black it's 0.16. The imtool displays the actual colors I want to extract(example pic is attached). My code is pretty simple as shown below.
colors = image(:);
uniqueColors = unique(colors);
Any help would be appreciated, thanks!
  2 件のコメント
Adam
Adam 2017 年 6 月 6 日
The colour is presumably just a normalisation over the full data range. I don't use imtool so I don't know how it scales the data. There is no such thing as the 'actual colour' as such though - it is all dependent on how the data is scaled. If you are happy with the way it is scaled in the picture than you just need to normalise your data from its initial range to a 0-1 range (and make a triplet out of the results for greyscale colour).
I do that using a custom class I have but there are functions in the image processing toolbox I think that Image Analyst will now better than me - I forget to use most of the convenience functions in there.
Jason Bond
Jason Bond 2017 年 6 月 6 日
Thank you Adam. In order to normalise between 0 and 1, I added the following line:
colorsN = (colors - min(colors)) / ( max(colors) - min(colors));
And this does give values between 0 and 1. But when I compare these values, especially for gray colors, the indexes are off by some degree of accuracy. For example, colorsN(2) is 0.6486, but the value shown on the image tool is 0.651. How can I find the exact match? Thank you!

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2017 年 6 月 6 日
Just index your image
grayLevel = yourImage(row, column);
  3 件のコメント
Image Analyst
Image Analyst 2017 年 6 月 6 日
It's returning the gray level, not the class number. So if you want class numbers, so that 0.16 gray level = class #0, 0.53 = class #1, and 0.87 = class #2, and so on, then you're going to have to find the unique gray levels in the image and convert them to a class number.
uniqueGrayLevels = unique(yourImage(:));
Then use imquantize(), something like
quant_A = imquantize(yourImage, uniqueGrayLevels )
Now the values of quant_A will be 1,2,3 etc. instead of the fractional numbers.
Jason Bond
Jason Bond 2017 年 6 月 7 日
Thanks for all your help.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImages についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by