To implement Erosion and Dilation using Python and OpenCV.
- Anaconda - Python 3.7
- OpenCV
Import the necessary packages.
Create the text image using cv2.putText.
Then create the structuring image for dilation/erosion.
Apply erosion and dilation using plt.erode and plt.dilate.
Plot the images using plt.imshow.
Developed By:RASIKA.M
Register Number:212222230117
# Import the necessary packages
import numpy as np
import cv2
import matplotlib.pyplot as plt
# Create the Text using cv2.putText
image = np.zeros((100,500),dtype = 'uint8')
font = cv2.FONT_HERSHEY_SIMPLEX
cv2.putText(image,"RASIKA",(5,70),font,2,(255),5,cv2.LINE_AA)
plt.imshow(image,cmap='gray')
plt.title('Input Text'), plt.xticks([]), plt.yticks([])
plt.show()
# Create the structuring element
kernel=cv2.getStructuringElement(cv2.MORPH_CROSS,(7,7))
# Erode the image
image_erode=cv2.erode(image,kernel)
plt.imshow(image_erode,cmap='gray')
plt.title('Eroded Text'), plt.xticks([]), plt.yticks([])
plt.show()
# Dilate the image
image_dilate=cv2.dilate(image,kernel)
plt.imshow(image_dilate,cmap='gray')
plt.title('Dilated Text'), plt.xticks([]), plt.yticks([])
plt.show()
Thus the generated text image is eroded and dilated using python and OpenCV.