Erosion
Mat performErosion(Mat inputImage, int erosionElement, int erosionSize)
{
Mat outputImage;
int erosionType;
if(erosionElement == 0)
erosionType = MORPH\_RECT;
else if(erosionElement == 1)
erosionType = MORPH\_CROSS;
else if(erosionElement == 2)
erosionType = MORPH\_ELLIPSE;
// Create the structuring element for erosion
Mat element = getStructuringElement(erosionType, Size(2\*erosionSize + 1, 2\*erosionSize + 1), Point(erosionSize, erosionSize));
// Erode the image using the structuring element
erode(inputImage, outputImage, element);
// Return the output image
return outputImage;
}
Dilation
Mat performDilation(Mat inputImage, int dilationElement, int dilationSize)
{
Mat outputImage;
int dilationType;
if(dilationElement == 0)
dilationType = MORPH\_RECT;
else if(dilationElement == 1)
dilationType = MORPH\_CROSS;
else if(dilationElement == 2)
dilationType = MORPH\_ELLIPSE;
// Create the structuring element for dilation
Mat element = getStructuringElement(dilationType, Size(2\*dilationSize + 1, 2\*dilationSize + 1), Point(dilationSize, dilationSize));
// Dilate the image using the structuring element
dilate(inputImage, outputImage, element);
// Return the output image
return outputImage;
}