{ } Raw JSON

bundles / scipy 1.17.1 / scipy / ndimage / _morphology / binary_erosion

function

scipy.ndimage._morphology:binary_erosion

source: /scipy/ndimage/_morphology.py :305

Signature

def   binary_erosion ( input structure = None iterations = 1 mask = None output = None border_value = 0 origin = 0 brute_force = False * axes = None )

Summary

Multidimensional binary erosion with a given structuring element.

Extended Summary

Binary erosion is a mathematical morphology operation used for image processing.

Parameters

input : array_like

Binary image to be eroded. Non-zero (True) elements form the subset to be eroded.

structure : array_like, optional

Structuring element used for the erosion. Non-zero elements are considered True. If no structuring element is provided, an element is generated with a square connectivity equal to one.

iterations : int, optional

The erosion is repeated iterations times (one, by default). If iterations is less than 1, the erosion is repeated until the result does not change anymore.

mask : array_like, optional

If a mask is given, only those elements with a True value at the corresponding mask element are modified at each iteration.

output : ndarray, optional

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

border_value : int (cast to 0 or 1), optional

Value at the border in the output array.

origin : int or tuple of ints, optional

Placement of the filter, by default 0.

brute_force : boolean, optional

Memory condition: if False, only the pixels whose value was changed in the last iteration are tracked as candidates to be updated (eroded) in the current iteration; if True all pixels are considered as candidates for erosion, regardless of what happened in the previous iteration. False by default.

axes : tuple of int or None

The axes over which to apply the filter. If None, input is filtered along all axes. If an origin tuple is provided, its length must match the number of axes.

Returns

binary_erosion : ndarray of bools

Erosion of the input by the structuring element.

Notes

Erosion [1] is a mathematical morphology operation [2] that uses a structuring element for shrinking the shapes in an image. The binary erosion of an image by a structuring element is the locus of the points where a superimposition of the structuring element centered on the point is entirely contained in the set of non-zero elements of the image.

Array API Standard Support

binary_erosion 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-arrayapi for more information.

Examples

from scipy import ndimage
import numpy as np
a = np.zeros((7,7), dtype=int)
a[1:6, 2:5] = 1
a
ndimage.binary_erosion(a).astype(a.dtype)
ndimage.binary_erosion(a, structure=np.ones((5,5))).astype(a.dtype)

See also

binary_closing
binary_dilation
binary_opening
generate_binary_structure
grey_erosion

Aliases

  • scipy.ndimage.binary_erosion

Referenced by