|
| 1 | +% This is the testing demo of CDnCNN for denoising noisy color images corrupted by |
| 2 | +% AWGN. |
| 3 | + |
| 4 | +% clear; clc; |
| 5 | +addpath('utilities'); |
| 6 | +folderTest = fullfile('testsets','CBSD68'); %%% test dataset |
| 7 | +folderModel = 'model'; |
| 8 | + |
| 9 | +showResult = 1; |
| 10 | +useGPU = 1; |
| 11 | +pauseTime = 0; |
| 12 | + |
| 13 | +% image noise level |
| 14 | +noiseSigma = 25; |
| 15 | +% model noise level |
| 16 | +modelSigma = 25; % from {5, 10, 15, 25, 35, 50} |
| 17 | +load(fullfile(folderModel,'specifics_color',['color_sigma=',num2str(modelSigma,'%02d'),'.mat'])); |
| 18 | + |
| 19 | +net = vl_simplenn_tidy(net); |
| 20 | + |
| 21 | +% for i = 1:size(net.layers,2) |
| 22 | +% net.layers{i}.precious = 1; |
| 23 | +% end |
| 24 | + |
| 25 | +% move to gpu |
| 26 | +if useGPU |
| 27 | + net = vl_simplenn_move(net, 'gpu') ; |
| 28 | +end |
| 29 | + |
| 30 | +% read images |
| 31 | +ext = {'*.jpg','*.png','*.bmp'}; |
| 32 | +filePaths = []; |
| 33 | +for i = 1 : length(ext) |
| 34 | + filePaths = cat(1,filePaths, dir(fullfile(folderTest,ext{i}))); |
| 35 | +end |
| 36 | + |
| 37 | +%%% PSNR and SSIM |
| 38 | +PSNRs = zeros(1,length(filePaths)); |
| 39 | + |
| 40 | +for i = 1:length(filePaths) |
| 41 | + |
| 42 | + % read current image |
| 43 | + label = imread(fullfile(folderTest,filePaths(i).name)); |
| 44 | + [~,nameCur,extCur] = fileparts(filePaths(i).name); |
| 45 | + label = im2double(label); |
| 46 | + |
| 47 | + % add Gaussian noise |
| 48 | + randn('seed',0); |
| 49 | + input = single(label + noiseSigma/255*randn(size(label))); |
| 50 | + |
| 51 | + % convert to GPU |
| 52 | + if useGPU |
| 53 | + input = gpuArray(input); |
| 54 | + end |
| 55 | + |
| 56 | + res = vl_simplenn(net,input,[],[],'conserveMemory',true,'mode','test'); |
| 57 | + %res = vl_ffdnet_matlab(net, input); %%% use this if you did not install matconvnet. |
| 58 | + output = input - res(end).x; |
| 59 | + |
| 60 | + % convert to CPU |
| 61 | + if useGPU |
| 62 | + output = gather(output); |
| 63 | + input = gather(input); |
| 64 | + end |
| 65 | + |
| 66 | + % calculate PSNR |
| 67 | + [PSNRCur] = Cal_PSNRSSIM(im2uint8(label),im2uint8(output),0,0); |
| 68 | + if showResult |
| 69 | + imshow(cat(2,im2uint8(label),im2uint8(input),im2uint8(output))); |
| 70 | + title([filePaths(i).name,' ',num2str(PSNRCur,'%2.2f'),'dB']) |
| 71 | + drawnow; |
| 72 | + pause(pauseTime) |
| 73 | + end |
| 74 | + PSNRs(i) = PSNRCur; |
| 75 | + |
| 76 | +end |
| 77 | + |
| 78 | +disp(mean(PSNRs)); |
| 79 | + |
| 80 | + |
0 commit comments