forked from emreozanalkan/RegionGrowingAlgorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddNeighbors.m
More file actions
49 lines (33 loc) · 1.62 KB
/
Copy pathAddNeighbors.m
File metadata and controls
49 lines (33 loc) · 1.62 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
function AddNeighbors( imageRowCount, imageColCount, row, col, neighborhoodType, neighborList, visitedMatrix )
%ADDNEIGHBORS Adding
% Detailed explanation goes here
if row < 1 || row > imageRowCount || col < 1 || col > imageColCount
return;
end
% Left Neighbor
AddNeighborToList(imageRowCount, imageColCount, row, col - 1, neighborList, visitedMatrix);
% Top Neighbor
AddNeighborToList(imageRowCount, imageColCount, row - 1, col, neighborList, visitedMatrix);
% Right Neighbor
AddNeighborToList(imageRowCount, imageColCount, row, col + 1, neighborList, visitedMatrix);
% Bottom Neighbor
AddNeighborToList(imageRowCount, imageColCount, row + 1, col, neighborList, visitedMatrix);
if neighborhoodType == 8
% Top Left Neighbor
AddNeighborToList(imageRowCount, imageColCount, row - 1, col - 1, neighborList, visitedMatrix);
% Top Right Neighbor
AddNeighborToList(imageRowCount, imageColCount, row - 1, col + 1, neighborList, visitedMatrix);
% Bottom Right Neigbor
AddNeighborToList(imageRowCount, imageColCount, row + 1, col + 1, neighborList, visitedMatrix);
% Bottom Left Neighbor
AddNeighborToList(imageRowCount, imageColCount, row + 1, col - 1, neighborList, visitedMatrix);
end
end
function AddNeighborToList(imageRowCount, imageColCount, row, col, neighborList, visitedMatrix)
if row < 1 || row > imageRowCount || col < 1 || col > imageColCount
return;
end
if visitedMatrix(row, col) == 0
neighborList.add([row col]);
end
end