Extract Color from Grayscale Image not Index
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jason Bond
am 6 Jun. 2017
Kommentiert: Jason Bond
am 7 Jun. 2017
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 Kommentare
Adam
am 6 Jun. 2017
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.
Akzeptierte Antwort
Image Analyst
am 6 Jun. 2017
Just index your image
grayLevel = yourImage(row, column);
3 Kommentare
Image Analyst
am 6 Jun. 2017
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.
Weitere Antworten (0)
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!