-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathDemo_MCWNNM_ADMM1_NL_RealGT.m
91 lines (84 loc) · 4.28 KB
/
Demo_MCWNNM_ADMM1_NL_RealGT.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
%-------------------------------------------------------------------------------------------------------------
% This is an implementation of the MCWNNM algorithm for real color image denoising.
% Author: Jun Xu, csjunxu@comp.polyu.edu.hk
% The Hong Kong Polytechnic University
%
% Please refer to the following paper if you use this code:
%
% @article{MCWNNM,
% author = {Jun Xu and Lei Zhang and David Zhang and Xiangchu Feng},
% title = {Multi-channel Weighted Nuclear Norm Minimization for Real Color Image Denoising},
% journal = {ICCV},
% year = {2017}
% }
%
% Please see the file License.txt for the license governing this code.
%-------------------------------------------------------------------------------------------------------------
clear;
GT_Original_image_dir = 'Real_ccnoise_denoised_part/';
GT_fpath = fullfile(GT_Original_image_dir, '*mean.png');
TT_Original_image_dir = 'Real_ccnoise_denoised_part/';
TT_fpath = fullfile(TT_Original_image_dir, '*real.png');
GT_im_dir = dir(GT_fpath);
TT_im_dir = dir(TT_fpath);
im_num = length(TT_im_dir);
Par.win = 20; % Non-local patch searching window
Par.delta = 0; % Parameter between each iter
Par.Constant = 2 * sqrt(2); % Constant num for the weight vector
Par.Innerloop = 2; % InnerLoop Num of between re-blockmatching
Par.ps = 6; % Patch size
Par.step = 5;
Par.Iter = 2; % total iter numbers
Par.display = true;
% Par.method = 'WNNM_ADMM';
Par.method = 'MCWNNM_ADMM';
Par.model = '2';
Par.maxIter = 10;
for mu = [1]
Par.mu = mu;
for rho = [6]
Par.rho = rho;
for lambda = [4]
Par.lambda = lambda;
% record all the results in each iteration
Par.PSNR = zeros(Par.Iter, im_num, 'single');
Par.SSIM = zeros(Par.Iter, im_num, 'single');
for i = 1:im_num
Par.image = i;
Par.nlsp = 70; % Initial Non-local Patch number
Par.I = double( imread(fullfile(GT_Original_image_dir, GT_im_dir(i).name)) );
S = regexp(GT_im_dir(i).name, '\.', 'split');
fprintf('%s :\n', GT_im_dir(i).name);
[h, w, ch] = size(Par.I);
Par.nim = double( imread(fullfile(TT_Original_image_dir, TT_im_dir(i).name)) );
for c = 1:ch
Par.nSig0(c,1) = NoiseEstimation(Par.nim(:, :, c), Par.ps);
end
fprintf('The noise levels are %2.2f, %2.2f, %2.2f. \n', Par.nSig0(1), Par.nSig0(2), Par.nSig0(3) );
PSNR = csnr( Par.nim, Par.I, 0, 0 );
SSIM = cal_ssim( Par.nim, Par.I, 0, 0 );
fprintf('The initial value of PSNR = %2.4f, SSIM = %2.4f \n', PSNR,SSIM);
time0 = clock;
[im_out, Par] = MCWNNM_ADMM1_NL_Denoising( Par.nim, Par.I, Par ); % WNNM denoisng function
fprintf('Total elapsed time = %f s\n', (etime(clock,time0)) );
im_out(im_out>255) = 255;
im_out(im_out<0) = 0;
% calculate the PSNR
Par.PSNR(Par.Iter, Par.image) = csnr( im_out, Par.I, 0, 0 );
Par.SSIM(Par.Iter, Par.image) = cal_ssim( im_out, Par.I, 0, 0 );
% imname = sprintf(['../../cc_Results/' Par.method '_NL_CC15_' Par.model '_Oite' num2str(Par.Iter) '_Iite' num2str(Par.maxIter) '_rho' num2str(rho) '_mu' num2str(Par.mu) '_lambda' num2str(lambda) '_' TT_im_dir(i).name]);
% imwrite(im_out/255, imname);
fprintf('%s : PSNR = %2.4f, SSIM = %2.4f \n',TT_im_dir(i).name, Par.PSNR(Par.Iter, Par.image),Par.SSIM(Par.Iter, Par.image) );
end
mPSNR = mean(Par.PSNR,2);
[~, idx] = max(mPSNR);
PSNR = Par.PSNR(idx,:);
SSIM = Par.SSIM(idx,:);
mSSIM=mean(SSIM,2);
fprintf('The best PSNR result is at %d iteration. \n',idx);
fprintf('The average PSNR = %2.4f, SSIM = %2.4f. \n', mPSNR(idx),mSSIM);
name = sprintf(['../../' Par.method '_NL_CC' num2str(im_num) '_' Par.model '_Oite' num2str(Par.Iter) '_Iite' num2str(Par.maxIter) '_rho' num2str(rho) '_mu' num2str(Par.mu) '_lambda' num2str(lambda) '.mat']);
save(name,'PSNR','SSIM','mPSNR','mSSIM');
end
end
end