machinevisiontoolbox.Image.erode

Image.erode(se, n=1, border='replicate', bordervalue=0, **kwargs)

Morphological erosion

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

  • n (int, optional) – number of times to apply the erosion, 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.erode

Returns:

eroded image

Return type:

Image

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

Example:

>>> from machinevisiontoolbox import Image
>>> import numpy as np
>>> img = Image.Squares(1,7)
>>> img.print()
 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 0
 0 0 0 0 0 0 0
>>> img.erode(np.ones((3,3))).print()
 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 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 structuing 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 this is the maximum value over the structuring element.

References:
  • Robotics, Vision & Control for Python, Section 11.6, P. Corke, Springer 2023.

Seealso:

dilate opencv.erode