How to find an average of multiple images?
7 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
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
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.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!