現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
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.
Image Analyst
2015 年 2 月 17 日
I don't know what that means. What does the word "yr" mean in English?
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!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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 (한국어)