How do I find the maximum and minimum of a histogram in MATLAB?
Show older comments
I want to find max and min of a histogram in matlab please advise me. thanks
4 Comments
What does this mean?
If you have the data that created the histogram then it's simply min()/max() of that data. If you don't, then all you have is the bin boundaries and all you can say is that the values are within them.
This, of course, means that there were no values outside the range of the last bin edge that were ignored (as histc does if don't use inf for range). And, if there weren't such samples ignored, there's no way of knowing if those extreme value(s) were/were not included in the first/last bins.
Once a histogram has been formed there's a loss of information that is simply irretrievable w/o the raw data.
roya a
on 29 Jul 2013
dpb
on 29 Jul 2013
Again, too nebulous. What do you mean "maximum value of the intensity axes"?
You mean the maximum bin count? If so, if you used either hist or histc then it's just max|min on the returned counts vector.
If something else, explain what.
roya a
on 29 Jul 2013
Answers (4)
Image Analyst
on 29 Jul 2013
[pixelCounts, grayLevels] = imhist(grayImage);
minGrayLevel = min(grayImage(:));
maxGrayLevel = max(grayImage(:));
% or
minGrayLevel = find(pixelCounts > 0, 1, 'first');
maxGrayLevel = find(pixelCounts > 0, 1, 'last');
minCounts = min(pixelCounts(:));
maxCounts = max(pixelCounts(:));
Oliver Herbage
on 25 Oct 2016
2 votes
Using the function 'histogram.m' H = histogram(X) will plot a histogram and return details to 'H'
'H.Values' returns a vector of the values from these details and the max and min functions can then be used on this to obtain the max and min of the histogram (e.g. 'max(H.Values)' and 'min(H.Values)')
Sean de Wolski
on 29 Jul 2013
doc min
doc max
doc histc
doc min % and/or max
Look at alternate (optional) returns.
Categories
Find more on Histograms 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!