-
Notifications
You must be signed in to change notification settings - Fork 0
/
Nesterov_Denoising.m
171 lines (98 loc) · 4.85 KB
/
Nesterov_Denoising.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
%% This program is used for image denoising
% using total variation (TV) and Nesterov's first order method
%-------------Description------------------
% min ||x||_TV s.t. ||x-b||_l2 < delta
% b= original noisy image
% x= reconstructed denoised image
% delta = threshold error
% Ref: Dahl et al.,"Algorithms and software for
% total variation image reconstruction via first-order
%methods" Numer. Algor.,53: 67-92 (2010)
%-------------------------------------------
% Author: Sovan Mukherjee, April, 2015
clear all;close all; clc;
%% Shepp-Logan
N=1024; %Pixel size of the image
Im_original= phantom(N); %original Shepp-Logan Phantom
% Add some gaussian noise to the image
sigma= 0.10; %standard deviation of the noise
b = Im_original+sigma*randn(size(Im_original,1)); % noisy image
figure;
imshow(Im_original);
title('Original Image');
figure;
imshow(b); % show the noisy image
title('Noisy Image');
%% ------------------------------------------------------------------------
%% -- implement Nesterov's first order method -----------------------------
x= b; % initialize denoised image as the original noisy image
% set up the parameters
m= size(Im_original,1); % no. of image pixels in x-direction
n= size(Im_original,2); % no. of image pixels in y-direction
x= reshape(x, m*n,1); % tranform the image matrix into a vector
b= reshape(b, m*n,1);
e_rel =5e-4; % relative epsilon
% epsilon= norm(b, Inf)*m*n*e_rel; % thresold parameter for stopping the iteration
epsilon= max(b(:))*m*n*e_rel; % thresold parameter for stopping the iteration
mu= epsilon/(m*n); % smoothing parameter
tao=0.99;
delta= tao*sqrt(m*n)*sigma; % threshold relative error between noisy and denoised image
% find the gradient operator
[D1,D2]= grad_operator_new(size(Im_original,1)); % calculating gradient operator
D= [D1;D2]; % gradient operator
L_mu= 8/mu; % Lipschitz constant of the gradient
% Nesterov's algorithm starts here
max_iter=300; % maximum number of iteration
wk= zeros(m*n,1);
tic;
for k =0:max_iter-1
fprintf('iteration # %d\t',k);
alphak= 0.5*(k+1);
Dhx= D1*x;
Dvx= D2*x;
D_x= [Dhx;Dvx]; % gradient of x
% compute gk (step 1)
w=max(mu,sqrt(abs(Dhx).^2+abs(Dvx).^2));
u1=Dhx./w;
u2=Dvx./w;
uk=[u1;u2];
gk= D'*uk;
% compute yk (step 2)
yk1= L_mu*(x-b)-gk;
% yk1= -L_mu*(x-b)+gk;
yk2= max(L_mu,norm(yk1,2)/delta);
yk = yk1/yk2+b;
% compute zk (step 3)
wk= wk+alphak*gk;
zk1= -wk;
zk2= max(L_mu, norm(wk,2)/delta);
zk= zk1/zk2+b;
% update xk (step 4)
x= (2/(k+3))*zk+((k+1)/(k+3))*yk;
%stopping criterion
D_x_norm= sum(sqrt(abs(Dhx).^2+abs(Dvx).^2));
% D_x_sum= sum(D*x);
stop_parameter= D_x_norm+delta*norm(gk,2)-uk'*D*b; %stopping parameter
if stop_parameter<epsilon
break;
end
fprintf('Relative error= %f\n',stop_parameter);
end
t.tv=toc;
fprintf('\nReconstruction time (s)= %f\n',t.tv);
%% ----- Nesterov's algorithm ends here -----------------------------------
%% show the denoised reconstructed image
x= reshape(x, size(Im_original,1),size(Im_original,2));
b= reshape(b, size(Im_original,1),size(Im_original,2));
figure;
imshow(x); % show the denoised image
title('denoised image');
%% Calculate peak signal-to-noise ratio (PSNR)
[m_0,n_0]= size(Im_original);
% PSNR for noisy image
mse_n= (1/(m_0*n_0))*sum(sum((Im_original-b).^2));
max= max(Im_original(:));
PSNR_dB_noised= 10*log10(max^2/mse_n);
% PSNR for denoised image
mse= (1/(m_0*n_0))*sum(sum((Im_original-x).^2));
PSNR_dB_denoised= 10*log10(max^2/mse);