{ } Raw JSON

bundles / skimage 0.26.1rc0.dev0+git20260530.b607368ff / skimage / morphology / misc / remove_small_objects

function

skimage.morphology.misc:remove_small_objects

source: /dev/scikit-image/src/skimage/morphology/misc.py :32

Signature

def   remove_small_objects ( ar min_size = <DEPRECATED> connectivity = 1 * max_size = 63 out = None )

Summary

Remove objects smaller than the specified size.

Extended Summary

Expects ar to be an array with labeled objects, and removes objects smaller than or equal to max_size. If ar is bool, the image is first labeled. This leads to potentially different behavior for bool vs. 0-and-1 arrays.

Parameters

ar : ndarray (arbitrary shape, int or bool type)

The array containing the objects of interest. If the array type is int, the ints must be non-negative.

max_size : int, optional

Remove objects whose contiguous area (or volume, in N-D) contains this number of pixels or fewer.

connectivity : int, {1, 2, ..., ar.ndim}, optional (default: 1)

The connectivity defining the neighborhood of a pixel. Used during labelling if ar is bool.

out : ndarray

Array of the same shape as ar, into which the output is placed. By default, a new array is created.

Returns

out : ndarray, same shape and type as input `ar`

The input array with small connected components removed.

Raises

: TypeError

If the input array is of an invalid type, such as float or string.

: ValueError

If the input array contains negative values.

Other Parameters

min_size : DEPRECATED

Deprecated in favor of max_size.

Examples

from skimage import morphology
a = np.array([[0, 0, 0, 1, 0],
              [1, 1, 1, 0, 0],
              [1, 1, 1, 0, 1]], bool)
b = morphology.remove_small_objects(a, max_size=5)
b
c = morphology.remove_small_objects(a, max_size=6, connectivity=2)
c
d = morphology.remove_small_objects(a, max_size=5, out=a)
d is a

See also

skimage.morphology.remove_objects_by_distance
skimage.morphology.remove_small_holes

Aliases

  • skimage.morphology.remove_small_objects

Referenced by