To implement Erosion and Dilation using Python and OpenCV.
- Anaconda - Python 3.7
- OpenCV
Import the necessary packages.
Create the Text using cv2.putText
Create the structuring element.
Erode the image.
Dilate the image.
/*
Developed by : DHANASEKAR.G
Register Number: 212220230009
*/
# Import the necessary packages
import cv2
import numpy as np
import matplotlib.pyplot as plt
# Create the Text using cv2.putText
img1=np.zeros((300,700),dtype='uint8')
font=cv2.FONT_ITALIC=3
img2=cv2.putText(img1,"DHANS",(5,70),font,3,(255),5,cv2.LINE_AA)
cv2.imshow("Original",img2)
cv2.waitKey(0)
cv2.destroyAllWindows()
# Create the structuring element
kernel=np.ones((5,5),np.uint8)
kernal1=cv2.getStructuringElement(cv2.MORPH_CROSS,(7,7))
# Erode the image
erode=cv2.erode(img2,kernel)
cv2.imshow("Erosion1",erode)
cv2.waitKey(0)
cv2.destroyAllWindows()
# Dilate the image
dilute=cv2.dilate(img2,kernel1)
cv2.imshow("Dilution",dilute)
cv2.waitKey(0)
cv2.destroyAllWindows()
Thus the generated text image is eroded and dilated using python and OpenCV.