Azzera filtri
Azzera filtri

Extract Color from Grayscale Image not Index

2 visualizzazioni (ultimi 30 giorni)
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 Commenti
Adam
Adam il 6 Giu 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.
Jason Bond
Jason Bond il 6 Giu 2017
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!

Accedi per commentare.

Risposta accettata

Image Analyst
Image Analyst il 6 Giu 2017
Just index your image
grayLevel = yourImage(row, column);
  3 Commenti
Image Analyst
Image Analyst il 6 Giu 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.
Jason Bond
Jason Bond il 7 Giu 2017
Thanks for all your help.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Images in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by