Merge pull request #1183 from jni/warn-single-labels

Warn when single int label of 1 is passed to remove_small_objects
This commit is contained in:
Johannes Schönberger
2014-09-30 08:18:33 -04:00
2 changed files with 14 additions and 1 deletions
+5
View File
@@ -1,5 +1,6 @@
import numpy as np
import functools
import warnings
import scipy.ndimage as nd
from .selem import _default_selem
@@ -128,6 +129,10 @@ def remove_small_objects(ar, min_size=64, connectivity=1, in_place=False):
"relabeling the input with `scipy.ndimage.label` or "
"`skimage.morphology.label`.")
if len(component_sizes) == 2:
warnings.warn("Only one label was provided to `remove_small_objects`. "
"Did you mean to use a boolean array?")
too_small = component_sizes < min_size
too_small_mask = too_small[ccs]
out[too_small_mask] = 0
+9 -1
View File
@@ -1,5 +1,6 @@
import numpy as np
from numpy.testing import assert_array_equal, assert_equal, assert_raises
from numpy.testing import (assert_array_equal, assert_equal, assert_raises,
assert_warns)
from skimage.morphology import remove_small_objects
test_image = np.array([[0, 0, 0, 1, 0],
@@ -55,6 +56,13 @@ def test_uint_image():
assert_array_equal(observed, expected)
def test_single_label_warning():
image = np.array([[0, 0, 0, 1, 0],
[1, 1, 1, 0, 0],
[1, 1, 1, 0, 0]], int)
assert_warns(UserWarning, remove_small_objects, image, min_size=6)
def test_float_input():
float_test = np.random.rand(5, 5)
assert_raises(TypeError, remove_small_objects, float_test)