MATLAB: At what range histogram of 16 and 8 bins fall.

histogram

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().

Best Answer

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.