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

1 次查看(过去 30 天)
Hi, 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
Thank you, Minh

采纳的回答

Matt Fig
Matt Fig 2011-3-28
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by