How to read and add 100 consecutive images

2 次查看(过去 30 天)
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 个评论
Walter Roberson
Walter Roberson 2024-3-4
TifImage = imread(['test_163',num2str(i),'.tif']);
num2str() does not emit leading 0 by default.
TifImage = imread(['test_163',num2str(i, '%02d'),'.tif']);

请先登录,再进行评论。

回答(1 个)

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

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by