How to find "number of pixels" for a particular "gray level" in using HIST function ?
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Image Analyst
il 23 Giu 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.
Più risposte (1)
Walter Roberson
il 23 Giu 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 Commenti
Vedere anche
Categorie
Scopri di più su Modify Image Colors in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!