-
Notifications
You must be signed in to change notification settings - Fork 5
/
draw_contours.m
52 lines (49 loc) · 1.52 KB
/
draw_contours.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
function [contourImg] = draw_contours(labels, img)
% function [contourImg] = draw_contours(labels, img)
%
% David Stutz <david.stutz@rwth-aachen.de>
rows = size(img, 1);
cols = size(img, 2);
contourImg = img;
for i = 1: rows
for j = 1: cols
label = labels(i, j);
labelTop = 0;
labelBottom = 0;
labelLeft = 0;
labelRight = 0;
if i > 1
labelTop = labels(i - 1, j);
end;
if j > 1
labelLeft = labels(i, j - 1);
end;
if i < rows
labelBottom = labels(i + 1, j);
end;
if j < cols
labelRight = labels(i, j + 1);
end;
if labelTop ~= 0 && labelTop ~= label
contourImg(i, j, 1) = 0;
contourImg(i, j, 2) = 0;
contourImg(i, j, 3) = 0;
end;
if labelLeft ~= 0 && labelLeft ~= label
contourImg(i, j, 1) = 0;
contourImg(i, j, 2) = 0;
contourImg(i, j, 3) = 0;
end;
if labelBottom ~= 0 && labelBottom ~= label
contourImg(i, j, 1) = 0;
contourImg(i, j, 2) = 0;
contourImg(i, j, 3) = 0;
end;
if labelRight ~= 0 && labelRight ~= label
contourImg(i, j, 1) = 0;
contourImg(i, j, 2) = 0;
contourImg(i, j, 3) = 0;
end;
end;
end;
end