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 and Dilate the image.
End Program.
Developed By : Shafeeq Ahamed. S
Register Number: 212221230092
import cv2
import numpy as np
from matplotlib import pyplot as plt
img1 = np.zeros((100,550), dtype = 'uint8')
font = cv2.FONT_HERSHEY_SIMPLEX
cv2.putText(img1,'Shafeeq Ahamed',(5,70), font, 2,(255),5,cv2.LINE_AA)
plt.imshow(img1,'gray')
kernel = cv2.getStructuringElement(cv2.MORPH_CROSS,(7,7))
cv2.erode(img1, kernel)
image_erode1 = cv2.erode(img1,kernel)
plt.imshow(image_erode1, 'gray')
image_dilate1 = cv2.dilate(img1, kernel)
plt.imshow(image_dilate1, 'gray')
Thus the generated text image is eroded and dilated using python and OpenCV.