Clear Filters
Clear Filters

imhist(P,10) , imhist(P,256) What are the differences among resulting histograms?

1 view (last 30 days)
I'm a new MATLAB user. I don't understand the meaning of bins used in imhist command. Can someone tell me the differences between the resulting histograms imhist(P,10), imhist(P,256)

Accepted Answer

Image Analyst
Image Analyst on 16 Mar 2013
A uint8 image might have intensities in the range of 0-255. If you use 256 bins, you get a count of how many pixels have each gray level. If you use 10 bins, you get a count of how many pixels are in the range 0-24, 25-49, 50-74, and so on.

More Answers (1)

Wayne King
Wayne King on 16 Mar 2013
Edited: Wayne King on 16 Mar 2013
It's the same meaning as the "regular" histogram, hist().
The number of bins in any histogram governs how coarsely or finely you bin the data. The fewer the bins, the wider the intervals and accordingly more values will fall in each bin. Conversely, the more bins, the shorter the intervals and fewer values will fall in each.
Choosing the optimal number of bins for your data is part science and part art. You want the histogram to give you a visual representation of the distribution of the data. Too few bins and the picture is too coarse. Too many bins and you end up not summarizing the data in any useful way.
Compare the following example with Gaussian random variables (just uses hist)
x = randn(1000,1);
subplot(221)
hist(x,30); title('30 bins');
subplot(222)
hist(x,4); title('4 bins');
subplot(223)
hist(x,400); title('400 bins');
I think you'll agree, the choice of 30 gives the best summary of the data distribution here.

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!