bundles / scipy latest / scipy / ndimage / _morphology / grey_dilation
function
scipy.ndimage._morphology:grey_dilation
Signature
def grey_dilation ( input , size = None , footprint = None , structure = None , output = None , mode = reflect , cval = 0.0 , origin = 0 , * , axes = None ) Summary
Calculate a greyscale dilation, using either a structuring element, or a footprint corresponding to a flat structuring element.
Extended Summary
Grayscale dilation is a mathematical morphology operation. For the simple case of a full and flat structuring element, it can be viewed as a maximum filter over a sliding window.
Parameters
input: array_likeArray over which the grayscale dilation is to be computed.
size: tuple of intsShape of a flat and full structuring element used for the grayscale dilation. Optional if
footprintorstructureis provided.footprint: array of ints, optionalPositions of non-infinite elements of a flat structuring element used for the grayscale dilation. Non-zero values give the set of neighbors of the center over which the maximum is chosen.
structure: array of ints, optionalStructuring element used for the grayscale dilation.
structuremay be a non-flat structuring element. Thestructurearray applies an additive offset for each pixel in the neighborhood.output: array, optionalAn array used for storing the output of the dilation may be provided.
mode: {'reflect','constant','nearest','mirror', 'wrap'}, optionalThe
modeparameter determines how the array borders are handled, wherecvalis the value when mode is equal to 'constant'. Default is 'reflect'cval: scalar, optionalValue to fill past edges of input if
modeis 'constant'. Default is 0.0.origin: scalar, optionalThe
originparameter controls the placement of the filter. Default 0axes: 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
grey_dilation: ndarrayGrayscale dilation of
input.
Notes
The grayscale dilation of an image input by a structuring element s defined over a domain E is given by:
(input+s)(x) = max {input(y) + s(x-y), for y in E}
In particular, for structuring elements defined as s(y) = 0 for y in E, the grayscale dilation computes the maximum of the input image inside a sliding window defined by E.
Grayscale dilation [1] is a mathematical morphology operation [2].
Array API Standard Support
grey_dilation 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((7,7), dtype=int) a[2:5, 2:5] = 1 a[4,4] = 2; a[2,3] = 3 a ndimage.grey_dilation(a, size=(3,3)) ndimage.grey_dilation(a, footprint=np.ones((3,3))) s = ndimage.generate_binary_structure(2,1)✓
s
✗ndimage.grey_dilation(a, footprint=s) ndimage.grey_dilation(a, size=(3,3), structure=np.ones((3,3)))✓
See also
Aliases
-
scipy.ndimage.grey_dilation