-
Notifications
You must be signed in to change notification settings - Fork 1
/
linkEdge.m
75 lines (67 loc) · 2.76 KB
/
linkEdge.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
75
function [edge2, visit_map2] = linkEdge(edg, local_max, theta, i, j, visit_map, thre_low)
% CIS 581 Project 1 - Written by Zimeng YANG
% LINKEDGE - Search the pixels in the edge direction and link edges
% visit_map is used to show whether the pixels have been visited
% Initialization
edge2 = edg;
visit_map2 = visit_map;
visit_map2(i, j) = 1;
% Search the pixels along the edge direction. If their gradient magnitudes
% are larger than the lower threshold, the pixels are the edge, and make
% those pixels as the new centers, start linking again. When there are no
% nearby pixels that meet the requists, stop linking
if (theta(i,j)>=0) && (theta(i,j)<45)
% For each pixel, search in two opposite directions along the edge
% direction
for idx = j:j+1
if (local_max(i-1,idx)>thre_low) && (visit_map2(i-1,idx) == 0)
edge2(i,j) = 1;
[edge2, visit_map2] = linkEdge(edge2, local_max, theta, i-1, idx, visit_map2, thre_low);
end
end
for idx = j-1:j
if (local_max(i+1,idx)>thre_low) && (visit_map(i+1,idx) == 0)
edge2(i,j) = 1;
[edge2, visit_map2] = linkEdge(edge2, local_max, theta, i+1, idx, visit_map2, thre_low);
end
end
elseif (theta(i,j)>=45) && (theta(i,j)<90)
for idx = i-1:i
if (local_max(idx,j+1)>thre_low) && (visit_map(idx,j+1) == 0)
edge2(i,j) = 1;
[edge2, visit_map2] = linkEdge(edge2, local_max, theta, idx, j+1, visit_map2, thre_low);
end
end
for idx = i:i+1
if (local_max(idx,j-1)>thre_low) && (visit_map(idx,j-1) == 0)
edge2(i,j) = 1;
[edge2, visit_map2] = linkEdge(edge2, local_max, theta, idx, j-1, visit_map2, thre_low);
end
end
elseif (theta(i,j)>=-45) && (theta(i,j)<0)
for idx = j:j+1
if (local_max(i+1,idx)>thre_low) && (visit_map(i+1,idx) == 0)
edge2(i,j) = 1;
[edge2, visit_map2] = linkEdge(edge2, local_max, theta, i+1, idx, visit_map2, thre_low);
end
end
for idx = j-1:j
if (local_max(i-1,idx)>thre_low) && (visit_map(i-1,idx) == 0)
edge2(i,j) = 1;
[edge2, visit_map2] = linkEdge(edge2, local_max, theta, i-1, idx, visit_map2, thre_low);
end
end
else
for idx = i-1:i
if (local_max(idx,j-1)>thre_low) && (visit_map(idx,j-1) == 0)
edge2(i,j) = 1;
[edge2, visit_map2] = linkEdge(edge2, local_max, theta, idx, j-1, visit_map2, thre_low);
end
end
for idx = i:i+1
if (local_max(idx,j+1)>thre_low) && (visit_map(idx,j+1) == 0)
edge2(i,j) = 1;
[edge2, visit_map2] = linkEdge(edge2, local_max, theta, idx, j+1, visit_map2, thre_low);
end
end
end