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)
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:
[pixelCounts GLs] = imhist(grayImage);
cdf = cumsum(pixelCounts) / sum(pixelCounts);
indexGray32 = find(cdf<=0.32, 1, 'last');
percentGray32 = GLs(indexGray32)
Best Answer