forked from canyilu/LibADMM-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_tensor_completion.m
97 lines (73 loc) · 1.53 KB
/
test_tensor_completion.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
addpath(genpath(cd))
clear
pic_name = [ './image/testimg.jpg'];
I = double(imread(pic_name));
X = I/255;
[n1,n2,n3] = size(X);
opts.mu = 1e-3;
opts.tol = 1e-6;
opts.rho = 1.2;
opts.max_iter = 500;
opts.DEBUG = 1;
p = 0.6;
maxP = max(abs(X(:)));
omega = find(rand(n1*n2*n3,1)<p);
M = zeros(n1,n2,n3);
M(omega) = X(omega);
%% %% test lrtc_snn and lrtc_tnn
alpha = [1, 1, 1e-3];
alpha = alpha / sum(alpha);
[Xhat,err,iter] = lrtc_snn(M,omega,alpha,opts);
% [Xhat,err,iter] = lrtc_tnn(M,omega,opts);
err
iter
Xhat = max(Xhat,0);
Xhat = min(Xhat,maxP);
RSE = norm(X(:)-Xhat(:))/norm(X(:))
psnr = PSNR(X,Xhat,maxP)
figure(1)
subplot(1,3,1)
imshow(X/maxP)
subplot(1,3,2)
imshow(M/maxP)
subplot(1,3,3)
imshow(Xhat/maxP)
pause
%% test lrtcR_snn
E = randn(n1,n2,n3)/100;
M = M+E;
alpha = [1, 1, 0.001]*10;
% alpha = alpha / sum(alpha);
[Xhat,err,iter] = lrtcR_snn(M,omega,alpha,opts);
err
iter
Xhat = max(Xhat,0);
Xhat = min(Xhat,maxP);
RSE = norm(X(:)-Xhat(:))/norm(X(:))
psnr = PSNR(X,Xhat,maxP)
figure(1)
subplot(1,3,1)
imshow(X/maxP)
subplot(1,3,2)
imshow(M/maxP)
subplot(1,3,3)
imshow(Xhat/maxP)
pause
%% test lrtcR_tnn
E = randn(n1,n2,n3)/100;
M = M+E;
lambda = 0.1;
[Xhat,E,obj,err,iter] = lrtcR_tnn(M,omega,lambda,opts);
err
iter
Xhat = max(Xhat,0);
Xhat = min(Xhat,maxP);
RSE = norm(X(:)-Xhat(:))/norm(X(:))
psnr = PSNR(X,Xhat,maxP)
figure(1)
subplot(1,3,1)
imshow(X/maxP)
subplot(1,3,2)
imshow(M/maxP)
subplot(1,3,3)
imshow(Xhat/maxP)