-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdarkChannel.m
executable file
·47 lines (40 loc) · 1.03 KB
/
darkChannel.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
function win_dark = getT(input,path_d,path_t,path_gt,path_res)
figure('visible','off');
patch_size = 15;
r = 60;
A = 0.75;
eps = 10^-3;
img = imread(input);
[h,w,c] = size(img);
I = double(img) / 255;
w1 = 0.8;
patch_size =patch ;img_size = w * h;
win_dark = zeros(h,w);
for i=1:h
for j=1:w
win_dark(i,j)=min(I(i,j,:));
end
end
% dark channel
win_dark = ordfilt2(win_dark,1,ones(15,15),'symmetric');
imwrite(win_dark,path_d);
% rough transmission
t0 = 0.1;
transmission = 1 - 0.85 * win_dark/A;
t = max(t0,transmission);
imwrite(t,path_t);
% guided filter
I1 = double(rgb2gray(img))/255;
gt = guidedfilter(I1 ,t, r, eps);
imwrite(gt,path_gt);
% result
res = zeros(h,w,c);
for i=1:c
for j=1:h
for l=1:w
res(j,l,i)=(I(j,l,i)-A)/gt(j,l)+A;
end
end
end
imwrite(res,path_res);
exit