How to find an average of multiple images?

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일

0 개 추천

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

Sofya
Sofya 2014년 6월 25일
Yes, thank you very much. It is 'uint8'.
Although even after editing this part the problem remains, such that I'm still getting an average of the data from one single image rather than the average of all I images. Any ideas of how to improve that?
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개)

질문:

2014년 6월 25일

편집:

2014년 6월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by