Ensuring same bins in image histogram

조회 수: 7 (최근 30일)
Jason
Jason 2014년 12월 4일
댓글: Jason 2014년 12월 5일
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

채택된 답변

Image Analyst
Image Analyst 2014년 12월 4일
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);
  댓글 수: 5
Image Analyst
Image Analyst 2014년 12월 5일
If you don't want one bin per possible gray level you can set your bin edges to whatever width you want, like
binEdges = 0 : 66 : 65535;
thisCounts = histc(grayImage(:), binEdges);
I wouldn't use linspace if you know you want integers, though it will work.
Jason
Jason 2014년 12월 5일
OK, I will follow your advice, just out of curiosity, whats wrong with using linspace?.

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

추가 답변 (2개)

Thorsten
Thorsten 2014년 12월 4일
Use hist/histc with a second vector argument to specify bin centers/edges
N = HIST(Y,X), where X is a vector, returns the distribution of Y
among bins with centers specified by X. The first bin includes
data between -inf and the first center and the last bin
includes data between the last bin and inf. Note: Use HISTC if
it is more natural to specify bin edges instead.
  댓글 수: 2
Jason
Jason 2014년 12월 4일
I always though that this function wasn't the best to use with images? Thanks
Thorsten
Thorsten 2014년 12월 4일
These functions can be used with images; no problem.

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


Adam
Adam 2014년 12월 4일
[counts,x] = imhist(___)
should do the job so far as I can see. Of course your data with a range of 12000 will be spread over fewer bins than the data with a range of 65000, but then you'd expect that from what you want.
Then you should just be able to sum the counts together for the 10 images.
  댓글 수: 2
Jason
Jason 2014년 12월 4일
So can I dictate what the bin wodth should be or is it automatic? I guess I would find out by X(2)-x(1) ?? Thanks
Adam
Adam 2014년 12월 4일
편집: Adam 2014년 12월 4일
[counts,x] = imhist( I, n );
n is the number of bins so you if you want to specify bin width you can calculate n from that. Default is 256 bins.
Also note though that those bin values are taken from the data type. You need to be using int16 to have bins up to 65536, not single or double which provide histograms from 0 to 1.

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by