-
Notifications
You must be signed in to change notification settings - Fork 57
/
run_cnn.m
53 lines (43 loc) · 1.29 KB
/
run_cnn.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
function [ dehaze ] = run_cnn( im )
%RUN_CNN Summary of this function goes here
% Detailed explanation goes here
r0 = 50;
eps = 10^-3;
gray_I = rgb2gray(im);
load dehaze
haze=im-0.5;
%% Feature Extraction F1
f1=convolution(haze, weights_conv1, biases_conv1);
F1=[];
f1temp=reshape(f1,size(f1,1)*size(f1,2),size(f1,3));
for step=1:4
maxtemp=max(f1temp(:,(step*4-3):step*4),[],2);
F1=[F1,maxtemp]; %#ok<AGROW>
end
F1=reshape(F1,size(f1,1),size(f1,2),size(F1,2));
%% Multi-scale Mapping F2
F2=zeros(size(F1,1),size(F1,2),48);
F2(:,:,1:16)=convolution(F1, weights_conv3x3, biases_conv3x3);
F2(:,:,17:32)=convolution(F1, weights_conv5x5, biases_conv5x5);
F2(:,:,33:48)=convolution(F1, weights_conv7x7, biases_conv7x7);
%% Local Extremum F3
F3=convMax(single(F2), 3);
%% Non-linear Regression F4
F4=min(max(convolution(F3, weights_ip, biases_ip),0),1);
%% Atmospheric light
sortdata = sort(F4(:), 'ascend');
idx = round(0.01 * length(sortdata));
val = sortdata(idx);
id_set = find(F4 <= val);
BrightPxls = gray_I(id_set);
iBright = BrightPxls >= max(BrightPxls);
id = id_set(iBright);
Itemp=reshape(im,size(im,1)*size(im,2),size(im,3));
A = mean(Itemp(id, :),1);
A=reshape(A,1,1,3);
F4 = guidedfilter(gray_I, F4, r0, eps);
J=bsxfun(@minus,im,A);
J=bsxfun(@rdivide,J,F4);
J=bsxfun(@plus,J,A);
dehaze=J;
end