-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathselectLineSegmentGroups.m
48 lines (43 loc) · 1.31 KB
/
selectLineSegmentGroups.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
function lineGroups = selectLineSegmentGroups(lineGroups, I)
minNoLineGroups = 5;
while true
% better not eliminate if there are already few groups
noLineGroups = length(lineGroups);
if noLineGroups <= minNoLineGroups
break;
end
funToSolve = @(x)getDistParamError(x, I, lineGroups);
[~, error] = fminsearch(funToSolve, [0;0]);
minError = error;
origLineGroups = lineGroups;
% eliminate each line segment group and search for a distortion
% parameter
indToEliminate = 0;
for i = 1:noLineGroups
lineGroups = {};
for j = 1:noLineGroups
if j ~= i
lineGroups{end + 1} = origLineGroups{j};
end
end
funToSolve = @(x)getDistParamError(x, I, lineGroups);
[~, error] = fminsearch(funToSolve, [0;0]);
if (error < minError)
minError = error;
indToEliminate = i;
end
end
% if eliminating any of the line segment groups didn't help, break
if indToEliminate == 0
lineGroups = origLineGroups;
break;
else
disp(['Eliminating line segment group #' num2str(indToEliminate)]);
lineGroups = {};
for j = 1:noLineGroups
if j ~= indToEliminate
lineGroups{end + 1} = origLineGroups{j};
end
end
end
end