필터 지우기
필터 지우기

at what range histogram of 16 and 8 bins fall.

조회 수: 2 (최근 30일)
preet
preet 2012년 12월 31일
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().

채택된 답변

Image Analyst
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
preet
preet 2013년 1월 3일
there is any logic to divide the values in this way....half to the first and last bin....
in general if we talk about 8bins corresponding to 256 values..the it should be divide the rang of bins into equal . like 256/8=32...but here is somthing different in Matlab..
Walter Roberson
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
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;
  댓글 수: 1
preet
preet 2012년 12월 31일
thanx for compact code.. the value of b is for gray scale image
0
17
34
51
68
85
102
119
136
153
170
187
204
221
238
255
this s not the center..i think

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by