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