How to find "number of pixels" for a particular "gray level" in using HIST function ?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Mohan
am 23 Jun. 2012
Kommentiert: SHRUTI SINGH
am 14 Okt. 2016
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 (^_^)
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 23 Jun. 2012
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.
1 Kommentar
Weitere Antworten (1)
Walter Roberson
am 23 Jun. 2012
Usually if you want to be testing for exact values you would use histc() instead of hist(), in order to have greater certainty about exactly where the boundaries will go.
In order to get the count for a specific grey level using either hist() or histc() you would have to have adjacent bins that together gather everything that is not that grey level. This is easier to specify in histc() but it can be done in hist() as well, if you are careful.
With either function, assign the output to a variable. The (first) output will be a vector of values, one for each bin. By knowing which bin you put that specific gray level in, index the output vector to get the counts.
Mind you if I was doing this for only one gray level, I would just count them directly:
sum(YourGrayImage(:) == TheGrayLevel)
Sample code using histc:
counts = histc( YourGrayImage(:), 0:255 );
Then the count for gray value G is counts(G+1)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Modify Image Colors finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!