-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGet_Dx.m
46 lines (42 loc) · 877 Bytes
/
Get_Dx.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
%% a tool
% I, input image
% step, 1 - D is the minimal map of each channel.
% 2 - D is eroded.
% 3 - D is dark channel.
% r, mask radius
function [ D ] = Get_Dx( I, step, r )
%% prepare
[m,n,c] = size(I);
if nargin <= 2
r = ceil(0.05*min(m,n));
end
if nargin <= 1
step = 3;
end
%% step 1. channel min only
if c == 1
B = I;
else
B = min(I(:,:,1),I(:,:,2));
B = min(I(:,:,3),B);
end
if step <= 1
D = B;
return;
end
%% step 2. erode
se=strel('disk',r);
D=imerode(B,se);
if step <= 2
return;
end
%% step 3. refine
L = get_laplacian(I);
U = speye(size(L));
lambda = 0.0001;
A = L + lambda * U;
b = lambda * D(:);
D_refine = A \ b;
D_refine = reshape(D_refine, m, n);
D = D_refine;
end