Skip to content

Commit 9a89b6a

Browse files
felipecodefelipecode
felipecode
authored and
felipecode
committed
Added new files for turbidity estimation. ( The ones that actually work)
1 parent 8feff4c commit 9a89b6a

File tree

5 files changed

+280
-0
lines changed

5 files changed

+280
-0
lines changed

EvaluateTurbidity/script.m

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
tvec = [];
3+
for i=2:11
4+
tvec = [ tvec, turbidityEst2(rgb2gray(imvecl{1}),rgb2gray(imvecl{i}))];
5+
end

EvaluateTurbidity/softmatting.m

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
%% Matting the transmission map
2+
% Code in this section was partly inspired by code originally from
3+
% http://www.soe.ucsc.edu/classes/ee264/Winter10/Proj6-Code.zip
4+
5+
6+
function t = softmatting(trans_est,im)
7+
8+
win_size = 3; % window size
9+
win_els = win_size.^2; % number of window elements
10+
l_els = win_els.^2; % number of elements calculated in each iteration
11+
12+
win_bord = floor(win_size./2);
13+
14+
e = 0.000001;
15+
16+
[m,n,c] = size(im);
17+
numpix = m*n;
18+
19+
k = reshape(1:numpix, m, n);
20+
U = eye(win_size);
21+
D = eye(win_els);
22+
23+
num_els = l_els*(m-2*win_bord)*(n-2*win_bord);
24+
25+
ind_i = ones(1,num_els);
26+
ind_j = ind_i;
27+
28+
els = zeros(1,num_els);
29+
30+
count = 0;
31+
32+
'Aqui4'
33+
for x = (1 + win_bord):(n - win_bord)
34+
for y = (1 + win_bord):(m - win_bord)
35+
36+
wk = reshape(im(y-win_bord:y+win_bord,x-win_bord:x+win_bord,:), win_els, c);
37+
38+
w_ind = reshape(k(y-win_bord:y+win_bord,x-win_bord:x+win_bord), 1, win_els);
39+
40+
[i j] = meshgrid(w_ind, w_ind);
41+
42+
i = reshape(i,1,l_els);
43+
j = reshape(j,1,l_els);
44+
45+
ind_i((count*l_els + 1):(count*l_els+l_els)) = i;
46+
ind_j((count*l_els + 1):(count*l_els+l_els)) = j;
47+
48+
win_mu = mean(wk)';
49+
50+
win_cov = wk'*wk/win_els-win_mu*win_mu';
51+
52+
dif = wk' - repmat(win_mu,1,win_els);
53+
54+
elements = D - (1 + dif(:,1:win_els)'*inv(...
55+
win_cov + e./win_els.*U)*dif(:,1:win_els))...
56+
./win_els;
57+
58+
els((count*l_els + 1):(count*l_els+l_els)) = ...
59+
reshape(elements,1,l_els);
60+
61+
count = count + 1;
62+
end
63+
end
64+
65+
66+
L = sparse(ind_i, ind_j, els, numpix, numpix);
67+
68+
%% generate refined transmission map
69+
'Aqui6'
70+
% recommended value from HST paper
71+
lambda = .0001;
72+
% equation 15 from HST
73+
74+
a=trans_est(:) .* lambda;
75+
'Aqui6_1'
76+
b=lambda .* speye(size(L));
77+
'Aqui6_2'
78+
soma=L + b;
79+
'Aqui6_3'
80+
t = (soma) \ a;
81+
82+
'Aqui61'
83+
t = t - min(t(:));
84+
85+
'Aqui62'
86+
t = t ./ (max(t(:)));
87+
'Aqui63'
88+
t = t .* (max(trans_est(:)) - min(trans_est(:))) + min(trans_est(:));
89+
'Aqui64'
90+
t = reshape(t, size(trans_est));
91+
92+
end

EvaluateTurbidity/transmission.m

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function trans = transmission(im)
2+
3+
4+
5+
6+
end

EvaluateTurbidity/turbidityEst.m

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
function turb=turbidityEst(J,I,r,c)
2+
3+
4+
%[A,I] = double(max(max(I)))./255;
5+
6+
7+
8+
9+
10+
%gauss = fspecial('gaussian',12);
11+
%J = imfilter(J,gauss);
12+
%I = imfilter(I,gauss);
13+
14+
% [posx posy] = Aest(I,15);
15+
16+
17+
18+
[H S I ] = rgb2hsv(I);
19+
[H S J ] = rgb2hsv(J);
20+
21+
22+
23+
%J = double(J)./255;
24+
%I = double(I)./255;
25+
26+
27+
% A = I(posx(1),posy(1));
28+
A = max(max(I));
29+
30+
31+
%A = I(posx,posy);
32+
33+
%B = I - A;
34+
%figure;
35+
%imshow(B);
36+
%C = J - A;
37+
%figure;
38+
%imshow(C)
39+
for i=1:size(I,1)
40+
for j=1:size(J,2)
41+
B(i,j) = I(i,j) - A;
42+
C(i,j) = J(i,j) - A;
43+
tmap(i,j) = B(i,j)/C(i,j);
44+
end
45+
end
46+
% tmap = (B./C);
47+
%tmap = B./C;
48+
%figure;
49+
%imshow(tmap);
50+
%tmap = 1- tmap;
51+
%max(max(tmap))
52+
%tmap = tmap./max(max(tmap));
53+
%c = tmap(posx,posy);
54+
%figure
55+
%imshow(tmap);
56+
%tmap
57+
tmap = - log(tmap);
58+
%figure
59+
%imshow(tmap);
60+
%dmax = max(max(tmap));
61+
turb = 0;
62+
63+
% vectorize tmap
64+
65+
66+
for i=1:length(r)
67+
68+
turb = turb + tmap(r(i),c(i));
69+
end
70+
turb
71+
turb = turb/length(r);
72+
%daltMap = tmap./dmax;
73+
%c =
74+
%cmap = tmap./distance;
75+
76+
%imshow(daltMap);
77+
78+
79+
80+
%figure
81+
%imshow(cmap);
82+
83+
84+
%t = sum(sum(cmap))/(size(cmap,1)*size(cmap,2));
85+
86+
%c = max(max(cmap));
87+
88+
%figure
89+
%imshow(tmap);
90+
91+
end

EvaluateTurbidity/turbidityEst2.m

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
function tmap=turbidityEst2(J,I)
2+
3+
%[A,I] = double(max(max(I)))./255;
4+
5+
6+
7+
8+
9+
%gauss = fspecial('gaussian',12);
10+
%J = imfilter(J,gauss);
11+
%I = imfilter(I,gauss);
12+
13+
% [posx posy] = Aest(I,15);
14+
15+
16+
17+
[H S I ] = rgb2hsv(I);
18+
[H S J ] = rgb2hsv(J);
19+
20+
21+
22+
%J = double(J)./255;
23+
%I = double(I)./255;
24+
25+
26+
% A = I(posx(1),posy(1));
27+
A = max(max(I));
28+
29+
30+
%A = I(posx,posy);
31+
32+
%B = I - A;
33+
%figure;
34+
%imshow(B);
35+
%C = J - A;
36+
%figure;
37+
%imshow(C)
38+
39+
for i=1:size(I,1)
40+
for j=1:size(J,2)
41+
B(i,j) = I(i,j) - A;
42+
C(i,j) = J(i,j) - A;
43+
tmap(i,j) = max([0.001 B(i,j)/C(i,j)]);
44+
if tmap(i,j) == 1
45+
tmap(i,j) = 0.988;
46+
end
47+
end
48+
end
49+
% tmap = (B./C);
50+
%tmap = B./C;
51+
figure;
52+
imshow(tmap);
53+
%tmap = 1- tmap;
54+
%max(max(tmap))
55+
%tmap = tmap./max(max(tmap));
56+
%c = tmap(posx,posy);
57+
%figure
58+
%imshow(tmap);
59+
tmap = - log(tmap);
60+
%figure
61+
%imshow(tmap);
62+
%dmax = max(max(tmap));
63+
64+
65+
%daltMap = tmap./dmax;
66+
%c =
67+
%cmap = tmap./distance;
68+
69+
%imshow(daltMap);
70+
71+
72+
73+
%figure
74+
%imshow(cmap);
75+
76+
77+
%t = sum(sum(cmap))/(size(cmap,1)*size(cmap,2));
78+
79+
%c = max(max(cmap));
80+
81+
figure
82+
imshow(tmap);
83+
84+
85+
86+
end

0 commit comments

Comments
 (0)