-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathComputeNormlizedSGD.m
executable file
·77 lines (51 loc) · 1.44 KB
/
ComputeNormlizedSGD.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
74
75
76
77
function [ sgd ] = ComputeNormlizedSGD( F1, F2, size1, size2)
h1 = size1(1); w1 = size1(2);
h2 = size2(1); w2 = size2(2);
N = 1000;
sgd = 0;
count = 0;
iteration = 0;
max_iteration = N * 10;
while (count < N && iteration < max_iteration)
iteration = iteration + 1;
d1 = one_iteration(F1, F2, h1, w1, h2, w2);
if d1 < 0
continue;
end
d2 = one_iteration(F2, F1, h2, w2, h1, w1);
if d2 < 0
continue;
end
count = count + 1;
sgd = sgd + (d1 + d2) / 2;
end
sgd = min(sgd / N, 1);
end
function d = one_iteration(F1, F2, h1, w1, h2, w2)
d = -1;
factor1 = 1 / sqrt(h1 * h1 + w1 * w1);
factor2 = 1 / sqrt(h2 * h2 + w2 * w2);
m = round([w1.*rand(), h1.*rand()]);
epiLine1 = epipolarLine(F1,m);
borderline1 = lineToBorderPoints(epiLine1,[h2, w2]);
if borderline1(1) < 0
return;
end
m1 = find_point_in_line(epiLine1,borderline1);
epiLine2 = epipolarLine(F2,m);
d1_ = d_from_point_to_line(m1, epiLine2);
d1_ = d1_ * factor2;
epiLine3 = epipolarLine(F2',m1);
d1 = d_from_point_to_line(m, epiLine3);
d1 = d1 * factor1;
d = (d1 + d1_) / 2;
end
function m = find_point_in_line(epiLines, borderlines)
m_x = borderlines(1) + (borderlines(3) - borderlines(1)) * rand();
m_y = - (epiLines(1) * m_x + epiLines(3)) / epiLines(2);
m = [m_x, m_y];
end
function distance = d_from_point_to_line(point, line)
point(:,3) = 1;
distance = abs(dot(point, line)) / (norm(line(1:2)) + 1e-10);
end