-
Notifications
You must be signed in to change notification settings - Fork 0
/
amplify_spatial_Gdown_temporal_ideal.m
94 lines (69 loc) · 2.57 KB
/
amplify_spatial_Gdown_temporal_ideal.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
% amplify_spatial_Gdown_temporal_ideal(vidFile, outDir, alpha,
% level, fl, fh, samplingRate,
% chromAttenuation)
%
% Spatial Filtering: Gaussian blur and down sample
% Temporal Filtering: Ideal bandpass
%
% Copyright (c) 2011-2012 Massachusetts Institute of Technology,
% Quanta Research Cambridge, Inc.
%
% Authors: Hao-yu Wu, Michael Rubinstein, Eugene Shih,
% License: Please refer to the LICENCE file
% Date: June 2012
%
function amplify_spatial_Gdown_temporal_ideal(vidFile,outDir,alpha,level, ...
fl,fh,samplingRate, chromAttenuation)
[~,vidName] = fileparts(vidFile);
outName = fullfile(outDir,[vidName '-ideal-from-' num2str(fl) ...
'-to-' num2str(fh) ...
'-alpha-' num2str(alpha) ...
'-level-' num2str(level) ...
'-chromAtn-' num2str(chromAttenuation) '.avi']);
% Read video
vid = VideoReader(vidFile);
% Extract video info
vidHeight = vid.Height;
vidWidth = vid.Width;
nChannels = 3;
fr = vid.FrameRate;
len = vid.NumberOfFrames;
temp = struct('cdata', zeros(vidHeight, vidWidth, nChannels, 'uint8'), 'colormap', []);
startIndex = 1;
endIndex = len-10;
vidOut = VideoWriter(outName);
vidOut.FrameRate = fr;
open(vidOut)
% compute Gaussian blur stack
disp('Spatial filtering...')
Gdown_stack = build_GDown_stack(vidFile, startIndex, endIndex, level);
disp('Finished')
% Temporal filtering
disp('Temporal filtering...')
filtered_stack = ideal_bandpassing(Gdown_stack, 1, fl, fh, samplingRate);
disp('Finished')
%% amplify
filtered_stack(:,:,:,1) = filtered_stack(:,:,:,1) .* alpha;
filtered_stack(:,:,:,2) = filtered_stack(:,:,:,2) .* alpha .* chromAttenuation;
filtered_stack(:,:,:,3) = filtered_stack(:,:,:,3) .* alpha .* chromAttenuation;
%% Render on the input video
disp('Rendering...')
% output video
k = 0;
for i=startIndex:endIndex
k = k+1
temp.cdata = read(vid, i);
[rgbframe,~] = frame2im(temp);
rgbframe = im2double(rgbframe);
frame = rgb2ntsc(rgbframe);
filtered = squeeze(filtered_stack(k,:,:,:));
filtered = imresize(filtered,[vidHeight vidWidth]);
filtered = filtered+frame;
frame = ntsc2rgb(filtered);
frame(frame > 1) = 1;
frame(frame < 0) = 0;
writeVideo(vidOut,im2uint8(frame));
end
disp('Finished')
close(vidOut);
end