/
vertextrfill.m
46 lines (44 loc) · 1.79 KB
/
vertextrfill.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
function vertextrfill = vertextrfill(EDGEim)
%this code fills vertical extremes, the leftmost and rightmost columns
%of the image, after the canny edges have been extracted. This can also
%fill the top and bottom by transposing EDGEim. EDGEim is the edge
%image from the output of an edge detector.
flagrise = false;
flagfall = false;
vertextrfill = EDGEim;
for kk = [1,length(EDGEim(1,:))]
currentnvalue = false; %current neighbor value
lastnvalue = false;
flagrise = false;
flagfall = false;
for jj = 1:length(EDGEim(:,1))
if kk == 1
currentnvalue = vertextrfill(jj,kk+1);
if and((currentnvalue == 0),(lastnvalue == 1))
flagfall = ~flagfall;
elseif and((currentnvalue == 1),(lastnvalue == 0))
flagrise = ~flagrise;
end
if or(flagrise,flagfall) == 0
lastnvalue = currentnvalue;
elseif or(flagrise,flagfall) == 1
vertextrfill(jj,kk)=true;
lastnvalue = currentnvalue;
end
end
if kk == length(EDGEim(1,:))
currentnvalue = vertextrfill(jj,kk-1);
if and((currentnvalue == 0),(lastnvalue == 1))
flagrise = ~flagrise;
elseif and((currentnvalue == 1),(lastnvalue == 0))
flagfall = ~flagfall;
end
if or(flagrise,flagfall) == 0
lastnvalue = currentnvalue;
elseif or(flagrise,flagfall) == 1
vertextrfill(jj,kk)=true;
lastnvalue = currentnvalue;
end
end
end
end