How do I find the maximum and minimum of a histogram in MATLAB?

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.
I have already created the histogram and my problem is that i couldn't find the maximum value of the intensity axes.is there any command MATLAB for that?
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.
for example: i have one image with these intensity: 13 , 23 , 23 , 13 , 6 , 1 , 3 , 1 , 1 , 1 , 2, 5 , 5, 13, 5, 1, 3, 4 , 3, 1, 1, 2, 6, 3, 1, 0, 0, 2, 3, 23, 3, 1 , 3. max=1 , min=4

Sign in to comment.

Answers (4)

[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(:));

1 Comment

let me give you one example: we have axis X and axis Y. any maximum point in a plot has individual X and Y value. So,Im looking for X and Y values of maximum point in a histogram. by these commands i can get only Y value of maximum point how about X value?

Sign in to comment.

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)')
doc min % and/or max
Look at alternate (optional) returns.

Tags

Asked:

on 29 Jul 2013

Answered:

on 25 Oct 2016

Community Treasure Hunt

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

Start Hunting!