-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathExtractMidpoints2.m
More file actions
87 lines (80 loc) · 1.97 KB
/
ExtractMidpoints2.m
File metadata and controls
87 lines (80 loc) · 1.97 KB
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
78
79
80
81
82
83
84
85
86
87
function [Points] = ExtractMidpoints2(Image)
% Function to Extract the Midpoints of a line in a binary image.
% Input: Image - matrix of the binary image with a line
% Output: Points - matrix of the extracted points
%
%
s = size(Image);
width = s(2);
height = s(1);
HPoints = zeros(1, height);
WPoints = zeros(1, width);
st = [];
p = 1; % Inner increment variable
for m = height:-1:1
xa = [];
xb = [];
for n = 1:1:width
if(Image(m, n) == 1)
xa = n;
break;
end
end
for n = width:-1:1
if(Image(m, n) == 1)
xb = n;
break;
end
end
if ~(isempty(xa) || isempty(xb))
if ~(xa == 1 || xb == width)
if(~((xb - xa) > 80))
if(~((xb - xa) < 40))
st = m;
break;
end
end
end
end
end
% Entry Point xa and xb
midpoint = xa + round((xb - xa)/2);
% disp(midpoint)
if (~isempty(st))
for m = st:-10:1
ya = [];
yb = [];
for n = midpoint:1:width
if (Image(m,n) == 0)
yb = n;
break;
end
end
for n = midpoint:-1:1
if (Image(m,n) == 0)
ya = n;
break;
end
end
if ~(isempty(ya) || isempty(yb))
if ~(ya == 1 || yb == width)
if(~((yb - ya) > 80))
if(~((yb - ya) < 20))
midpoint = ya + round((yb - ya)/2);
% disp(midpoint);
HPoints(p) = m;
WPoints(p) = midpoint;
p = p + 1;
end
end
end
end
end
end
Iw = WPoints > 0;
Ih = HPoints > 0;
Points = [WPoints(Iw); HPoints(Ih)];
%image(Image);
%hold on;
%plot(WPoints, HPoints, '.r');
end