From a2def31fca2dddce920c924fd57a211820e14b45 Mon Sep 17 00:00:00 2001 From: Juan Nunez-Iglesias Date: Tue, 30 Sep 2014 14:51:00 +1000 Subject: [PATCH] Warn users of `remove_small_objects` about type When input type is `int`, we assume that the image is pre-labeled. However, when only 0 and 1 are present, it may be that the user expects us to treat it as a binary image. We don't, but now issue a warning that they might want to use a bool image. Fixes #1178. --- skimage/morphology/misc.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/skimage/morphology/misc.py b/skimage/morphology/misc.py index fe1f27d8bae..3b20ef8826f 100644 --- a/skimage/morphology/misc.py +++ b/skimage/morphology/misc.py @@ -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