필터 지우기
필터 지우기

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 CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by