MATLAB: How to find “number of pixels” for a particular “gray level” in using HIST function

grey levelhistnumber of image pixels

Hi,
I am working on image processing.
In using the hist function, I want to know, how to get the "number of pixels" for a particular "grey level" and also for all the gray level value ?
Please help, Thank you in advance (^_^)

Best Answer

For a normal 8 bit (uint8) grayscale image I do this:
[pixelCounts grayLevels] = imhist(grayImage);
It's a lot trickier for double images. Let me know if you have double images - I think I have a demo on that.