How to sum 20 images in a loop
Show older comments
Hello everybody I'm wondering how I can sum more than 15 images in a loop?
Here is the code:
imgs=<500x500x20 uint8> % 20 images
NI=size(imgs,3); % NI = Number of Images (i.e. = 20)
for e=2:NI % e = from 2 to 20 with step 1 (i.e 2,3,4....20)
I1(:,:,e-1)= imgs(:,:,1)-imgs(:,:,e); % subtract all other 19 images form the first image
figure; imshow(I1(:,:,e-1),[]); % plot results of each single subtractions
end
% Now I want to sum all subtracted images, how can I do it?
I have tried:
for i=1:size(I1,3)
I2= sum(I1(:,:,i));
end
for i=2:size(I1,3)
i3= imadd(I1(:,:,i),I1(:,:,i-1));
end
Can anyone give me line of code how to do it?
Accepted Answer
More Answers (1)
Image Analyst
on 10 Dec 2014
Edited: Image Analyst
on 10 Dec 2014
Did you try not using a loop and simply using the sum function?
I2 = sum(double(I1), 3);
??? What you are doing is taking a slice, and summing the rows along the columns, so you have a row vector where each element is the sum along the columns.
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!