Image.dilate#

Image.dilate(se: ndarray | list, n: int = 1, border: str = 'replicate', bordervalue: float = 0, **kwargs: Any) Self[source]#

Morphological dilation

Parameters:
  • se (ndarray(N,M)) – structuring element

  • n (int, optional) – number of times to apply the dilation, defaults to 1

  • border (str, optional) – option for boundary handling, see convolve, defaults to ‘replicate’

  • bordervalue (scalar, optional) – padding value, defaults to 0

  • kwargs – addition options passed to opencv.dilate

Returns:

dilated image

Return type:

Image

Returns the image after morphological dilation with the structuring element se applied n times.

The image can be of any type and boolean images where True is treated as 1 and False as 0. The structuring element should be a 2D array of non-negative integers, where non-zero values indicate the shape of the structuring element.

Example:

>>> from machinevisiontoolbox import Image
>>> import numpy as np
>>> pixels = np.zeros((7,7), dtype='uint8'); pixels[3,3] = 1
>>> img = Image(pixels)
>>> img.print()
   0 0 0 0 0 0 0
   0 0 0 0 0 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 0 0 0 0 0
   0 0 0 0 0 0 0
>>> img.dilate(np.ones((3,3))).print()
   0 0 0 0 0 0 0
   0 0 0 0 0 0 0
   0 0 1 1 1 0 0
   0 0 1 1 1 0 0
   0 0 1 1 1 0 0
   0 0 0 0 0 0 0
   0 0 0 0 0 0 0

Note

  • It is cheaper to apply a smaller structuring element multiple times than one large one, the effective structuring element is the Minkowski sum of the structuring element with itself N times.

  • The structuring element typically has odd side lengths.

  • For a greyscale image dilation is the minimum value over the structuring element.

Warning

treats NaNs in input image as standard IEEE-754 floating-point values, meaning any morphological operation involving a NaN results in NaN. A single NaN within the structuring element’s window propagates to make the output pixel NaN. Use fixbad for handling NaN values.

References:

Important

Uses OpenCV function cv2.dilate which accepts multiple-channel, CV_8U, CV_16U, CV_16S, CV_32F or CV_64F images.

Seealso:

erode morph open close opencv.dilate