Extract Color from Grayscale Image not Index
2 次查看(过去 30 天)
显示 更早的评论
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
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.
采纳的回答
Image Analyst
2017-6-6
Just index your image
grayLevel = yourImage(row, column);
3 个评论
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.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!