how can i find more than one minimum points of the histogram??
1 次查看(过去 30 天)
显示 更早的评论
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?
回答(2 个)
Image Analyst
2015-2-5
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 个评论
Image Analyst
2015-2-5
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
2015-2-6
编辑:Image Analyst
2015-2-6
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
2015-2-6
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
2015-2-7
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
2015-2-7
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
2015-2-8
this fig is histogram of lena image.and in this histogram i want to find 3 minimum points other than 0.
Image Analyst
2015-2-8
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
2015-2-9
Image Analyst
2015-2-9
编辑:Image Analyst
2015-2-9
% 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
2015-2-10
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
2015-2-11
编辑:Image Analyst
2015-2-11
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
2015-2-11
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
2015-2-11
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
2015-2-11
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
2015-2-12
i m not getting what u r saying... actually i need to make a algorithm i.e i m going to attach...
Image Analyst
2015-2-12
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
2015-2-13
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
2015-2-13
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
2015-2-15
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
2015-2-16
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
2015-2-16
Anamika, there are probably lots of bins that have only one count in them. Which three do you want?
Image Analyst
2015-2-16
编辑:Image Analyst
2015-2-17
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
2015-2-18
that is a hindi word, that i wrote in hurry...'how did i found that points as the answer?'.
Image Analyst
2015-2-20
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
2015-2-20
and the code u have given is just giving the first 3 minimum points. i want overall 3 minimum points
Jos (10584)
2015-2-17
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 个评论
Jos (10584)
2015-2-21
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
2015-2-21
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
2015-2-21
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)