How to find an average of multiple images?

7 views (last 30 days)
Sofya
Sofya on 25 Jun 2014
Edited: Sofya on 26 Jun 2014
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

Accepted Answer

Ben11
Ben11 on 25 Jun 2014
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 Comments
Ben11
Ben11 on 25 Jun 2014
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 on 25 Jun 2014
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.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!