-
Notifications
You must be signed in to change notification settings - Fork 24
/
runDehazing.m
73 lines (61 loc) · 1.39 KB
/
runDehazing.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
close all;clear;clc;
inputImagePath = 'inputImgs/tree2.png';
I = imread(inputImagePath);
r = 15;
beta = 1.0;
%----- Parameters for Guided Image Filtering -----
gimfiltR = 60;
eps = 10^-3;
%-------------------------------------------------
tic;
[dR, dP] = calVSMap(I, r);
refineDR = fastguidedfilter_color(double(I)/255, dP, r, eps, r/4);
%refineDR = imguidedfilter(dR, double(I)/255, 'NeighborhoodSize', [gimfiltR, gimfiltR], 'DegreeOfSmoothing', eps);
tR = exp(-beta*refineDR);
tP = exp(-beta*dP);
imwrite(dR, 'res/originalDepthMap.png');
imwrite(refineDR, 'res/refineDepthMap.png');
figure;
imshow([dP dR refineDR]);
title('depth maps');
figure;
imshow([tP tR]);
title('transmission maps');
imwrite(tR, 'res/transmission.png');
a = estA(I, dR);
t0 = 0.05;
t1 = 1;
I = double(I)/255;
[h w c] = size(I);
J = zeros(h,w,c);
J(:,:,1) = I(:,:,1)-a(1);
J(:,:,2) = I(:,:,2)-a(2);
J(:,:,3) = I(:,:,3)-a(3);
t = tR;
[th tw] = size(t);
for y=1:th
for x=1:tw
if t(y,x)<t0
t(y,x)=t0;
end
end
end
for y=1:th
for x=1:tw
if t(y,x)>t1
t(y,x)=t1;
end
end
end
J(:,:,1) = J(:,:,1)./t;
J(:,:,2) = J(:,:,2)./t;
J(:,:,3) = J(:,:,3)./t;
J(:,:,1) = J(:,:,1)+a(1);
J(:,:,2) = J(:,:,2)+a(2);
J(:,:,3) = J(:,:,3)+a(3);
toc;
figure;
imshow([I J]);
title('hazy image and dehazed image');
saveName = ['res/' num2str(r) '_beta' num2str(beta) '.png'];
imwrite(J, saveName);