skimage2.morphology.remove_small_holes#

skimage2.morphology.remove_small_holes(ar, area_threshold=<DEPRECATED>, connectivity=1, *, max_size=63, out=None)[source]#

Remove contiguous holes smaller than the specified size.

Parameters:
arndarray (arbitrary shape, int or bool type)

The array containing the connected components of interest.

max_sizeint, optional

Remove holes 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 area_threshold which only removed holes strictly smaller than its size.

connectivityint, {1, 2, …, ar.ndim}, optional (default: 1)

The connectivity defining the neighborhood of a pixel.

outndarray

Array of the same shape as ar and bool dtype, 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 holes within connected components removed.

Other Parameters:
area_thresholdDEPRECATED

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.

Notes

If the array type is int, it is assumed that it contains already-labeled objects. The labels are not kept in the output image (this function always outputs a bool image). It is suggested that labeling is completed after using this function.

Examples

>>> from _skimage2 import morphology
>>> a = np.array([[1, 1, 1, 1, 1, 0],
...               [1, 1, 1, 0, 1, 0],
...               [1, 0, 0, 1, 1, 0],
...               [1, 1, 1, 1, 1, 0]], bool)
>>> b = morphology.remove_small_holes(a, max_size=1)
>>> b
array([[ True,  True,  True,  True,  True, False],
       [ True,  True,  True,  True,  True, False],
       [ True, False, False,  True,  True, False],
       [ True,  True,  True,  True,  True, False]])
>>> c = morphology.remove_small_holes(a, max_size=1, connectivity=2)
>>> c
array([[ True,  True,  True,  True,  True, False],
       [ True,  True,  True, False,  True, False],
       [ True, False, False,  True,  True, False],
       [ True,  True,  True,  True,  True, False]])
>>> d = morphology.remove_small_holes(a, max_size=1, out=a)
>>> d is a
True