Image.open#

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

Morphological opening

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

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

Returns:

dilated image

Return type:

Image

Returns the image after morphological opening with the structuring element se applied as n erosions followed by n dilations.

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
>>> img = Image.Read("eg-morph1.png")
>>> img.print('{:1d}')
  00000000000000000000000000000000000000000000000000
  00000000000000000000000000000000000000000000000000
  00000000000000000000000000000000000000000000000000
  00000000000000000000000000000000000000000000000000
  00000000000000000000000000000000000000000000000000
  00000000000000000000000000000000000000001100000000
  00000000000000000000000000000000000000001100000000
  00000000000000000000000000000000000000001100000000
  00000000000000010000000000000000000000001100000000
  00000000000000010000000000000000000000001100000000
  00000000001111111111000000000000000000001100000000
  00000000001111111111000000000000000000001100000000
  00000000001111111111000001111100000000001100000000
  00000000001111111111000001111100000000001100000000
  00000000001111111111111111111100000000001100000000
  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
>>> img.open(np.ones((5,5))).print('{:1d}')
  00000000000000000000000000000000000000000000000000
  00000000000000000000000000000000000000000000000000
  00000000000000000000000000000000000000000000000000
  00000000000000000000000000000000000000000000000000
  00000000000000000000000000000000000000000000000000
  00000000000000000000000000000000000000000000000000
  00000000000000000000000000000000000000000000000000
  00000000000000000000000000000000000000000000000000
  00000000000000000000000000000000000000000000000000
  00000000000000000000000000000000000000000000000000
  00000000001111111111000000000000000000000000000000
  00000000001111111111000000000000000000000000000000
  00000000001111111111000001111100000000000000000000
  00000000001111111111000001111100000000000000000000
  00000000001111111111000001111100000000000000000000
  00000000001111111111000001111100000000000000000000
  00000000001111111111000001111100000000000000000000
  00000000001111111111000000000000000000000000000000
  00000000001111111111000000000000000000000000000000
  00000000001111111111000000000000000000000000000000
  00000000000000000000000000000000000000000000000000
  00000000000000000000000000000000000000000000000000
  00000000000000000000000000000000000000000000000000
  00000000000000000000000000000000000000000000000000
  00000000000000000000000000000000000000000000000000
  00000000000000000000000000000000000000000000000000
  00000000000000000000000000000000000000000000000000
  00000000000000000000000000000000000000000000000000
  00000000000000000000000000000000000000000000000000
  00000000000000000000000000000000000000000000000000
  00000000000000000000000000000000000000000000000000
  00000000000000000000000000000000000000000000000000
  00000000000000000000000000000000000000000000000000
  00000000000000000000000000000000000000000000000000
  00000000000000000000000000000000000000000000000000
  00000000000000000000000000000000000000000000000000
  00000000000000000000000000000000000000000000000000
  00000000000000000000000000000000000000000000000000
  00000000000000000000000000000000000000000000000000
  00000000000000000000000000000000000000000000000000

Note

  • For binary image an opening operation can be used to eliminate small white noise regions.

  • 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.

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.morphologyEx which accepts multiple-channel, CV_8U, CV_16U, CV_16S, CV_32F or CV_64F images.

Seealso:

close morph erode dilate opencv.morphologyEx