To implement Erosion and Dilation using Python and OpenCV.
- Anaconda - Python 3.7
- OpenCV
Import the necessary packages.
Create the text image.
Create the structuring image for dilation/erosion.
Apply erosion and dilation using cv2.erode and cv2.dilate.
Display the images.
Developer Name : NITHISHWAR S
Register number : 212221230071
import numpy as np
import cv2
import matplotlib.pyplot as plt
img1=np.zeros((100,300),dtype= 'uint8')
font=cv2.FONT_HERSHEY_SIMPLEX
cv2.putText(img1,'NITHISHWAR',(5,70),font,1.4,(355),5,cv2.LINE_AA)
plt.imshow(img1,cmap='gray')
plt.title("Original Image")
plt.axis('off')
# Create the structuring element
kernel = cv2.getStructuringElement(cv2.MORPH_CROSS,(7,7))
# Erode the image
image_erode = cv2.erode(img1,kernel)
plt.title("Eroded Image")
plt.imshow(image_erode,cmap='gray')
plt.axis('off')
# Dilate the image
image_dilate = cv2.dilate(img1,kernel)
plt.title("Dilated Image")
plt.imshow(image_dilate,cmap='gray')
plt.axis('off')
Thus the generated text image is eroded and dilated using python and OpenCV.