-
Notifications
You must be signed in to change notification settings - Fork 3
/
demo_testpsnr.m
87 lines (60 loc) · 2.12 KB
/
demo_testpsnr.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
function [mpsnr, mssim] = demo_testpsnr(iter, img_path, pad, testnum)
caffe.reset_all();
blur_data = dir(fullfile(img_path, '*_batch.png'));
gt_data = dir(fullfile(img_path, '*_gt.png'));
ker_data = dir(fullfile(img_path, '*_kernel.png'));
model_path = 'models/';
solver_file = fullfile(model_path, 'llight_solver_test.prototxt');
save_file = fullfile(model_path, 'llight_ps256_bs1.mat');
Solver = modelconfig_test(solver_file, save_file, iter);
if ~exist('testnum', 'var')
testnum = length(blur_data);
end
% mkdir(strcat('SOTSindoor_results/results', num2str(iter)));
psnrs=0;
ssims=0;
load ('GSVDgaudisk.mat');
pad_size = 55;
for i = 1: length(blur_data)
clear batch
blurimg_in = im2double(imread(fullfile(img_path,blur_data(i).name)));
if pad
blurimg = padarray(blurimg_in,[pad_size, pad_size],'replicate','both');
else
blurimg = blurimg_in;
end
gtimg = im2double(imread(fullfile(img_path, gt_data(i).name)));
kernel = im2double(imread(fullfile(img_path, ker_data(i).name)));
kernel = kernel / sum(kernel(:));
kernelF = psf2otf(kernel, [151,151]);
kernel = otf2psf(kernelF);
IKernelF = conj(kernelF) ./ (conj(kernelF).*kernelF + 1/100);
IKernel = otf2psf(IKernelF);
IKernel = L*L'*IKernel*R*R';
IKernel = IKernel / sum(IKernel(:)); %% estimated shrinked inverse kernel
M = L'*IKernel*R;
weights = Solver.Solver_.net.get_weights();
for k = 1:50
for j = 1:50
weights(2).weights{1,1}(1,1,k,j) = M(k, j);
end
end
Solver.Solver_.net.set_weights(weights);
[row, col, cha] = size(blurimg);
for cha = 1:3
batchc = {single(blurimg(:,:,cha))};
Solver.Solver_.net.blobs('data').reshape([row, col, 1, 1]);
tic
activec = Solver.Solver_.net.forward(batchc);
toc
num_output = length(activec);
active= activec{num_output};
output (:,:,cha) = active;
end
[psnr, ssim] = V5_showresults(output, gtimg);
psnrs = psnrs + psnr;
ssims = ssims + ssim;
clear output
end
mpsnr = psnrs/testnum;
mssim = ssims/testnum;