-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateLatentImage.m
130 lines (84 loc) · 2.73 KB
/
updateLatentImage.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
function [L] = updateLatentImage(B, L, K, lambda, max_iter)
[M N] = size(B);
epsilon = 0;%7./255;
SIGMA = 10;%/10;%10%0.3536;%
TAU = 1/sqrt(8)^2/SIGMA;
[B_dx, B_dy] = extract_gradient(B);
% max_B_dx = max(abs(B_dx(:)));
% max_B_dy = max(abs(B_dy(:)));
% thr = 0.05;
% % thr = 0.1;
% B_dx(abs(B_dx) < thr*max_B_dx) = 0;
% B_dy(abs(B_dy) < thr*max_B_dy) = 0;
K_t = K';
tmp_Kt_B = K_t*reshape(B', [M*N 1]);
tmp_Kt_Bdx = K_t*reshape(B_dx', [M*N 1]);
tmp_Kt_Bdy = K_t*reshape(B_dy', [M*N 1]);
b_I = ( reshape(tmp_Kt_B, [N M])' );
b_dx = nablax_t_A( reshape(tmp_Kt_Bdx, [N M])' );
b_dy = nablay_t_A( reshape(tmp_Kt_Bdy, [N M])' );
% end
L_ = L;
dual_p_x = zeros(M, N);
dual_p_y = zeros(M, N);
% w_I = 0.05;%0.01;
w_I = 0.25;
for(iter = 1 : max_iter)
% iter
u_x = dxp(L_);
u_y = dyp(L_);
dual_p_x = (dual_p_x + SIGMA*u_x);%/(1+SIGMA*epsilon);
dual_p_y = (dual_p_y + SIGMA*u_y);%/(1+SIGMA*epsilon);
if 1
reprojection = max(1, sqrt(dual_p_x.^2 + dual_p_y.^2));
dual_p_x = dual_p_x./reprojection;
dual_p_y = dual_p_y./reprojection;
end
div_u = dxm(dual_p_x) + dym(dual_p_y);
L_ = L;
L = L + TAU * div_u;
[L_dx, L_dy] = extract_gradient(L);
b = L/(2*TAU*lambda) + b_dx + b_dy + w_I*b_I;
tmp_dx = K* reshape(L_dx', [N*M 1]);
tmp_dx = reshape(K_t*tmp_dx, [N M])';
tmp_dy = K* reshape(L_dy', [N*M 1]);
tmp_dy = reshape(K_t*tmp_dy, [N M])';
tmp = K* reshape(L', [N*M 1]);
tmp = reshape(K_t*tmp, [N M])';
AL = nablax_t_A(tmp_dx) + nablay_t_A( tmp_dy ) + w_I*tmp;
AL = (1/(2*TAU*lambda))*L + AL;
r = (b - AL);
p = r;
r_sqr = sum(sum(r.*r));
for(iter_inner = 1 : 5)
[p_dx p_dy] = extract_gradient(p);
tmp_dx = K* reshape(p_dx', [N*M 1]);
tmp_dx = reshape(K_t*tmp_dx, [N M])';
tmp_dy = K* reshape(p_dy', [N*M 1]);
tmp_dy = reshape(K_t*tmp_dy, [N M])';
tmp = K* reshape(p', [N*M 1]);
tmp = reshape(K_t*tmp, [N M])';
Ap = nablax_t_A(tmp_dx) + nablay_t_A( tmp_dy ) + w_I*tmp;
Ap = (1/(2*TAU*lambda))*p + Ap;
alpha = r_sqr/sum(sum(p.*Ap));
r = r - alpha*Ap;
tmp = sum(sum(r.*r));
beta = 1/(r_sqr);
r_sqr = tmp;
L = L + alpha*p;
beta = beta*r_sqr;
p = r + beta*p;
end
L(L > 1) = 1;
L(L < 0) = 0;
L_ = 2*L - L_;
% L_(L_ > 1) = 1;
% L_(L_ < 0) = 0;
end
L = imsharpen(L);
L = min(1, max(0, L));
imshow(L_);
tmp_title = sprintf('iter=%d', iter);
title(tmp_title);
drawnow;
end