I\'m new to Matlab processing, and I would like to read and process a large video (more than 200k frames) inside a \"for loop\" (or without it). In particular, i would like
Here is my version:
mov = VideoReader('movie.avi');
nFrames = mov.NumberOfFrames;
len = 1000; %# epoch length
step = 3; %# step size
%# indices of each epoch
indices = bsxfun(@plus, 1:step:len, (0:ceil(nFrames/len-1))'*len); %#'
indices = num2cell(indices,2);
indices{end}(indices{end}>nFrames) = [];
%# loop over each epoch
corr_coef = cell(size(indices));
for e=1:numel(indices)
%# read first image in epoch
img1 = read(mov, indices{e}(1));
img1 = rgb2gray(img1); %# instead of im2bw(img1, graythresh(img1))
%# read rest of images in epoch
corr_coef{e} = zeros(1,numel(indices{e})-1);
for f=2:numel(indices{e})
img2 = read(mov, indices{e}(f));
img2 = rgb2gray(img2);
%# compute corr2 between the two images
corr_coef{e}(f-1) = corr2(img1,img2);
end
end
The cell array corr_coef
contains the correlation coefficients in each epoch, where each cell contains a vector corr_coef{e}(i)
of corr2
between the first frame and the (i+1)-th frame.
Note that if one of the frames is constant (all black for example), the 2D correlation coefficient is simply NaN (zero divided by zero in the formula)