forked from sidney001/image_pairs_deblur
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deconvglucy.m
72 lines (58 loc) · 1.55 KB
/
deconvglucy.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
function [ dI ] = deconvglucy( Nd, dB, K, niter, alpha, verbose )
%DECONVGCLUCY Gain-controlled Richardson-Lucy algorithm
%
% Nd - denoised image
% dB - deltaB = B - Nd conv K (+ offset)
% K - kernel
% niter - # of iterations
% alpha - weight of the gain map
% verbose - display more information if true
%
if nargin < 4
% default = 0.2 in the paper
alpha = 0.2;
end
if nargin < 5
verbose = true;
end
if alpha > 0
if verbose
disp('Calculating Igain map...');
end
% calculate gain map according to Nd and param alpha
Igain = compute_Igain_map(Nd, alpha);
figure;imshow(Igain,[ ]);title('gain map');
imwrite(Igain,'gain_map.png')
if verbose
disp('Igain map ready.');
end
else
[ h, w, ~ ] = size(Nd);
Igain = ones([ h w ], 'double');
end
dI = zeros(size(dB), 'double');
dnom = zeros(size(dB), 'double');
Khat = rot90(K, 2); % = flipud(fliplr(K));
[~, ~, d] = size(dB);
if verbose
disp('Start iterating...');
end
for i = 1:niter
dI = dI + 1;
dI = max(dI, 0);%将小于0的值赋值为0
% calculate the denominator in the equation
for j = 1:d
dnom(:,:,j) = fftconv2(dI(:,:,j), K);
% dnom(:,:,j) = conv2(dI(:,:,j), K, 'same');
end
tmp = dB./dnom;
for j = 1:d
% dI(:,:,j) = conv2(tmp(:,:,j), Khat, 'same') .* dI(:,:,j) - 1;
dI(:,:,j) = fftconv2(tmp(:,:,j), Khat) .* dI(:,:,j) - 1;%%%为啥旋转90°???
if i ~= niter
dI(:,:,j) = Igain .* dI(:,:,j);
end
end
dI = min(dI, 1);
end
end