taking an average histogram from number of histograms

1 回表示 (過去 30 日間)
Muhammad Ali Qadar
Muhammad Ali Qadar 2013 年 8 月 4 日
コメント済み: Sabanam 2014 年 4 月 8 日
hi, I am trying to take to the average histogram from multiple histogram , I am trying like this
img = dir('C:\Program Files\MATLAB\R2012a\bin\Patches\*.png'); % the folder in which ur images exists
for i = 1 : length(img)
filename = strcat('C:\Program Files\MATLAB\R2012a\bin\Patches\',img(i).name);
I = imread(filename);
I=I(:,:,1);
I=im2double(I);
[rows, columns, numberOfColorBands] = size(I);
if numberOfColorBands > 1
I = rgb2gray(I);
end
% [count, bin]=imhist(I);
[bin,xout]=hist(I);
for i=1:bin
bin1=sum(bin(i))./max(bin);
end
bar(xout,bin);
end
somebody please suggest how could I get the average histogram if I am having number of histograms Same discussion cuold be found here mean histogram Thanks
  2 件のコメント
dpb
dpb 2013 年 8 月 4 日
Sure, just like the result of the thread you posted says--set a given range and number of bins then accumulate the counts in those bins and average.
doc histc
Muhammad Ali Qadar
Muhammad Ali Qadar 2013 年 8 月 6 日
can you please explain more with an example

サインインしてコメントする。

採用された回答

dpb
dpb 2013 年 8 月 6 日
I'm really no image processor but aiui, imhist returns 256 bins for a grayscale image so why isn't it simply the accumulation of all the counts in each bin for each image?
dirn='C:\Program Files\MATLAB\R2012a\bin\Patches';
% do the first to establish the histogram outputs
I = imread(fullfile(dirn,img(i).name));
I=I(:,:,1);
% Since you took the first plane here, the 3rd dim from size() will
% never be >1 so that's all superfluous in you code--if you do need to
% convert to grayscale, do it here though..
[cnt, bin]=imhist(I);
for i = 2 : length(img) % now accumulate rest...
filename = fullfile(dirn,img(i).name);
I = imread(filename);
I=I(:,:,1);
% ditto the above comment...
cnt=cnt+imhist(I); % the accumlator
end
cnt=cnt/length(img); % and average
stem(bin,cnt);
end
  2 件のコメント
Muhammad Ali Qadar
Muhammad Ali Qadar 2013 年 8 月 8 日
編集済み: Muhammad Ali Qadar 2013 年 8 月 8 日
yes This line
cnt=cnt/length(img)
infact important to me I think i Can do it now thank you , Later I will add my Solution also
Sabanam
Sabanam 2014 年 4 月 8 日
Its really useful code...

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeHistograms についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by