-
Notifications
You must be signed in to change notification settings - Fork 1
/
inter_frame_differencing.m
55 lines (45 loc) · 1.22 KB
/
inter_frame_differencing.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
% Inter-Frame Differencing Method
clc, clearvars, close all
% Read the Video file
obj = VideoReader('motions\jump.avi');
% Inilialize number of frames 'f' by 1
f = 1;
% Extract individual frames
while hasFrame(obj)
% Read frames as grayscale
frames(:,:,f) = rgb2gray(readFrame(obj));
% Increment f by 1
f = f+1;
end
% Total number of frames
f = f-1;
% Find inter-frame differences
for i = 2:f
% Absolute difference between two consective frames
diff{i-1} = imabsdiff(frames(:,:,i), frames(:,:,i-1));
end
% Define MEI parameter w
w = 15;
% Start global loop for each frame
for i = 1:f-1
% Get MEI array for each frame i.e. H(x,y,t,T)
mei{i} = diff{i}.*w;
% Begin looping through each pixel
for y = 1:size(diff,1)
for x = 1:size(diff,2)
if mei{i}(y,x) == 255
mei{i}(y,x) = w;
else
if mei{i}(y,x) > 1
mei{i}(y,x) = mei{i}(y,x) - 1;
else
mei{i}(y,x) = 0;
end
end
end
end
% Display motion
figure(1);
imshow(mei{i},[])
title(['Frame ',num2str(i)])
end