-
Notifications
You must be signed in to change notification settings - Fork 7
/
test_total_variation.m
86 lines (68 loc) · 2.22 KB
/
test_total_variation.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
image_size = 100;
P = phantom('Modified Shepp-Logan',image_size);
y = single(im2uint8(P));
%%%%%%%%%%%%%%%%%%%%%%%%%%%total_variation%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
lambda = 0.06;
rho = lambda/4;
alpha = 1;
[z1, history] = total_variation(y, lambda, rho, alpha);
% reporting
K = length(history.objval);
h = figure;
subplot(3,1,1);
plot(1:K, history.objval, 'k', 'MarkerSize', 10, 'LineWidth', 2);
ylabel('f(x^k) + g(z^k)'); xlabel('iter (k)');
subplot(3,1,2);
semilogy(1:K, max(1e-8, history.r_norm), 'k', ...
1:K, history.eps_pri, 'k--', 'LineWidth', 2);
ylabel('||r||_2');
subplot(3,1,3);
semilogy(1:K, max(1e-8, history.s_norm), 'k', ...
1:K, history.eps_dual, 'k--', 'LineWidth', 2);
ylabel('||s||_2'); xlabel('iter (k)')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%total_variation_cross_links%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
lambda = 0.16;
rho = lambda/4;
alpha = 1;
[z2, history] = total_variation_cross_links(y, lambda, rho, alpha);
% reporting
K = length(history.objval);
h = figure;
subplot(3,1,1);
plot(1:K, history.objval, 'k', 'MarkerSize', 10, 'LineWidth', 2);
ylabel('f(x^k) + g(z^k)'); xlabel('iter (k)');
subplot(3,1,2);
semilogy(1:K, max(1e-8, history.r_norm), 'k', ...
1:K, history.eps_pri, 'k--', 'LineWidth', 2);
ylabel('||r||_2');
subplot(3,1,3);
semilogy(1:K, max(1e-8, history.s_norm), 'k', ...
1:K, history.eps_dual, 'k--', 'LineWidth', 2);
ylabel('||s||_2'); xlabel('iter (k)')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%total_variation_4block%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
lambda = 0.0139;
rho = lambda/4;
alpha = 1;
[z3, history] = total_variation_4block(y, lambda, rho, alpha);
% reporting
K = length(history.objval);
h = figure;
subplot(3,1,1);
plot(1:K, history.objval, 'k', 'MarkerSize', 10, 'LineWidth', 2);
ylabel('f(x^k) + g(z^k)'); xlabel('iter (k)');
subplot(3,1,2);
semilogy(1:K, max(1e-8, history.r_norm), 'k', ...
1:K, history.eps_pri, 'k--', 'LineWidth', 2);
ylabel('||r||_2');
subplot(3,1,3);
semilogy(1:K, max(1e-8, history.s_norm), 'k', ...
1:K, history.eps_dual, 'k--', 'LineWidth', 2);
ylabel('||s||_2'); xlabel('iter (k)')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure;
subplot(1,3,1);
imshow(abs(z1)>1,[])
subplot(1,3,2);
imshow(abs(z2)>1,[])
subplot(1,3,3);
imshow(abs(z3)>1,[])