-
Notifications
You must be signed in to change notification settings - Fork 10
/
demo.m
201 lines (168 loc) · 4.91 KB
/
demo.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
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
%%
% Example uses of the Panoramic Robust PCA (PRPCA) method to perform
% robust foreground-background separation from video with arbitrary camera
% motion.
%
% May 18, 2018
%
% B. E. Moore, C. Gao, and R. R. Nadakuditi, "Panoramic robust PCA for
% foreground-background separation on noisy, free-motion camera video,"
% arXiv:1712.06229, 2017.
%
% C. Gao, B. E. Moore, and R. R Nadakuditi, "Augmented robust PCA for
% foreground-background separation on noisy, moving camera video," in
% IEEE Global Conference on Signal and Information Processing (GlobalSIP),
% November 2017, pp. 1240-1244.
%
addpath('src/');
%% Noiseless (grayscale)
% Load data
Ytrue = [];
contents = dir('data/tennis/*.jpg');
for i = 1:numel(contents)
img = imread(sprintf('data/tennis/%s',contents(i).name));
Ytrue(:,:,i) = im2double(imresize(rgb2gray(img),0.5)); %#ok
end
% Perform Noiseless PRPCA
opts = struct();
opts.nIters = 25;
[pano, L, S, Lreg, Sreg] = PRPCA_noiseless(Ytrue,opts);
% Visualize registered decomposition
movie = [Lreg; Sreg];
opts2 = struct();
opts2.ylabels = {'foreground', 'backgrond'};
PlayMovie(movie,opts2);
% Visualize decomposition from original persepctive
movie = [Ytrue; L; S];
opts3 = struct();
opts3.ylabels = {'foreground', 'background', 'observations'};
PlayMovie(movie,opts3);
% Visualize panorama
figure();
imshow(pano,[]);
title('Panoramic background');
%% Noiseless (color)
% Load data
Ytrue = [];
contents = dir('data/tennis/*.jpg');
for i = 1:numel(contents)
img = imread(sprintf('data/tennis/%s',contents(i).name));
Ytrue(:,:,:,i) = im2double(imresize(img,0.5)); %#ok
end
% Perform Noiseless PRPCA
opts = struct();
opts.nIters = 25;
[pano, L, S, Lreg, Sreg] = PRPCA_noiseless(Ytrue,opts);
% Visualize panorama
figure();
imshow(pano,[]);
title('Panoramic background');
% Play results
movie = [Lreg; Sreg];
opts2 = struct();
opts2.ylabels = {'foreground', 'background'};
PlayMovie(movie,opts2);
% Play results in original ratio
movie = [Ytrue; L; S];
opts3 = struct();
opts3.ylabels = {'foreground', 'background', 'observations'};
PlayMovie(movie,opts3);
%% Noisy (grayscale)
rng(1);
% Load homographies
load('data/tennis/Tgray.mat')
% Load data
Ytrue = [];
contents = dir('data/tennis/*.jpg');
for i = 1:numel(contents)
img = imread(sprintf('data/tennis/%s',contents(i).name));
Ytrue(:,:,i) = im2double(imresize(rgb2gray(img),0.5)); %#ok
end
% Generate noisy, corrupted data
p = 0.2; % salt and pepper noise probability
M0 = (rand(size(Ytrue)) < 0.5 * p);
M1 = (rand(size(Ytrue)) < 0.5 * p);
Ynoisy = Ytrue;
Ynoisy(M0) = 1;
Ynoisy(M1) = 0;
PlayMovie(Ynoisy)
% Perform PRPCA
opts = struct();
opts.nIters = 150;
opts.nItersS = 10;
opts.T = T;
opts.lambdaS = 0.02;
opts.lambdaE = 0.02;
[pano, L, E, S, Lreg, Ereg, Sreg] = PRPCA(Ynoisy,opts);
% Visualize registered decomposition
movie = [Lreg; Sreg; Ereg];
opts2 = struct();
opts2.ylabels = {'sparse', 'foreground', 'background'};
PlayMovie(movie,opts2);
% Visualize decomposition from original persepctive
movie = [Ynoisy; L; S; E; L + S];
opts3 = struct();
opts3.ylabels = {'reconstruction', 'sparse', 'foreground', 'background', 'observations'};
PlayMovie(movie,opts3);
% Visualize panorama
figure();
imshow(pano,[]);
title('Panoramic background');
% Visualize key frames of decomposition
LS = L + S;
keyframes = [
[Ytrue(:,:,1); Ynoisy(:,:,1); L(:,:,1) ; E(:,:,1); S(:,:,1); LS(:,:,1)] ...
[Ytrue(:,:,17); Ynoisy(:,:,17); L(:,:,17); E(:,:,17); S(:,:,17); LS(:,:,17)]
];
figure();
imshow(keyframes);
title('Key frames of decomposition');
%% Noisy (color)
rng(1);
% Load homographies
load('data/tennis/Tcolor.mat')
% Load data
Ytrue = [];
contents = dir('data/tennis/*.jpg');
for i = 1:numel(contents)
img = imread(sprintf('data/tennis/%s',contents(i).name));
Ytrue(:,:,:,i) = im2double(imresize(img,0.5)); %#ok
end
% Generate noisy, corrupted data
p = 0.2; % salt and pepper noise probability
M0 = (rand(size(Ytrue)) < 0.5 * p);
M1 = (rand(size(Ytrue)) < 0.5 * p);
Ynoisy = Ytrue;
Ynoisy(M0) = 1;
Ynoisy(M1) = 0;
% Perform PRPCA
opts = struct();
opts.nIters = 150;
opts.nItersS = 10;
opts.T = T;
opts.lambdaS = 0.02;
opts.lambdaE = 0.02;
[pano, L, E, S, Lreg, Ereg, Sreg] = PRPCA(Ynoisy,opts);
% Visualize registered decomposition
movie = [Lreg; Sreg; Ereg];
opts2 = struct();
opts2.ylabels = {'sparse', 'foreground', 'background'};
PlayMovie(movie,opts2);
% Visualize decomposition from original persepctive
movie = [Ynoisy; L; S; E; L + S];
opts3 = struct();
opts3.ylabels = {'reconstruction', 'sparse', 'foreground', 'backgrond', 'observations'};
PlayMovie(movie,opts3);
% Visualize panorama
figure();
imshow(pano,[]);
title('Panoramic background');
% Visualize key frames of decomposition
LS = L + S;
keyframes = [
[Ytrue(:,:,:,1); Ynoisy(:,:,:,1); L(:,:,:,1); E(:,:,:,1); S(:,:,:,1); LS(:,:,:,1)] ...
[Ytrue(:,:,:,17); Ynoisy(:,:,:,17); L(:,:,:,17); E(:,:,:,17); S(:,:,:,17); LS(:,:,:,17)]
];
figure();
imshow(keyframes);
title('Key frames of decomposition');