Fix type hierarchy check in remove_small_objects

This commit is contained in:
Juan Nunez-Iglesias
2013-09-09 13:53:33 +10:00
parent 8ed56abb42
commit 2af5c41571
2 changed files with 14 additions and 1 deletions
+1 -1
View File
@@ -52,7 +52,7 @@ def remove_small_objects(ar, min_size=64, connectivity=1, in_place=False):
True
"""
# Should use `issubdtype` for bool below, but there's a bug in numpy 1.7
if not (ar.dtype == bool or np.issubdtype(ar.dtype, int)):
if not (ar.dtype == bool or np.issubdtype(ar.dtype, np.integer)):
raise TypeError("Only bool or integer image types are supported. "
"Got %s." % ar.dtype)
+13
View File
@@ -42,6 +42,19 @@ def test_labeled_image():
assert_array_equal(observed, expected)
def test_uint_image():
labeled_image = np.array([[2, 2, 2, 0, 1],
[2, 2, 2, 0, 1],
[2, 0, 0, 0, 0],
[0, 0, 3, 3, 3]], dtype=np.uint8)
expected = np.array([[2, 2, 2, 0, 0],
[2, 2, 2, 0, 0],
[2, 0, 0, 0, 0],
[0, 0, 3, 3, 3]], dtype=np.uint8)
observed = remove_small_objects(labeled_image, min_size=3)
assert_array_equal(observed, expected)
def test_float_input():
float_test = np.random.rand(5, 5)
assert_raises(TypeError, remove_small_objects, float_test)