{ } Raw JSON

bundles / skimage 0.26.1rc0.dev0+git20260530.b607368ff / skimage / morphology / gray / erosion

function

skimage.morphology.gray:erosion

source: /dev/scikit-image/src/skimage/morphology/gray.py :143

Signature

def   erosion ( image footprint = None out = None * mode = reflect cval = 0.0 )

Summary

Return grayscale morphological erosion of an image.

Extended Summary

Morphological erosion sets a pixel at (i,j) to the minimum over all pixels in the neighborhood centered at (i,j). Erosion shrinks bright regions and enlarges dark regions.

Parameters

image : ndarray

Image array.

footprint : ndarray or tuple, optional

The neighborhood expressed as a 2-D array of 1's and 0's. If None, use a cross-shaped footprint (connectivity=1). The footprint can also be provided as a sequence of smaller footprints as described in the notes below.

out : ndarray, optional

The array to store the result of the morphology. If None is passed, a new array will be allocated.

mode : str, optional

The mode parameter determines how the array borders are handled. Valid modes are: 'reflect', 'constant', 'nearest', 'mirror', 'wrap', 'max', 'min', or 'ignore'. If 'max' or 'ignore', pixels outside the image domain are assumed to be the maximum for the image's dtype, which causes them to not influence the result. Default is 'reflect'.

cval : scalar, optional

Value to fill past edges of input if mode is 'constant'. Default is 0.0.

Returns

eroded : array, same shape as `image`

The result of the morphological erosion.

Notes

For uint8 (and uint16 up to a certain bit-depth) data, the lower algorithm complexity makes the skimage.filters.rank.minimum function more efficient for larger images and footprints.

The footprint can also be a provided as a sequence of 2-tuples where the first element of each 2-tuple is a footprint ndarray and the second element is an integer describing the number of times it should be iterated. For example footprint=[(np.ones((9, 1)), 1), (np.ones((1, 9)), 1)] would apply a 9x1 footprint followed by a 1x9 footprint resulting in a net effect that is the same as footprint=np.ones((9, 9)), but with lower computational cost. Most of the builtin footprints such as skimage.morphology.disk provide an option to automatically generate a footprint sequence of this type.

For even-sized footprints, skimage.morphology.binary_erosion and this function produce an output that differs: one is shifted by one pixel compared to the other. skimage.morphology.pad_footprint is available to account for this.

Examples

import numpy as np
from skimage.morphology import footprint_rectangle
bright_square = np.array([[0, 0, 0, 0, 0],
                          [0, 1, 1, 1, 0],
                          [0, 1, 1, 1, 0],
                          [0, 1, 1, 1, 0],
                          [0, 0, 0, 0, 0]], dtype=np.uint8)
erosion(bright_square, footprint_rectangle((3, 3)))

Aliases

  • skimage.morphology.erosion

Referenced by