-
Notifications
You must be signed in to change notification settings - Fork 15
/
do_hough.m
74 lines (64 loc) · 1.81 KB
/
do_hough.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
function do_hough(l,rotI,pk,thresh)
[H,theta,rho] = hough(l); %%ceil(0.3*max(H(:)))
P = houghpeaks(H,pk,'threshold',thresh);
x = theta(P(:,2));
y = rho(P(:,1));
plot(x,y,'s','color','black');
lines = houghlines(l,theta,rho,P,'FillGap',5,'MinLength',7);
figure, imshow(rotI), hold on
max_len = 0;
the = [lines.theta];
ml = [];
for k = 1:length(lines)
ml = [ml norm(lines(k).point1 - lines(k).point2)];
end
[~,b] = max(ml);
nn = find(abs(the - the(b)) < 2);
rr = [lines(nn).rho ];
vl = zeros(size(rr));
iter = 0;
for i = 1:length(rr)
kw = (sqrt(sum((rr - rr(i)).^2,1)) < 2);
if(vl(bn) ==0 && vl(i) == 0)
vl(bn) = iter;
vl(i) = iter;
iter = iter+1;
elseif(vl(i) == 0 && vl(bn) ~= 0)
vl(i) = vl(bn);
elseif(vl(i)~=0)
continue;
end
end
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
% Plot beginnings and ends of lines
plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');
plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
% Determine the endpoints of the longest line segment
len = norm(lines(k).point1 - lines(k).point2);
if ( len > max_len)
max_len = len;
xy_long = xy;
end
end
% highlight the longest line segment
plot(xy_long(:,1),xy_long(:,2),'LineWidth',2,'Color','red');
figure, imshow(rotI), hold on
max_len = 0;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
% Plot beginnings and ends of lines
plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');
plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
% Determine the endpoints of the longest line segment
len = norm(lines(k).point1 - lines(k).point2);
if ( len > max_len)
max_len = len;
xy_long = xy;
end
end
% highlight the longest line segment
plot(xy_long(:,1),xy_long(:,2),'LineWidth',2,'Color','red');
end