mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-25 13:30:51 +08:00
WIP
This commit is contained in:
committed by
emmanuelle
parent
6614e1339a
commit
44150989ee
@@ -47,17 +47,14 @@ ctypedef struct bginfo:
|
||||
|
||||
cdef void get_bginfo(background_val, bginfo *ret) except *:
|
||||
if background_val is None:
|
||||
warn(DeprecationWarning(
|
||||
'The default value for `background` will change to 0 in v0.12'
|
||||
))
|
||||
ret.background_val = -1
|
||||
ret.background_val = 0
|
||||
else:
|
||||
ret.background_val = background_val
|
||||
|
||||
# The node -999 doesn't exist, it will get subsituted by a meaningful value
|
||||
# upon the first background pixel occurence
|
||||
ret.background_node = -999
|
||||
ret.background_label = -1
|
||||
ret.background_label = 0
|
||||
|
||||
|
||||
# A pixel has neighbors that have already been scanned.
|
||||
@@ -389,8 +386,7 @@ def label(input, neighbors=None, background=None, return_num=False,
|
||||
**Deprecated, use ``connectivity`` instead.**
|
||||
background : int, optional
|
||||
Consider all pixels with this value as background pixels, and label
|
||||
them as -1. (Note: background pixels will be labeled as 0 starting with
|
||||
version 0.12).
|
||||
them as 0.
|
||||
return_num : bool, optional
|
||||
Whether to return the number of assigned labels.
|
||||
connectivity : int, optional
|
||||
@@ -430,10 +426,10 @@ def label(input, neighbors=None, background=None, return_num=False,
|
||||
... [1, 1, 5],
|
||||
... [0, 0, 0]])
|
||||
|
||||
>>> print(label(x, background=0))
|
||||
[[ 0 -1 -1]
|
||||
[ 0 0 1]
|
||||
[-1 -1 -1]]
|
||||
>>> print(label(x, background=1))
|
||||
[[ 0 1 1]
|
||||
[ 0 0 2]
|
||||
[ 3 3 3]]
|
||||
|
||||
"""
|
||||
# We have to ensure that the shape of the input can be handled by the
|
||||
@@ -515,7 +511,7 @@ cdef DTYPE_t resolve_labels(DTYPE_t *data_p, DTYPE_t *forest_p,
|
||||
our knowledge of prov. labels relationship.
|
||||
We also track how many distinct final labels we have.
|
||||
"""
|
||||
cdef DTYPE_t counter = bg.background_label + 1, i
|
||||
cdef DTYPE_t counter = 0, i
|
||||
|
||||
for i in range(shapeinfo.numels):
|
||||
if i == bg.background_node:
|
||||
|
||||
@@ -24,17 +24,14 @@ class TestConnectedComponents:
|
||||
[6, 5, 5, 7, 8, 9]])
|
||||
|
||||
def test_basic(self):
|
||||
with expected_warnings(['`background`']):
|
||||
assert_array_equal(label(self.x), self.labels)
|
||||
assert_array_equal(label(self.x), self.labels)
|
||||
|
||||
# Make sure data wasn't modified
|
||||
assert self.x[0, 2] == 3
|
||||
|
||||
def test_random(self):
|
||||
x = (np.random.rand(20, 30) * 5).astype(np.int)
|
||||
|
||||
with expected_warnings(['`background`']):
|
||||
labels = label(x)
|
||||
labels = label(x)
|
||||
|
||||
n = labels.max()
|
||||
for i in range(n):
|
||||
@@ -45,29 +42,26 @@ class TestConnectedComponents:
|
||||
x = np.array([[0, 0, 1],
|
||||
[0, 1, 0],
|
||||
[1, 0, 0]])
|
||||
with expected_warnings(['`background`']):
|
||||
assert_array_equal(label(x), x)
|
||||
assert_array_equal(label(x), x)
|
||||
|
||||
def test_4_vs_8(self):
|
||||
x = np.array([[0, 1],
|
||||
[1, 0]], dtype=int)
|
||||
with expected_warnings(['`background`']):
|
||||
assert_array_equal(label(x, 4),
|
||||
[[0, 1],
|
||||
[2, 3]])
|
||||
assert_array_equal(label(x, 8),
|
||||
[[0, 1],
|
||||
[1, 0]])
|
||||
assert_array_equal(label(x, 4),
|
||||
[[0, 1],
|
||||
[2, 3]])
|
||||
assert_array_equal(label(x, 8),
|
||||
[[0, 1],
|
||||
[1, 0]])
|
||||
|
||||
def test_background(self):
|
||||
x = np.array([[1, 0, 0],
|
||||
[1, 1, 5],
|
||||
[0, 0, 0]])
|
||||
|
||||
with expected_warnings(['`background`']):
|
||||
assert_array_equal(label(x), [[0, 1, 1],
|
||||
[0, 0, 2],
|
||||
[3, 3, 3]])
|
||||
assert_array_equal(label(x), [[0, 1, 1],
|
||||
[0, 0, 2],
|
||||
[3, 3, 3]])
|
||||
|
||||
assert_array_equal(label(x, background=0),
|
||||
[[0, -1, -1],
|
||||
@@ -100,8 +94,7 @@ class TestConnectedComponents:
|
||||
[0, 0, 6],
|
||||
[5, 5, 5]])
|
||||
|
||||
with expected_warnings(['`background`']):
|
||||
assert_array_equal(label(x, return_num=True)[1], 4)
|
||||
assert_array_equal(label(x, return_num=True)[1], 4)
|
||||
|
||||
assert_array_equal(label(x, background=0, return_num=True)[1], 3)
|
||||
|
||||
@@ -142,8 +135,7 @@ class TestConnectedComponents3d:
|
||||
[10, 5, 7, 7, 7]])
|
||||
|
||||
def test_basic(self):
|
||||
with expected_warnings(['`background`']):
|
||||
labels = label(self.x)
|
||||
labels = label(self.x)
|
||||
assert_array_equal(labels, self.labels)
|
||||
|
||||
assert self.x[0, 0, 2] == 2, \
|
||||
@@ -151,9 +143,7 @@ class TestConnectedComponents3d:
|
||||
|
||||
def test_random(self):
|
||||
x = (np.random.rand(20, 30) * 5).astype(np.int)
|
||||
|
||||
with expected_warnings(['`background`']):
|
||||
labels = label(x)
|
||||
labels = label(x)
|
||||
|
||||
n = labels.max()
|
||||
for i in range(n):
|
||||
@@ -165,8 +155,7 @@ class TestConnectedComponents3d:
|
||||
x[0, 2, 2] = 1
|
||||
x[1, 1, 1] = 1
|
||||
x[2, 0, 0] = 1
|
||||
with expected_warnings(['`background`']):
|
||||
assert_array_equal(label(x), x)
|
||||
assert_array_equal(label(x), x)
|
||||
|
||||
def test_4_vs_8(self):
|
||||
x = np.zeros((2, 2, 2), int)
|
||||
@@ -174,9 +163,8 @@ class TestConnectedComponents3d:
|
||||
x[1, 0, 0] = 1
|
||||
label4 = x.copy()
|
||||
label4[1, 0, 0] = 2
|
||||
with expected_warnings(['`background`']):
|
||||
assert_array_equal(label(x, 4), label4)
|
||||
assert_array_equal(label(x, 8), x)
|
||||
assert_array_equal(label(x, 4), label4)
|
||||
assert_array_equal(label(x, 8), x)
|
||||
|
||||
def test_background(self):
|
||||
x = np.zeros((2, 3, 3), int)
|
||||
@@ -202,9 +190,7 @@ class TestConnectedComponents3d:
|
||||
[BG, 0, 1],
|
||||
[BG, BG, BG]])
|
||||
|
||||
with expected_warnings(['`background`']):
|
||||
assert_array_equal(label(x), lnb)
|
||||
|
||||
assert_array_equal(label(x), lnb)
|
||||
assert_array_equal(label(x, background=0), lb)
|
||||
|
||||
def test_background_two_regions(self):
|
||||
@@ -240,9 +226,7 @@ class TestConnectedComponents3d:
|
||||
[0, 0, 6],
|
||||
[5, 5, 5]])
|
||||
|
||||
with expected_warnings(['`background`']):
|
||||
assert_array_equal(label(x, return_num=True)[1], 4)
|
||||
|
||||
assert_array_equal(label(x, return_num=True)[1], 4)
|
||||
assert_array_equal(label(x, background=0, return_num=True)[1], 3)
|
||||
|
||||
def test_1D(self):
|
||||
@@ -254,8 +238,7 @@ class TestConnectedComponents3d:
|
||||
(1, xlen, 1), (xlen, 1, 1), (1, 1, xlen))
|
||||
for reshape in reshapes:
|
||||
x2 = x.reshape(reshape)
|
||||
with expected_warnings(['`background`']):
|
||||
labelled = label(x2)
|
||||
labelled = label(x2)
|
||||
assert_array_equal(y, labelled.flatten())
|
||||
|
||||
def test_nd(self):
|
||||
|
||||
Reference in New Issue
Block a user