at what range histogram of 16 and 8 bins fall.
2 次查看(过去 30 天)
显示 更早的评论
when i am trying to make a histogram of an image without imhist(). my values does not match.
i=imread('lena.tif');
[count,b]=imhist(i,16);
what is the value of b? is b a range or interval ? if yes then what it is for each bin?
my program without imhist()
imData=imread('lena.tif');
for i=1:m
for j=1:n
histo=imData(i,j);
if ((histo==0) || (histo<=15))
count(1)=count(1)+1;
elseif ((histo==16) || (histo<=31))
count(2)=count(2)+1;
:
:
:
elseif((histo==224) || (histo<=239))
count(15)=count(15)+1;
else
count(16)=count(16)+1;
end
end
my value of this 'count' doesn't match with previous by using imhist().
0 个评论
采纳的回答
Image Analyst
2012-12-31
They are the bin centers. Look at this code to prove it:
myImage = uint8(0:255)
[pixelCounts grayValues] = imhist(myImage, 16)
pixelCounts =
9
17
17
17
17
17
17
17
17
17
17
17
17
17
17
9
grayValues =
0
17
34
51
68
85
102
119
136
153
170
187
204
221
238
255
Note how the first and last bins have only half the number of counts as the other bins? That's because they're centered at 0 and 255 and are only half the width of the other bins - they're 9 gray levels wide instead of 17 gray levels wide. So bin1 goes from 0 to 8, bin2 goes from 9 to 25, ... bin 16 goes from 247 to 255. It actually might go further but there are no 8 bit values past 255 so it ends there.
6 个评论
Walter Roberson
2013-1-3
Yes, there is logic. The first bin center goes at the minimum value, the last bin center goes at the minimum value, and the other (N-2) are placed equally in the range of values between the min and max. Placing (N-2) interior points at equal distances in the range (max-min) has them spaced (max-min)/(N-1) apart.
In this case, min = 0, max = 255, and (255-0)/(16-1) = 255/15 = 17, so the bin centers are 0:17:255
Perhaps you are asking about why this is done. It is not at all clear from the documentation, but we can see a small hint: http://www.mathworks.com/help/matlab/ref/hist.html
n = hist(Y) bins the elements in vector Y into 10 equally spaced containers
notice "equally spaced" is used, not "equal length". It isn't much to go on.
I do not know why this was chosen. The fact is that it was. If you want something different, then use hist() or histc() instead of imhist(), or write your own histogramming function. Hint: histc(). Or if you insist on not using histc() then use accumarray()
更多回答(1 个)
Walter Roberson
2012-12-31
I think the bins returned in "b" are the bin centers, such as would be returned by hist().
Note: you do not need the (histo==NUMBER) part of your code
if histo <= 15
count(1)=count(1)+1;
elseif histo <= 31
count(2)=count(2)+1;
and so on.
Or, much more compact, get rid of the if/elseif tree and use
binnum = 1 + floor(histo / 16);
count(binnum) = count(binnum) + 1;
另请参阅
类别
在 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!