-
Notifications
You must be signed in to change notification settings - Fork 11
/
Demo_test_WIN5RB.m
executable file
·91 lines (67 loc) · 2.44 KB
/
Demo_test_WIN5RB.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
clear; clc;
addpath('utilities');
addpath('./matconvnet/matlab/');
run ('./matconvnet/matlab/vl_setupnn.m');
savepath='./';
folderTest = 'testsets/BSD200/';
%folderTest='testsets/Set12/';
folderModel = 'model/WIN5RB/';
noiseSigma = 50; %%% image noise level
load(fullfile(folderModel,['SWRB_N' num2str(noiseSigma) '.mat']));
showResult = 0;
useGPU = 0;
pauseTime = 1;
IsSaveResult=1;
%%% read images
ext = {'*.jpg','*.png','*.bmp'};
filePaths = [];
for i = 1 : length(ext)
filePaths = cat(1,filePaths, dir(fullfile(folderTest,ext{i})));
end
%%% PSNR and SSIM
PSNRs = zeros(1,length(filePaths));
SSIMs = zeros(1,length(filePaths));
Times = zeros(1,length(filePaths));
for i = 1:length(filePaths)
%%% read images
label = imread(fullfile(folderTest,filePaths(i).name));
[H,W,Z]=size(label);
[~,nameCur,extCur] = fileparts(filePaths(i).name);
disp([num2str(i),' ',filePaths(i).name,' ',num2str(noiseSigma)]);
if(size(label,3)>1)
label = rgb2ycbcr(label);
label=label(:, :, 1);
end
label = im2double(label);
[label,isConsis]=Consistency(label);
randn('seed',0);
input = single(label + noiseSigma/255*randn(size(label)));
PSNR_noise = 10*log10(1/mean((label(:)-input(:)).^2));
tic;
output=NIDCN_DWRB(input,model);
timeCur=toc;
if isConsis<1
output=imresize(output,[H W]);
label=imresize(label,[H W]);
end
%%% calculate PSNR and SSIM
[PSNRCur, SSIMCur] = Cal_PSNRSSIM(im2uint8(label),im2uint8(output),0,0);
if showResult
imshow(cat(2,im2uint8(label),im2uint8(input),im2uint8(output)));
title([filePaths(i).name,' ',num2str(PSNRCur,'%2.2f'),' ',num2str(SSIMCur,'%2.4f')])
drawnow;
pause(pauseTime)
else
disp([filePaths(i).name,' ',num2str(PSNRCur,'%2.2f'),'dB',' ',num2str(SSIMCur,'%2.4f'),' ',num2str(timeCur,'%2.2f')]);
end
PSNRs(i) = PSNRCur;
SSIMs(i) = SSIMCur;
Times(i) = timeCur;
if IsSaveResult
%% Save
imwrite(im2uint8(label),fullfile(savepath,[nameCur '_original.bmp']));
imwrite(im2uint8(input),fullfile(savepath,[nameCur '_noisy_N' num2str(noiseSigma) '.bmp']));
imwrite(im2uint8(output),fullfile(savepath,[nameCur '_recover_WIN5RB_N' num2str(noiseSigma) '.bmp']));
end
end
disp([mean(PSNRs),mean(SSIMs),mean(Times)]);