mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-15 11:25:53 +08:00
BUG: Fix background labelling for case when (0, 0) belongs to the background.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user