How to calculate gray percentage of an gray scale image ? Like 50 % gray Level, 32% gray level....Please post your answers....Thanks in advance........

 채택된 답변

Image Analyst
Image Analyst 2011년 10월 29일

0 개 추천

This is ambigous so I guess I'll have to solve both scenarios. If you want to know what "percent gray" an image is, like you want to know if it really is "18% gray" then you'd do this:
maxGrayValue = intmax(class(grayImage))
meanGray = mean2(grayImage)
percentGray = meanGray / single(maxGrayValue)
This can of course be combined into one line if you want. You may have heard about the "18% gray" assumption in photography: http://en.wikipedia.org/wiki/Gray_card , or http://en.wikipedia.org/wiki/Middle_gray
On the other hand, if you're wanting to find out what gray level has 32% of the pixels darker than that, you can use the CDF:
% Get the histogram.
[pixelCounts GLs] = imhist(grayImage);
% Get the cumulative distribution function.
cdf = cumsum(pixelCounts) / sum(pixelCounts);
% For example, find the gray level where 32% of the pixels are darker.
indexGray32 = find(cdf<=0.32, 1, 'last');
percentGray32 = GLs(indexGray32)

추가 답변 (1개)

Amith Kamath
Amith Kamath 2011년 10월 29일

0 개 추천

but if you want to measure gray level in the way you have described above, you would want to replace the hist(<pixel value>) with hist(<pixel value range>) in the explanation in the link above. For example,
sum(hist(120:145)./sum(hist)) to check for fraction of pixels that are between 120 and 145 in value.
Thanks!

카테고리

도움말 센터File Exchange에서 Get Started with Image Processing Toolbox에 대해 자세히 알아보기

질문:

2011년 10월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by