-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhorizontal_lines.m
57 lines (33 loc) · 1.31 KB
/
horizontal_lines.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
function points = horizontal_lines(line1,line2,rotated_convexhull,flag)
% line1 is the left vertical line points. line2 is the right vertical line
% points.
% rotated_convexhull is the convex hull of the rotated image.
% flag is whether you want left corner points or right corner points.
new1=rotated_convexhull;
new1(:,end+1)=new1(:,1); % circular array
if (strcmp(flag,'left'))
for i=1:size(new1,2)-1
intersect_point(i,:) = intersection(line1,[new1(:,i)';new1(:,i+1)']);
end
elseif(strcmp(flag,'right'))
for i=1:size(new1,2)-1
intersect_point(i,:) = intersection(line2,[new1(:,i)';new1(:,i+1)']);
end
else
error('Which corner points you want');
end
% getting the top most and bottom most intersect_points and returning the
% points in order. (works for both left and right points)
id = find(~isnan(intersect_point(:,1)));
if(numel(id)>2 )
low_id = find(intersect_point(id,2) == min(intersect_point(id,2)) );
high_id = find(intersect_point(id,2) == max(intersect_point(id,2)) );
points=[intersect_point(id(low_id),:);intersect_point(id(high_id),:)];
else
points=[intersect_point(id(1),:);intersect_point(id(2),:)];
end
% flipping it, if found in reverse
if(points(2,2)<points(1,2))
points=flipud(points);
end
end