-
Notifications
You must be signed in to change notification settings - Fork 1
/
indices_for_merge.m
51 lines (45 loc) · 1.63 KB
/
indices_for_merge.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
function index = indices_for_merge(C,count,max_dist)
% Line detection and merging
% (c) Falah Jabar ([email protected])
index = zeros(count);
for i=1:count
k_min = C(i,1);
k_max = C(i,2);
l_min = min(C(i,3),C(i,4));
l_max = max(C(i,3),C(i,4));
if abs(C(i,6)) < 45
for j=i+1:count
u_min = C(j,1);
u_max = C(j,2);
v_min = min(C(j,3),C(j,4));
v_max = max(C(j,3),C(j,4));
if ((v_min < l_min) && (v_max >= l_min)) || ...
((v_min <= l_max) && (v_max > l_max)) || ...
((v_min >= l_min) && (v_max <= l_max))
% => segments i and j overllap
index(i,j) = 1;
elseif (abs(l_min-v_max) < max_dist) || ...
(abs(l_max-v_min) < max_dist)
% => segments i,j are close to each other
index(i,j) = 1;
end
end
else
for j=i+1:count
u_min = C(j,1);
u_max = C(j,2);
v_min = min(C(j,3),C(j,4));
v_max = max(C(j,3),C(j,4));
if ((u_min < k_min) && (u_max >= k_min))|| ...
((u_min <= k_max) && (u_max > k_max)) || ...
((u_min >= k_min) && (u_max <= k_max))
% => segments i and j overllap
index(i,j) = 1;
elseif (abs(k_min-u_max) < max_dist) || ...
(abs(k_max-u_min) < max_dist)
% => segments i,j are close to each other
index(i,j) = 1;
end
end
end
end