Javatpoint Logo
Javatpoint Logo

Morphological Operations in Image Processing in Python

Morphological operations can be used for extracting image components that are helpful for the description and representation of the shape of a region. Morphological operations are the fundamental tasks that are dependent on the image shape. It typically takes place on binary images. It requires two sources of data, the first of which is an input image, and the second is known as the structuring component.

Morphological operators are able to take an input image as well as the structuring component as input. The two elements are then combined with set operators. The objects of the image input are treated based on the characteristics of the shape of the image. These can be encoded by the structuring part.

The Opening is similar to erosion, as it removes bright foreground pixels from the edges of the foreground pixels. The result of this operation is to secure the foreground region, which is similar to the structuring component or even completely contains the structuring component while taking away all other regions in the foreground of pixels. The opening operation is utilized for the removal of internal noise within an image.

The Opening is an erosion operation that is followed by dilation.

Morphological Operations in Image Processing in Python

Required modules and libraries:

To perform the morphological operation in the image processing, we will need the following module:

1. cv2

Install: !pip3 install cv2

2. NumPy

Install: !pip3 install numpy

Syntax:

Syntax of cv2morphology is:

Parameters:

  • image: It takes input Image array.
  • MORPH_OPEN: It is used for applying the Morphological Opening operation.
  • kernel: It is used for structuring element.

Here below is the Python code for explaining Opening Morphological Operation -

Code:

Output

Input image

Morphological Operations in Image Processing in Python

Mask:

Morphological Operations in Image Processing in Python

Output Frame

Morphological Operations in Image Processing in Python

The system recognizes the designated blue book as the input and removes and eliminates the noise inside the area of interest with the aid of the Opening function.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA