-
Notifications
You must be signed in to change notification settings - Fork 537
/
Demo_test_CDnCNN_Specific.m
80 lines (61 loc) · 1.98 KB
/
Demo_test_CDnCNN_Specific.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
% This is the testing demo of CDnCNN for denoising noisy color images corrupted by
% AWGN.
% clear; clc;
addpath('utilities');
folderTest = fullfile('testsets','CBSD68'); %%% test dataset
folderModel = 'model';
showResult = 1;
useGPU = 1;
pauseTime = 0;
% image noise level
noiseSigma = 25;
% model noise level
modelSigma = 25; % from {5, 10, 15, 25, 35, 50}
load(fullfile(folderModel,'specifics_color',['color_sigma=',num2str(modelSigma,'%02d'),'.mat']));
net = vl_simplenn_tidy(net);
% for i = 1:size(net.layers,2)
% net.layers{i}.precious = 1;
% end
% move to gpu
if useGPU
net = vl_simplenn_move(net, 'gpu') ;
end
% 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));
for i = 1:length(filePaths)
% read current image
label = imread(fullfile(folderTest,filePaths(i).name));
[~,nameCur,extCur] = fileparts(filePaths(i).name);
label = im2double(label);
% add Gaussian noise
randn('seed',0);
input = single(label + noiseSigma/255*randn(size(label)));
% convert to GPU
if useGPU
input = gpuArray(input);
end
res = vl_simplenn(net,input,[],[],'conserveMemory',true,'mode','test');
%res = vl_ffdnet_matlab(net, input); %%% use this if you did not install matconvnet.
output = input - res(end).x;
% convert to CPU
if useGPU
output = gather(output);
input = gather(input);
end
% calculate PSNR
[PSNRCur] = 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'),'dB'])
drawnow;
pause(pauseTime)
end
PSNRs(i) = PSNRCur;
end
disp(mean(PSNRs));