skimage2.morphology.erosion#
- skimage2.morphology.erosion(image, footprint=None, *, out=None, mode='ignore', cval=0.0)[source]#
Return grayscale morphological erosion of an image.
Morphological erosion shrinks bright regions and enlarges dark regions. It assigns each pixel the minimum of the active neighborhood of that pixel. The values where
footprintis 1 define this active neighborhood.- Parameters:
- imagendarray
Input image.
- footprintndarray or tuple, optional
The neighborhood expressed as a 2-D array of 1’s and 0’s. If None, use a cross-shaped footprint (so-called 1-connectivity). The footprint can also be provided as a sequence of smaller footprints as described in the notes below. See _Notes_ for more.
- outndarray, optional
The array to store the result of the morphology. If None, a new array is allocated.
- modestr, optional
The
modeparameter 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 ‘ignore’.- cvalscalar, optional
Value to fill past edges of input if
modeis ‘constant’. Default is 0.0.
- Returns:
- outndarray, same shape and dtype as
image The result of the morphological erosion.
- outndarray, same shape and dtype as
Notes
For
uint8(anduint16up to a certain bit-depth) data, the lower algorithm complexity makes theskimage2.filters.rank.minimum()function more efficient for larger images and footprints.The footprint can also be 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 asfootprint=np.ones((9, 9)), but with lower computational cost. Most of the built-in footprints such asskimage2.morphology.disk()provide an option to automatically generate a footprint sequence of this type. Refer to the example Decompose flat footprints (structuring elements) for more insights.If
footprintcontains even-sized dimensions, they are padded with zeros to an odd size at the front (at index 0) withpad_footprint().Examples
>>> # Erosion shrinks bright regions >>> import numpy as np >>> from _skimage2.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))) array([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], dtype=uint8)