Opening | Morphological Transformations in OpenCV in C++
In this article, a Morphological operation called Opening is discussed.
Opening operation is similar to erosion in the sense that it also removes foreground pixels from the edges of the image. Opening operation is erosion operation followed by dilation. It is usually used for removing internal noise present inside an image. This operator safeguards the foreground region that has similarity with the structuring component or the one that fits inside the structuring element while removing everything else.
morphologyEx (src, dst, op, kernel, anchor, iterations, borderType, borderValue)
- src: It is the input image.
- dst: It is the output image.
- op: Type of morphological operation.
- kernel: Structuring element used for Closing.
- anchor: Anchor position inside the structuring element. The default value is [-1, -1} signifying position as the center of the structuring element.
- iterations: Number of times Closing is applied.
- borderType: Type of border ( BORDER_CONSTANT, BORDER_REPLICATE, etc.)
- borderValue: Border value
- Return: Output Image (Mat Object)
The opening operator is given by the expression:
The expression represents that AoB is a subset (sub-image of A). The opening operator removes internal noise and thin protrusions present inside an image.
Below is the C++ program to demonstrate the Opening Morphological Operation: