MATLAB: Ensuring same bins in image histogram

histogram

Hi, I have say 10 images that have been constructed from various amounts of summing 12 bit images. Nothing exceeds 16 bit i.e. no intensity is greater that 65535. Practically, the max intensity of the 10 images could range from anywhere between 12000 cts and 65535 counts. I want to create a histogram that combines all 10 images.
I cna do this if I use the number of bins nbins=65536. But for memory purposes, I want to reduce the number of bins to say 1000. The problem I think is that taking the two extreme images with max counts 12000 and 65535, will the binning into 1000 intensity levels be the same for both so I can just add their histograms. If not, how can i make sure that each bin is the same so for nbins=1000
1st bin =66 2nd bin =2*66
etc, rather than just taking the maxval of the image and then dividing this by 1000.
Thanks Jason

Best Answer

There will be no memory problem with one or two arrays of 65536 elements.
I agree with thorsten. If you want to be sure the bins are where you want then use histc()
overallHistogram = zeros(1, 65536)
for k = 1 : numberOfImages
grayImage = imread(................
% Get counts for this image.
thisCounts = histc(grayImage(:), 0:65535);
% Accumulate into our histogram that will sum all histograms.
overallHistogram = overallHistogram + thisCounts;
end
bar(overallHistogram);