import cv2
import numpy as np


img = cv2.imread('img\\ttt.jpg')

#定义结构元素
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3))

#腐蚀图像
eroded = cv2.erode(img, kernel)
cv2.imshow("fs_eroded", eroded)

#膨胀图像
dilated = cv2.dilate(img, kernel)
cv2.imshow("pz_dilated", dilated)

#NumPy定义的结构元素
NpKernel = np.uint8(np.ones((3,3)))
Nperoded = cv2.erode(img, NpKernel)
#显示腐蚀后的图像
cv2.imshow("Eroded by NumPy kernel", Nperoded)







cv2.waitKey(0)
cv2.destroyAllWindows()
