forked from emreozanalkan/RegionGrowingAlgorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CheckFixUnlabeledRegions.m
77 lines (56 loc) · 1.88 KB
/
CheckFixUnlabeledRegions.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
76
77
function [ regionMatrix ] = CheckFixUnlabeledRegions( regionMatrixInput )
%CHECKFIXUNLABELEDREGIONS Summary of this function goes here
% Detailed explanation goes here
regionMatrix = regionMatrixInput;
[zeroRows, zeroCols] = find(regionMatrixInput == 0);
for ii = 1 : numel(zeroRows)
[isCandidate, region] = IsZeroSeedCandidate(regionMatrixInput, zeroRows(ii), zeroCols(ii));
if ~isCandidate
regionMatrix(zeroRows(ii), zeroCols(ii)) = region;
end
end
end
function [ isCandidate, region ] = IsZeroSeedCandidate(regionMatrix, zeroRow, zeroCol)
import java.util.ArrayDeque;
neighbor_List = ArrayDeque();
[r, c] = size(regionMatrix);
visitedMatrix = zeros(r, c);
AddNeighbors(r, c, zeroRow, zeroCol, 8, neighbor_List, visitedMatrix);
regionLabels = [];
while ~neighbor_List.isEmpty()
neighborData = neighbor_List.pop();
regionLabels = [regionLabels regionMatrix(neighborData(1), neighborData(2))];
end
% regionLabels = [];
%
% % Left Neighbor
% regionLabels = [regionLabels regionMatrix(zeroRow, zeroCol - 1)];
%
% % Top Neighbor
% regionLabels = [regionLabels regionMatrix(zeroRow - 1, zeroCol)];
%
% % Right Neighbor
% regionLabels = [regionLabels regionMatrix(zeroRow, zeroCol + 1)];
%
% % Bottom Neighbor
% regionLabels = [regionLabels regionMatrix(zeroRow + 1, zeroCol)];
%
% % Top Left Neighbor
% regionLabels = [regionLabels regionMatrix(zeroRow - 1, zeroCol - 1)];
%
% % Top Right Neighbor
% regionLabels = [regionLabels regionMatrix(zeroRow - 1, zeroCol + 1)];
%
% % Bottom Right Neigbor
% regionLabels = [regionLabels regionMatrix(zeroRow + 1, zeroCol + 1)];
%
% % Bottom Left Neighbor
% regionLabels = [regionLabels regionMatrix(zeroRow + 1, zeroCol - 1)];
region = mode(regionLabels);
[rows, cols] = find(regionLabels == 0);
if numel(rows) > 3
isCandidate = 1;
else
isCandidate = 0;
end
end