forked from andrewssobral/lrslibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.m
118 lines (103 loc) · 3.54 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
%% LRSLibrary: A <Low-Rank and Sparse tools> Library for Background Modeling and Subtraction in Videos
close all; clear all; clc;
%% GUI
run;
%% UTILS
video2mat('dataset/demo.avi', 'dataset/demo.mat');
video = load_video_file('dataset/demo.avi');
show_video(video);
%%% 2D demo
M = im2double(convert_video_to_2d(video));
show_2dvideo(M,video.height,video.width);
%%% 3D demo
video3d = im2double(convert_video_to_3d(video));
show_3dvideo(video3d);
%%% 3D tensor demo
add_tensor_libs;
T = convert_video_to_3dtensor(video);
slice3(double(T)), colormap('gray');
rem_tensor_libs;
%%% 4D demo
video4d = convert_video_to_4d(video);
video4d = crop_4dvideo(video4d,1,10);
video4d = resize_4dvideo(video4d,2);
show_4dvideo(video4d);
%% DEMO 01
load('dataset/trafficdb/traffic_patches.mat');
V = im2double(imgdb{100});
show_3dvideo(V);
%%% Matrix-based algorithms
[M, m, n, p] = convert_video3d_to_2d(V);
show_2dvideo(M,m,n);
% Robust PCA
results = process_matrix('RPCA', 'FPCP', M, []);
show_results(M,results.L,results.S,results.O,1,m,n);
% Low Rank Recovery
results = process_matrix('LRR', 'FastLADMAP', M, []);
show_results(M,results.L,results.S,results.O,p,m,n);
% Non-Negative Matrix Factorization
results = process_matrix('NMF', 'ManhNMF', M, []);
show_results(M,results.L,results.S,results.O,p,m,n);
%%% Tensor-based algorithms
add_tensor_libs;
T = tensor(V);
% Non-Negative Tensor Factorization
results = process_tensor('NTF', 'bcuNCP', T);
show_3dtensors(T,results.L,results.S,results.O);
% Tensor Decomposition
results = process_tensor('TD', 'Tucker-ALS', T);
show_3dtensors(T,results.L,results.S,results.O);
rem_tensor_libs;
%% DEMO 02
% Robust PCA
process_video('RPCA', 'FPCP', 'dataset/demo.avi', 'output/demo_FPCP.avi');
% Low Rank Recovery
process_video('LRR', 'FastLADMAP', 'dataset/demo.avi', 'output/demo_LRR-FastLADMAP.avi');
% Non-Negative Matrix Factorization
process_video('NMF', 'ManhNMF', 'dataset/demo.avi', 'output/demo_ManhNMF.avi');
% Non-Negative Tensor Factorization
process_video('NTF', 'bcuNCP', 'dataset/demo.avi', 'output/demo_bcuNCP.avi');
% Tensor Decomposition
process_video('TD', 'Tucker-ALS', 'dataset/demo.avi', 'output/demo_Tucker-ALS.avi');
%% DEMO 03 - For Large Videos (block by block)
close all; clear all; clc;
video = load_video_file('dataset/highway.avi');
%% show_video(video);
M_total = [];
L_total = [];
S_total = [];
O_total = [];
M = []; k = 1; k_max = 50;
nframes = 250; % video.nrFramesTotal;
for i = 1 : nframes
%disp(['#frame ' num2str(i)]);
frame = video.frames(i).cdata;
I = reshape(frame,[],1);
M(:,k) = I;
if(k == k_max || i == nframes)
disp(['#last frame ' num2str(i)]);
M = im2double(M);
tic;
results = process_matrix('RPCA', 'IALM', M, []);
%results = process_matrix('RPCA', 'FPCP', M, []);
%results = process_matrix('LRR', 'FastLADMAP', M, []);
%results = process_matrix('NMF', 'NMF-MU', M, []);
toc
M_total = [M_total M];
L_total = [L_total results.L];
S_total = [S_total results.S];
O_total = [O_total results.O];
displog('Displaying results...');
show_results(M,results.L,results.S,results.O,size(M,2),video.height,video.width);
M = []; k = 0;
%break;
end
k = k + 1;
end
disp('Finished');
%%
show_results(M_total,L_total,S_total,O_total,size(M_total,2),video.height,video.width);
%%
convert_video2d_to_avi(S_total,size(S_total,2),video.height,video.width,'output/highway_S.avi');
convert_video2d_to_avi(L_total,size(L_total,2),video.height,video.width,'output/highway_L.avi');
convert_video2d_to_avi(O_total,size(O_total,2),video.height,video.width,'output/highway_O.avi');