Skip to content

Instantly share code, notes, and snippets.

@MadisonTBlake
Created April 8, 2014 23:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save MadisonTBlake/10210819 to your computer and use it in GitHub Desktop.
Save MadisonTBlake/10210819 to your computer and use it in GitHub Desktop.
Computes the average of each pixel in a video file.
filepath = 'C:\\bf4 2013-12-07 02-22-08-62.avi';
clc;
try
v_handle = VideoReader(filepath);
% video_frames = read(v_handle);
catch err
error('prog:input', 'Invalid filepath! Enter as ''C:\\filelocation\\file.avi'' ');
end
numFrames = v_handle.NumberOfFrames;
tic;
%Big as possible that can still run in your memory
PartitionSize = 500;
total = zeros(v_handle.Height, v_handle.Width, 3);
for n=1:PartitionSize:numFrames
stop = n+PartitionSize - 1;
if(stop > numFrames)
stop = numFrames;
end
A = read(v_handle, [n stop]);
%Automatically converted to double by MATLAB
B = sum(A,4);
total = total + B;
end
total = total./numFrames;
toc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment