How to find an average of multiple images?

10 ビュー (過去 30 日間)
Sofya
Sofya 2014 年 6 月 25 日
編集済み: Sofya 2014 年 6 月 26 日
Hi,
I'm trying to get an averaged array of several images. Here's a part of the code I've written:
im=cell(1,length(filenames));
for n=1:length(filenames)
filename=filenames{n};
FullFileName=[pathname,filename];
im{n} = imread(FullFileName);
%figure,imshow(im{n})
end
I want to find a linear combination of all im{} and then find the average, I tried:
Z=imlincomb(1,im{1},1,im{2},1,im{3},...
1,im{n},'uint16');%finds a linear combination of image arrays but only for 4 images,even if I select more
X=imdivide(Z,n); %finds the average
Y=uint8(X); %returns type to 'uint8'
figure, imshow(Y)
The main problem is to get imlincomb to include all the im{}. Is there any way of doing that?
Thanks in advance.
Sofya

採用された回答

Ben11
Ben11 2014 年 6 月 25 日
What is the class of I? It looks like sumI and I are not of the same class.
Eg. if it is uint8, then use this line when you declare sumI:
sumI = zeros([x,y,z],'uint8');
  3 件のコメント
Ben11
Ben11 2014 年 6 月 25 日
ok nice. Hum maybe something like this:
sumI = zeros([x,y,z],'uint8');
Z = zeros([x,y,z,n],'uint8');
for i=1:n
I=getimage(figure(i));
Z(:,:,:,i) = imlincomb(.5,I,.5,sumI);
figure, imshow(Z(:,:,:,i),[])
end
Do you want to open multiple figures? If not you could store your images in a cell array and use a single figure with a slider, for example, to scroll through them.
Sofya
Sofya 2014 年 6 月 25 日
Thanks,it works but this time it finds an average per image and displays each averaged image.
I don't particularly want to open all the figures, I just use them more for observation at the moment. From this code at the end I will only need the averaged image. So the cell array with a single figure and a slider would definitely be nicer but not necessary, unless it helps to solve averaging issue.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by