You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
how can i find more than one minimum points of the histogram??
2 views (last 30 days)
Show older comments
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)
Image Analyst
on 5 Feb 2015
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
Image Analyst
on 5 Feb 2015
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.
user06
on 6 Feb 2015
Edited: Image Analyst
on 6 Feb 2015
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);
Image Analyst
on 6 Feb 2015
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).
user06
on 7 Feb 2015
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
Image Analyst
on 7 Feb 2015
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.
user06
on 8 Feb 2015
this fig is histogram of lena image.and in this histogram i want to find 3 minimum points other than 0.
Image Analyst
on 8 Feb 2015
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).
user06
on 9 Feb 2015
Image Analyst
on 9 Feb 2015
Edited: Image Analyst
on 9 Feb 2015
% 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));
Image Analyst
on 10 Feb 2015
Look at the histogram and tell me what values (gray levels, bins) would you want it to return? Don't make me guess again.
user06
on 11 Feb 2015
Edited: Image Analyst
on 11 Feb 2015
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.
Image Analyst
on 11 Feb 2015
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?
user06
on 11 Feb 2015
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.
Image Analyst
on 11 Feb 2015
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?
user06
on 12 Feb 2015
i m not getting what u r saying... actually i need to make a algorithm i.e i m going to attach...
Image Analyst
on 12 Feb 2015
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)?
user06
on 13 Feb 2015
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?
Image Analyst
on 13 Feb 2015
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)
Image Analyst
on 15 Feb 2015
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?
user06
on 16 Feb 2015
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 ??????
Image Analyst
on 16 Feb 2015
Anamika, there are probably lots of bins that have only one count in them. Which three do you want?
Image Analyst
on 16 Feb 2015
Edited: Image Analyst
on 17 Feb 2015
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.
user06
on 18 Feb 2015
that is a hindi word, that i wrote in hurry...'how did i found that points as the answer?'.
Image Analyst
on 20 Feb 2015
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.
user06
on 20 Feb 2015
and the code u have given is just giving the first 3 minimum points. i want overall 3 minimum points
Jos (10584)
on 17 Feb 2015
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
Jos (10584)
on 21 Feb 2015
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.
user06
on 21 Feb 2015
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.
Image Analyst
on 21 Feb 2015
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.
See Also
Categories
Find more on Data Distribution Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)