how can i find more than one minimum points of the histogram??

Suppose I have a histogram and I want to find the minimum point of the histogram other than 0, then what procedure I should follow? In the histogram image below, the minimum point is approximately 10,15,17. Then how can I find this?

Answers (2)

Try this
% Get histogram
[pixelCounts, grayLevels] = imhist(grayImage);
% Find darkest bin with more than 15 pixels in it
darkestGL = find(pixelCounts > 15, 1, 'first');

36 Comments

this is not what i want. it is giving the nos from 1 onwards.
OK.
But what does that mean?
You can adjust the 15 in my code to be whatever you want to select whatever x value (bin, gray level) you want. Attach your data if you want more help.
Your code is just giving the continuous no...
I=imread('lena.jpg');
% Get histogram
[pixelCounts, grayLevels] = imhist(I);
% Find darkest bin with more than 15 pixels in it
darkestGL = find(pixelCounts > 12, 56, 'first');
%imhist(I);
fprintf('%d, ',darkestGL);
That's not my code exactly - you modified it to take the first 56 gray levels after the count exceeded 12. The counts exceed 12 around maybe gray level 30 or so. So, since graylevels from 30 on up to about 240 are all above 12, you will get the first 56 of those, which would be gray levels of 30 to 30 + 56 -1 = 30 to 85. In other words, you'll get an array like [30,31,32,33,34,35,........84,85].
I have no idea why you changed my code to return 56 gray levels instead of 1 (the very first one only).
i was jst checking that code thats why i modified it.but i want three minimum point as i explained in the ques with the help of a graph. plz help
I'm having trouble with your English. You said "the minimum point is approximately 10,15,17." Well, point is singular but you list 3 gray levels, not one . So did you really mean "the minimum points are approximately 10,15, and 17." I have no idea .
And my code gave a single number so I don't understand what it means when you say my code is "giving the continuous no." Again, it's a single number , not a range of continuous anything .
And I don't understand how modifying the call to find to return 56 elements will get 3 of anything. I'm not sure how checking my code involved modifying it to return 56 elements instead of the one minimum element.
Like I asked you before to make it easier to help you "Attach your data if you want more help." Like the lena image or the histogram array. You are not attaching anything. I do not know why.
I really have no idea how to help you now, unless you attach data and clearly explain what gray levels or counts in your histogram you want to detect/extract/determine/find.
this fig is histogram of lena image.and in this histogram i want to find 3 minimum points other than 0.
You did not answer any of my questions at all - you just paraphrased the same unclear request. lena is not a standard image that ships with MATLAB, and neither is your code. Now, for the third time , I'm asking you to attach your data (image plus code). If you don't do that I'll assume you don't want anymore help.
Also again, explain if you want the minimum gray levels with non-zero counts or the minimum counts (at whatever gray level they happen to occur at).
actually i have divided the lena image into 4 non overlapping blocks, and generated the histogram of each and every block, now what i need to do is find the 3 minimum gray levels except zero.
% Check which bins, other than the first one at zero gray level,
% are not zero:
nonZeroBins = find(pixelCounts1(2:end) > 0);
% Add 1 to get bins referenced to the full array again.
nonZeroBins = nonZeroBins + 1;
% Extract only the 3 darkest gray levels.
darkest3GLs = grayLevels1(nonZeroBins(1:3));
sorry to say but now also it is giving the 1 2 3 as the output of the histogram of the lena image, that i send u.i want the minimum points on the x axis...
Look at the histogram and tell me what values (gray levels, bins) would you want it to return? Don't make me guess again.
I have a doubt. If I write this, then I get an error.
a= imread('lena.jpg');
b=imresize(a,[256 256]);
imhist(b);
[pixelCounts, grayLevels] = imhist(b);
nonZeroBins = find(pixelCounts(2:end) > 0);
% Add 1 to get bins referenced to the full array again.
nonZeroBins=nonZeroBins+1;
% Extract only the 3 darkest gray levels.
darkest3GLs = grayLevels(nonZeroBins(1:3));
fprintf('%d ',darkest3GLs);
and the error is:
Attempt to call constructor image with incorrect letter case.
Error in ==> imhist>plot_result at 166
image(xdata,[0 1],repmat(C, [1 1 3]),'Parent',stripe_axes);
Error in ==> imhist at 90
plot_result(x, y, map, isScaled, class(a), range);
Error in ==> checking at 3
imhist(b);
and in the histogram i want 2 1 3 as the ans on the x axis.
First of all, I ran your code and it works find and does not give an error in imhist and does not display an image like you just showed. This is what it displays:
Somehow you must have converted a or b to double.
But I really don't know what you mean when you say you want 2 1 3 on the x-axis. Why? Instead of all the gray levels that are normally placed by the x-axis tick marks?
ok. i figured out that nw there is no error.. i need to find three minimum point or u can say 3 garay level with minimum value,they can be any where on the x axis.
The three darkest gray levels are 0, 1, and 2. The 3 darkest gray levels that are present in the image can be gotten with the code I gave you that finds the 3 darkest bins that have at least one pixel counted in them. Bin 0 has 4 pixels in it. Bin 1 has 4 pixels in it, and bin 2 has 2 pixels in it. Therefore they are the three minimum gray levels. Do you have some different definition? If so, what?
i m not getting what u r saying... actually i need to make a algorithm i.e i m going to attach...
Oh, it's a homework problem, though I'd agree with you it's a very poorly written one with several notational errors and ambiguities. You were supposed to reveal it was homework in the beginning by tagging it as homework. I'll do that for you.
I've given you code to do much of your homework already. Which of the questions do you need a hint for? Or my guess at what the instructor is asking for (in an admittedly unclear manner in many of the questions)?
actually i need to find the points which is described in the section b step 2 of the algorithm. or is there a way by that we can store the histogram values in array or we sort that array, by that 3 minimum points we can get easily?
What is the difference between the H array and the h array?
Try this:
grayImage = imread('lena.jpg');
% Get histogram
[h, grayLevels] = imhist(grayImage);
% Sort the counts to find the gray levels with the fewest counts
% Let's assume they don't really want to count bins with no pixels in them
% because those gray levels are not present in the actual image.
% So set those bins = inf so they won't be sorted
h(h == 0) = inf;
% Now do the sort in order of increasing count:
[sortedGLs, sortIndexes] = sort(h, 'ascend');
% Find the 3 bins with the fewest number of counts in them
darkestGLs = sortIndexes(1:3)
% Sort in increasing order of gray levels
% Because even though the counts are sorted,
% the bin numbers (gray levels) could be anywhere.
darkestGLs = sort(darkestGLs, 'Ascend');
% Get the "b"s
b1 = darkestGLs(1)
b2 = darkestGLs(2)
b3 = darkestGLs(3)
% Get the counts in those bins:
hb1 = h(b1)
hb2 = h(b2)
hb3 = h(b3)
now it is giving 1 1 1 as answer
Yes. That's right. Because the three darkest bins each have one pixel in them. Do you not think that's right? Look at what your professor says:
"In the histogram, find three minimum point h(b1), h( b2), h(b3). Assume three of them satisfy the following condition: 0<b1<b2<b3<255."
So if the h array is the histogram, meaning that it is an array holding the counts of pixels having each gray level, then, assuming you don't want to consider gray levels that have no pixels with that intensity, the minimum h(bin) would be where h(bin) equals 1, meaning it has one pixel with that gray level in the image. Then I found three gray levels that had 1 count. Why are you uncertain about this?
but it is showing 1 1 1 then by that b1=b2 =b3. and if this is the case then in the next step we have to determine maximum points between (0,b1) and(b3,255) then ??????
Anamika, there are probably lots of bins that have only one count in them. Which three do you want?
bins means interval right?
i want point that is lowest then second lowest then third lowest
I did that. The lowest bin has one count in it and it occurs at bin 236. The second lowest bin also has only one pixel in it, and it occurs at gray level 237, and the third lowest bin also has only one count in it and it occurs at 247. In fact, there are 6 bins , not only 3, that have only one pixel counted in them.
are yr to how did i found that levels as the ans.
I don't know what that means. What does the word "yr" mean in English?
that is a hindi word, that i wrote in hurry...'how did i found that points as the answer?'.
I'm afraid I don't know how to help any differently. I gave you code that will answer the homework question but, for some reason that you can't explain, you don't like it. You say it doesn't give the 3 lowest/shortest bins, but it actually does . So good luck with it - finding your own algorithm.
do one thing, attach the image and the histogram and the result...
and the code u have given is just giving the first 3 minimum points. i want overall 3 minimum points

Sign in to comment.

You can sort the outcome of the histogram
data = ceil(10*rand(100,1))
values = 1:10
count = histc(data,values)
[SortedCount, idx] = sort(count)
SortedValues = values(idx)
disp([SortedValues(:) SortedCount(:)])

6 Comments

the code is not giving the sorted value for the image.
it is giving the interval from 1 to 10 and giving its count..
Yes, because data is just an example containing values between 1 and 10. Then I sorted the count in ascending order, and sorted the values along with it. The first element of the sorted counts is belonging to the value that occurs least often (i.e., the minimum of the histogram!), the second element is the second minimum etc. If you run the code and look out the outputs you may see what happens.
it is not sorting values as per the requirement. i want sorted values on x axis with respect to y. means the value on the x axis having the lowest value on the y axis, that should come first and so on.
I did that in my code above. Like I said, "the lowest bin has one count in it and it occurs at bin 236. The second lowest bin also has only one pixel in it, and it occurs at gray level 237, and the third lowest bin also has only one count in it and it occurs at 247." Explain why 1 is not the lowest y value (count in the bin), and explain why 236,237,247 is not sorted.

Sign in to comment.

Asked:

on 5 Feb 2015

Commented:

on 21 Feb 2015

Community Treasure Hunt

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

Start Hunting!