bundles / scipy 1.17.1 / scipy / ndimage / _morphology / binary_fill_holes
function
scipy.ndimage._morphology:binary_fill_holes
Signature
def binary_fill_holes ( input , structure = None , output = None , origin = 0 , * , axes = None ) Summary
Fill the holes in binary objects.
Parameters
input: array_likeN-D binary array with holes to be filled
structure: array_like, optionalStructuring element used in the computation; large-size elements make computations faster but may miss holes separated from the background by thin regions. The default element (with a square connectivity equal to one) yields the intuitive result where all holes in the input have been filled.
output: ndarray, optionalArray of the same shape as input, into which the output is placed. By default, a new array is created.
origin: int, tuple of ints, optionalPosition of the structuring element.
axes: tuple of int or NoneThe axes over which to apply the filter. If None,
inputis filtered along all axes. If anorigintuple is provided, its length must match the number of axes.
Returns
out: ndarrayTransformation of the initial image
inputwhere holes have been filled.
Notes
The algorithm used in this function consists in invading the complementary of the shapes in input from the outer boundary of the image, using binary dilations. Holes are not connected to the boundary and are therefore not invaded. The result is the complementary subset of the invaded region.
Array API Standard Support
binary_fill_holes has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.
==================== ==================== ==================== Library CPU GPU ==================== ==================== ==================== NumPy ✅ n/a CuPy n/a ✅ PyTorch ✅ ⛔ JAX ⚠️ no JIT ⛔ Dask ⚠️ computes graph n/a ==================== ==================== ====================
See
dev-arrayapifor more information.
Examples
from scipy import ndimage import numpy as np a = np.zeros((5, 5), dtype=int) a[1:4, 1:4] = 1 a[2,2] = 0 a ndimage.binary_fill_holes(a).astype(int) ndimage.binary_fill_holes(a, structure=np.ones((5,5))).astype(int)✓
See also
Aliases
-
scipy.ndimage.binary_fill_holes
Referenced by
Other packages
- skimage user_guide:tutorial_segmentation