skimage2.morphology.remove_small_objects#
- skimage2.morphology.remove_small_objects(ar, min_size=<DEPRECATED>, connectivity=1, *, max_size=63, out=None)[source]#
Remove objects smaller than the specified size.
Expects
arto be an array with labeled objects, and removes objects smaller than or equal tomax_size. Ifaris bool, the image is first labeled. This leads to potentially different behavior for bool vs. 0-and-1 arrays.- Parameters:
- arndarray (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_sizeint, optional
Remove objects whose contiguous area (or volume, in N-D) contains this number of pixels or fewer.
Added in version 0.26: To make the naming clearer, replaces deprecated
min_sizewhich only removed objects strictly smaller than its size.- connectivityint, {1, 2, …, ar.ndim}, optional (default: 1)
The connectivity defining the neighborhood of a pixel. Used during labelling if
aris bool.- outndarray
Array of the same shape as
ar, into which the output is placed. By default, a new array is created.
- Returns:
- outndarray, same shape and type as input
ar The input array with small connected components removed.
- outndarray, same shape and type as input
- Other Parameters:
- min_sizeDEPRECATED
Deprecated in favor of
max_size.Deprecated since version 0.26.0.
- Raises:
- TypeError
If the input array is of an invalid type, such as float or string.
- ValueError
If the input array contains negative values.
Examples
>>> from _skimage2 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 array([[False, False, False, False, False], [ True, True, True, False, False], [ True, True, True, False, False]]) >>> c = morphology.remove_small_objects(a, max_size=6, connectivity=2) >>> c array([[False, False, False, True, False], [ True, True, True, False, False], [ True, True, True, False, False]]) >>> d = morphology.remove_small_objects(a, max_size=5, out=a) >>> d is a True