machinevisiontoolbox.Image.close
- Image.close(se, n=1, border='replicate', bordervalue=0, **kwargs)
Morphological closing
- Parameters:
se (ndarray(N,M)) – structuring element
n (int, optional) – number of times to apply the dilation then erosion, defauts 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.morphologyEx
- Returns:
dilated image
- Return type:
Image
Returns the image after morphological opening with the structuring element
se
applied asn
dilations followed byn
erosions.Example:
>>> from machinevisiontoolbox import Image >>> import numpy as np >>> img = Image.Read("eg-morph2.png") >>> img.print('{:1d}') 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000001100000000 00000000000000000000000000000000000000001100000000 00000000000000000000000000000000000000001100000000 00000000000000010000000000000000000000001100000000 00000000000000010000000000000000000000001100000000 00000000001111111111000000000000000000001100000000 00000000001111111111000000000000000000001100000000 00000000001111111111000001111100000000001100000000 00000000001111111111000001111100000000001100000000 00000000001111001111000001111100000000001100000000 00000000111111001111000001111100000000001100000000 00000000001111111111000001111100000000001100000000 00000000001111111111000000000000000000001100000000 00000000001111111111000000000000000000001100000000 00000000001111111111000000000000000000001100000000 00000000000000000000000000000000000000001100000000 00000000000000000000000000000000000000001100000000 00000000000000000000000000000000000000001100000000 00000000000000000000000000000000000000001100000000 00000000000000000000000000000000000000001100000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000111111111111111111110000000000000000000000000 00000111111111111111111110000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 >>> img.close(np.ones((5,5))).print('{:1d}') 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000001100000000 00000000000000000000000000000000000000001100000000 00000000000000000000000000000000000000001100000000 00000000000000010000000000000000000000001100000000 00000000000000010000000000000000000000001100000000 00000000001111111111000000000000000000001100000000 00000000001111111111000000000000000000001100000000 00000000001111111111000001111100000000001100000000 00000000001111111111000001111100000000001100000000 00000000001111111111000001111100000000001100000000 00000000111111111111000001111100000000001100000000 00000000001111111111000001111100000000001100000000 00000000001111111111000000000000000000001100000000 00000000001111111111000000000000000000001100000000 00000000001111111111000000000000000000001100000000 00000000000000000000000000000000000000001100000000 00000000000000000000000000000000000000001100000000 00000000000000000000000000000000000000001100000000 00000000000000000000000000000000000000001100000000 00000000000000000000000000000000000000001100000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000111111111111111111110000000000000000000000000 00000111111111111111111110000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000
- Note:
For binary image a closing operation can be used to eliminate joins between regions.
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.
- References:
Robotics, Vision & Control for Python, Section 11.6, P. Corke, Springer 2023.
- Seealso: