BUG: Fix background labelling for case when (0, 0) belongs to the background.

This commit is contained in:
Stefan van der Walt
2012-06-12 09:51:16 -07:00
parent 6741bb639a
commit 944f79cdce
2 changed files with 24 additions and 0 deletions
+3
View File
@@ -155,6 +155,9 @@ def label(np.ndarray[DTYPE_t, ndim=2] input,
raise ValueError('Neighbors must be either 4 or 8.')
# Initialize the first row
if data[0, 0] == background:
link_bg(forest_p, 0, &background_node)
for j in range(1, cols):
if data[0, j] == background:
link_bg(forest_p, j, &background_node)
+21
View File
@@ -61,5 +61,26 @@ class TestConnectedComponents:
[0, 0, 1],
[-1, -1, -1]])
def test_background_two_regions(self):
x = np.array([[0, 0, 6],
[0, 0, 6],
[5, 5, 5]])
assert_array_equal(label(x, background=0),
[[-1, -1, 0],
[-1, -1, 0],
[ 1, 1, 1]])
def test_background_one_region_center(self):
x = np.array([[0, 0, 0],
[0, 1, 0],
[0, 0, 0]])
assert_array_equal(label(x, neighbors=4, background=0),
[[-1, -1, -1],
[-1, 0, -1],
[-1, -1, -1]])
if __name__ == "__main__":
run_module_suite()