Repository navigation
Expand file tree
/
Copy pathBPDN_video.m
More file actions
135 lines (120 loc) · 3.86 KB
/
Copy pathBPDN_video.m
File metadata and controls
135 lines (120 loc) · 3.86 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
function [varargout] = BPDN_video(varargin)
% [vid_coef_cs, vid_recon_cs, vid_rMSE_cs, vid_PSNR_cs] = ...
% BPDN_video(MEAS_SIG, MEAS_SEL, lambda_val, TOL, TRUE_VID)
%
% The inputs are:
%
% MEAS_SIG: Mx1xT array of the measurements for the video frames
% MEAS_FUN: Tx1 or 1x1 cell array of the measurement functions
% lambda_val: Scalar value for the BPDN sparsity tradeoff
% TOL: Scalar value for the tolerance in the TFOCS solver
% DWTfunc: Wavelet transform (sparsity basis)
% TRUE_VID: Sqrt(N)xSqrt(N)xT array of the true video sequence (optional,
% to evaluate errors)
%
% The outputs are:
%
% vid_coef_cs: Nx1xT array of inferred sparse coefficients
% vid_recon_cs: Sqrt(N)xSqrt(N)xT array of the recovered video sequence
% vid_rMSE_cs: Tx1 array of rMSE values for the recovered video
% vid_PSNR_cs: Tx1 array of PSNR values for the recovered video
%
% Code by Adam Charles,
% Department of Electrical and Computer Engineering,
% Georgia Institute of Technology
%
% Last updated August 20, 2012.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Parse Inputs
MEAS_SIG = varargin{1};
MEAS_FUN = varargin{2};
lambda_val = varargin{3};
TOL = varargin{4};
DWTfunc = varargin{5};
if nargin > 5
rMSE_calc_opt = 1;
TRUE_VID = varargin{6};
else
rMSE_calc_opt = 0;
end
DWT_apply = DWTfunc.apply;
DWT_invert = DWTfunc.invert;
meas_func = MEAS_FUN{1};
Phit = meas_func.Phit;
M = numel(MEAS_SIG(:, :, 1));
N2 = numel(DWT_apply(Phit(MEAS_SIG(:, :, 1))));
num_frames = size(MEAS_SIG, 3);
opts.tol = TOL;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Run BPDN on each frame
for kk = 1:num_frames
tic
% Set up the measurement function
if numel(MEAS_FUN) == 1
meas_func = MEAS_FUN{1};
elseif numel(MEAS_FUN) == num_frames
meas_func = MEAS_FUN{kk};
else
error('You need either the same dynamics function for all time or one dynamics function per time-step!')
end
Phi = meas_func.Phi;
Phit = meas_func.Phit;
% Set up A and At for TFOCS
Af = @(x) Phi(DWT_invert(x));
Ab = @(x) DWT_apply(Phit(x));
A = linop_handles([M, N2], Af, Ab, 'R2R');
% Solve the BPDN objective
res = solver_L1RLS( A, MEAS_SIG(:, :, kk), lambda_val, zeros(N2, 1), opts );
im_res = DWT_invert(res);
% Save reconstruction results
vid_coef_cs(:, :, kk) = res;
vid_recon_cs(:, :, kk) = im_res;
if rMSE_calc_opt == 1
vid_rMSE_cs(kk) = sum(sum((vid_recon_cs(:, :, kk) - TRUE_VID(:, :, kk)).^2))/sum(sum(TRUE_VID(:, :, kk).^2));
vid_PSNR_cs(kk) = psnr(real(vid_recon_cs(:, :, kk)), TRUE_VID(:, :, kk), 1);
TIME_ITER = toc;
fprintf('Finished frame %d of %d in %f seconds. PSNR is %f. rMSE is %f. \n', kk, num_frames, TIME_ITER, vid_PSNR_cs(kk), vid_rMSE_cs(kk))
else
TIME_ITER = toc;
fprintf('Finished frame %d of %d in %f seconds.\n', kk, num_frames, TIME_ITER)
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Set ouptputs
if (rMSE_calc_opt == 1)
if nargout > 0
varargout{1} = vid_coef_cs;
end
if nargout > 1
varargout{2} = vid_recon_cs;
end
if nargout > 2
varargout{3} = vid_rMSE_cs;
end
if nargout > 3
varargout{4} = vid_PSNR_cs;
end
if nargout > 4
for kk = 5:nargout
varargout{kk} = [];
end
end
elseif (rMSE_calc_opt ~= 1)
if nargout > 0
varargout{1} = vid_coef_cs;
end
if nargout > 1
varargout{2} = vid_recon_cs;
end
if nargout > 2
for kk = 3:nargout
varargout{kk} = [];
end
end
else
error('How did you get here?')
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%