Skip to content

Commit

Permalink
Warn users of remove_small_objects about type
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jni committed Sep 30, 2014
1 parent d0fb18f commit a2def31
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions 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

Expand Down Expand Up @@ -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
Expand Down

1 comment on commit a2def31

@ehusby
Copy link

@ehusby ehusby commented on a2def31 Dec 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jni This is a small, easily-fixable bug:
The warning block doesn't check if the user actually supplied a boolean array, causing the warning to be thrown every time a boolean array with at least one True element is provided as input.
image

Please sign in to comment.