How do i loop this fuction and each time use a different AVI for processing

Illustration
Lucian - 2020-09-26T11:27:33+00:00
Question: How do i loop this fuction and each time use a different AVI for processing

I made a Function that will get an AVI and remove the background by using Z-stack so the image is easier to track the moving objects. But i want to do this for a series of AVI files but i'm not sure where to start. I know i should use loop but i don't know how to input the location of the AVIs per loop. Basically i want the fuction to get say an AVI-1 and process it then process AVI-2, then AVI-3, etc. The Bold is the Function and the Italic is the description: Vid1 = VideoReader('Moviessmall.avi') %# Allow MATLAB to recognize the file by using VideoReader Vid1Frames = read(Vid1) %# RECOGNIZING the Frames in the movie Vid2Frames = rgb2gray(Vid1Frames); %# Change the movie to a GRAY SCALE movie. limiting the movie to 3 arrays Vid3Frames = Vid1Frames(:,:,1:450); %# Stacks Z-PROJECT VidB = median(Vid3Frames, 3); %# Run a MEDIAN to get a background image VidB2 = repmat(VidB, [1 1 450]); %# Because images need to be of the same FRAME number to Subtract a Frame duplication with repeat must be done Vid2 = Vid3Frames-VidB2; %# The SUBTRACTION to get an array Vid2 = Vid3Frames-VidB2; %# The SUBTRACTION to get an array

Expert Answer

Profile picture of John Williams John Williams answered . 2025-11-20

You could put the names of the files in a cell array then loop over the array.

% This array stores the names of the files.
C = {'Moviessmall.avi';'Moviessmall_2.avi';'Moviessmall3.avi'};

for ii = 1:length(C)
  Vid1 = VideoReader(C{ii})
  % The rest of your code... If you need to store data, use a cell.
end


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!