-
Notifications
You must be signed in to change notification settings - Fork 9
/
main_Image_Mondrian.m
215 lines (187 loc) · 6.16 KB
/
main_Image_Mondrian.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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
clear ; clc ;
addpath(genpath('SBL_Tipping2001\'))
addpath(genpath('SparseLab2.1-Core'))
addpath('tools\')
rand_state = rng(0,'v5normal') ;
% load image data
I0 = imread('Dataset\Mondrian.tif');
I0 = double(I0);
% experimental setting
num_method = 5 ; nums = 10 ;
% filename = 'ResultsData\Image_Reconstruction\MondrianRes5_5.mat' ;
% Set finest, coarsest scales
j1 = 7;
j0 = 3;
c = 0.65 ;
qmf = MakeONFilter('Symmlet',8);
diary(['Image_Mondrian_',num2str(c),'.txt'])
diary on
% parameters
paras.a0 = 1e-6 ; paras.b0 = 1e-6 ;
paras.c0 = 1+1e-6; paras.d0 = 1e-6 ;
paras.e0 = 1e-2 ;
paras.iters = 5000 ; paras.threshold = 1e-3;
paras.delta = 1e-4 ; % for stopping criterion
paras.normalized = 1 ;
epsilon = 1e-4 ;
tau0 = 1e-2 ;
threshold = paras.threshold ;
% Do Hybrid-CS scheme:
% Sample 4^j0 resume coefficients (coarse-scale
% coeffs) at scale 2^(-j0) x 2^(-j0)
alpha0 = FWT2_PO(I0, j0, qmf) ;
alpha_BCS0 = zeros(size(alpha0));
alpha_BCS0(1:2^j0,1:2^j0) = alpha0(1:2^j0,1:2^j0);
alpha_LIN = zeros(size(alpha0));
alpha_LIN(1:2^j1,1:2^j1) = alpha0(1:2^j1,1:2^j1);
I_LIN = IWT2_PO(alpha_LIN, j0, qmf);
err_linear = norm(I0 - I_LIN,'fro') / norm(I0,'fro');
% Construct the vector theta of detail wavelet
% coeffs on scales j0 <= j < j1
theta1 = alpha0((2^j0+1):2^j1,1:2^j0);
theta2 = alpha0(1:2^j1,(2^j0+1):2^j1);
n1 = numel(theta1);
n2 = numel(theta2);
theta = [theta1(:); theta2(:)];
N = 4^j1 - 4^j0;
m = floor(c*N);
M = m + 4^j0 ;
% storage the results
time_SBL = zeros(nums, num_method);
errs = zeros(nums, num_method+1);
Iterations = zeros(nums,2);
Nzeros_num = zeros(nums,num_method+1) ;
Irecon = cell(nums, num_method+1);
Irecon{1,num_method+1} = I_LIN ;
errs(:,end) = err_linear ;
theta_all = cell(nums,1);
theta_hat = zeros(length(theta),num_method);
% main loop
for kk = 1:nums
fprintf('The %d th experiment:\n',kk) ;
% generate matrix Phi
Phi = MatrixEnsemble(m, N, 'USE');
% generate the vector S (random measurments of detail coeffs)
y_noise = Phi * theta;
if paras.normalized==0
a = max(eig(Phi'*Phi)) + epsilon;
InitVal.beta_init = Phi'*y_noise;
InitVal.lambda_init= var(y_noise)/100 ;
else
a = max(eig(normc(Phi)'*normc(Phi))) + epsilon ;
InitVal.beta_init = normc(Phi)'*y_noise ;
y_n = y_noise/max(abs(y_noise)) ;
InitVal.lambda_init= var(y_n)/100 ;
end
paras.a = a;
InitVal.gamma_init = 1/m^2 ;
% method 1
ii = 1; % index of method
tic
[temp,Iterations(kk,1)] = Ga_FSBL(y_noise, Phi, paras, InitVal) ;
time_SBL(kk,ii) = toc ;
alpha_BCS = alpha_BCS0;
alpha_BCS((2^j0+1):2^j1,1:2^j0) = reshape(temp(1:n1), 2^j1-2^j0, 2^j0);
alpha_BCS(1:2^j1,(2^j0+1):2^j1) = reshape(temp(n1+1:n1+n2), 2^j1, 2^j1-2^j0);
% Reconstruct
I_BCS = IWT2_PO(alpha_BCS, j0, qmf);
% compute error
errs(kk,ii) = norm(I0 - I_BCS,'fro') / norm(I0,'fro');
Nzeros_num(kk,ii) = length(nonzeros(temp));
theta_hat(:,ii) = temp;
Irecon{kk,ii} = I_BCS ;
% method 2
ii = ii+1 ;
tic
[temp,Iterations(kk,2)] = La_FSBL(y_noise, Phi, paras, InitVal) ;
time_SBL(kk,ii) = toc;
alpha_BCS = alpha_BCS0;
alpha_BCS((2^j0+1):2^j1,1:2^j0) = reshape(temp(1:n1), 2^j1-2^j0, 2^j0);
alpha_BCS(1:2^j1,(2^j0+1):2^j1) = reshape(temp(n1+1:n1+n2), 2^j1, 2^j1-2^j0);
% Reconstruct
I_BCS = IWT2_PO(alpha_BCS, j0, qmf);
% compute error
errs(kk,ii) = norm(I0 - I_BCS,'fro') / norm(I0,'fro');
Nzeros_num(kk,ii) = length(nonzeros(temp));
theta_hat(:,ii) = temp;
Irecon{kk,ii} = I_BCS ;
% method 3
ii = ii+1 ;
sigma2 = var(y_noise)/1e2 ;
delta_La = 1e-8 ;
tic
[weights,used_ids] = FastLaplace(Phi,y_noise, sigma2, delta_La);
time_SBL(kk,ii) = toc;
temp = zeros(N,1);
temp(used_ids) = weights ;
temp(abs(temp)./norm(temp)<threshold) = 0 ;
alpha_BCS = alpha_BCS0;
alpha_BCS((2^j0+1):2^j1,1:2^j0) = reshape(temp(1:n1), 2^j1-2^j0, 2^j0);
alpha_BCS(1:2^j1,(2^j0+1):2^j1) = reshape(temp(n1+1:n1+n2), 2^j1, 2^j1-2^j0);
% Reconstruct
I_BCS = IWT2_PO(alpha_BCS, j0, qmf);
% compute error
errs(kk,ii) = norm(I0 - I_BCS,'fro') / norm(I0,'fro');
Nzeros_num(kk,ii) = length(nonzeros(temp));
theta_hat(:,ii) = temp;
Irecon{kk,ii} = I_BCS ;
% method 4
ii = ii+1 ;
ii = 4;
sigma4 = var(y_noise)/1e3 ;
tic
temp = GGAMP_SBL(y_noise, Phi, paras,sigma4,1) ;
time_SBL(kk,ii) = toc ;
alpha_BCS = alpha_BCS0;
alpha_BCS((2^j0+1):2^j1,1:2^j0) = reshape(temp(1:n1), 2^j1-2^j0, 2^j0);
alpha_BCS(1:2^j1,(2^j0+1):2^j1) = reshape(temp(n1+1:n1+n2), 2^j1, 2^j1-2^j0);
% Reconstruct
I_BCS = IWT2_PO(alpha_BCS, j0, qmf);
% compute error
errs(kk,ii) = norm(I0 - I_BCS,'fro') / norm(I0,'fro');
Nzeros_num(kk,ii) = length(nonzeros(temp));
theta_hat(:,ii) = temp;
Irecon{kk,ii} = I_BCS ;
% method 5
ii = ii + 1;
tic
[weights2,ids_tipping] = SB1_Estimate(Phi,y_noise,InitVal.gamma_init,...
InitVal.lambda_init,paras.iters,0,paras.delta) ;
time_SBL(kk,ii) = toc;
temp = zeros(N,1);
temp(ids_tipping) = weights2 ;
temp(abs(temp)./norm(temp)<threshold)=0 ;
alpha_BCS = alpha_BCS0;
alpha_BCS((2^j0+1):2^j1,1:2^j0) = reshape(temp(1:n1), 2^j1-2^j0, 2^j0);
alpha_BCS(1:2^j1,(2^j0+1):2^j1) = reshape(temp(n1+1:n1+n2), 2^j1, 2^j1-2^j0);
% Reconstruct
I_BCS = IWT2_PO(alpha_BCS, j0, qmf);
% compute error
errs(kk,ii) = norm(I0 - I_BCS,'fro') / norm(I0,'fro');
Nzeros_num(kk,ii) = length(nonzeros(temp));
theta_hat(:,ii) = temp;
Irecon{kk,ii} = I_BCS ;
theta_all{kk,1} = theta_hat;
% linear reconstruction
Nzeros_num(kk,end) = length(nonzeros(theta));
Irecon{kk,end} = I_LIN ;
% save results
clear Phi
% save(filename,'-v7.3')
end
%
disp(errs)
disp(Nzeros_num)
disp(time_SBL)
beep;
disp('Done!') ;
%% plot figures and save data
figure()
nn=4 ;
subplot(2,3,1); AutoImage(Irecon{nn,end});
title(['(a) Linear, m=' num2str(4^j1)]);
tihao = {'(b) GFSBL','(c) LFSBL','(d) LPBCS','(e) GGAMP-SBL','(f) RVM-SBL' } ;
for i=1:num_method
subplot(2,3,i+1); AutoImage(Irecon{nn,i});
title([tihao{i},', m=' num2str(M)]);
end