-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathApply_Motion.m
44 lines (40 loc) · 865 Bytes
/
Apply_Motion.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
function mov = Apply_Motion(mov,motion,mode)
% Apply a given motion to a video
%
% mov = Apply_Motion(mov,motion,mode)
%
% default: mode = 'rigid' (it also could be 'nonrigid')
%
% By Jesus Perez-Ortega, Dec 2019
if nargin==2
rigid = true;
elseif nargin==3
switch mode
case 'rigid'
rigid = true;
case 'nonrigid'
rigid = false;
end
end
% Get size
[y,x,frames] = size(mov);
% Apply motion
tic
if frames>1
disp('Applying motion...')
end
ten_perc = round(frames/10);
for i = 1:frames
if rigid
mov(:,:,i) = imwarp(mov(:,:,i),motion,'OutputView',imref2d([y x]));
else
mov(:,:,i) = imwarp(mov(:,:,i),motion,'nearest');
end
if ~mod(i,ten_perc)
t = toc;
fprintf(' %d %%, %.1f s\n',round(i/frames*100),t)
end
end
if frames>1
disp(' Done')
end