Other morphological operators
Here are some other interesting morphological operators. Let's look at the output image first. We can look at the code at the end of this section.
Morphological opening
This is the operation that opens a shape. This operator is frequently used for noise removal in images. It's basically erosion followed by dilation. Morphological opening removes small objects from the foreground in the image by placing them in the background:
Here is the function to perform morphological opening:
Mat performOpening(Mat inputImage, int morphologyElement, int morphologySize) { Mat outputImage, tempImage; int morphologyType; if(morphologyElement == 0) morphologyType = MORPH_RECT; else if(morphologyElement == 1) morphologyType = MORPH_CROSS; else if(morphologyElement == 2) morphologyType = MORPH_ELLIPSE; // Create the structuring element for erosion Mat element = getStructuringElement(morphologyType, Size(2*morphologySize + 1, 2...