Other morphological operators

Here are some other morphological operators that are interesting. Let's first take a look at the output image. We can take a look at the code at the end of this section.

Morphological opening

This is an operation that opens a shape. This operator is frequently used for noise removal in an image. We can achieve morphological opening by applying erosion followed by dilation to an image. The morphological opening process basically removes small objects from the foreground in the image by placing them in the background:

Morphological opening

Here is the function to the perform morphological opening:

Mat performOpening(Mat inputImage, int morphologyElement, ...

Get OpenCV By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.