Created
April 8, 2014 23:58
-
-
Save MadisonTBlake/10210819 to your computer and use it in GitHub Desktop.
Computes the average of each pixel in a video file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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