How to read and add 100 consecutive images

2 visualizzazioni (ultimi 30 giorni)
Adrian
Adrian il 4 Mar 2024
I need to be able to read and add 100 consecutive images with Imread. I have about 19000 images, so I will need to use a for loop. I need to read 100 consecutive images, and repeat the process for all images.
I was working with this code. I don't know how to change the formatting so I can read 100 images, since so far I was just taking the last two images of the start image, and adding 30 or 40 consecutive images. This code is an example of what I ussed to add (and average) 80 consecutive images that I selected randomly from my 19000 images.
%CHANGE THE FIRST IMAGE OF THE SEQUENCE HERE (my first image is 00001)
filename = 'test_16310.tif';
%number of consecutive images you want to average:
images=80;
I0 = imread(filename);
% original line of code: lastTwoDigits = str2double(filename(end-5:end-4));
lastTwoDigits = str2double(filename(end-5:end-4));
sumImage = im2double(I0); % Inialize to first image. The double function is used to convert
% the image data from the default integer data type to double-precision, which allows for more accurate arithmetic operations.
for i=(lastTwoDigits+1):(lastTwoDigits+images) % Read remaining images.
TifImage = imread(['test_163',num2str(i),'.tif']);
sumImage = sumImage + double(TifImage);
end
meanImage = sumImage / images;
  1 Commento
Walter Roberson
Walter Roberson il 4 Mar 2024
TifImage = imread(['test_163',num2str(i),'.tif']);
num2str() does not emit leading 0 by default.
TifImage = imread(['test_163',num2str(i, '%02d'),'.tif']);

Accedi per commentare.

Risposte (1)

Image Analyst
Image Analyst il 4 Mar 2024
See attached demo file where I do exactly that. Adapt as needed.

Prodotti


Release

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by