import cv2
import numpy as np
import matplotlib.pyplot as plt
img = cv2.imread(r"C:\Users\Curry\Desktop\cc.png")
kernel = np.ones(shape=[10,10],dtype=np.uint8)
img = 255-img #黑变白,白变黑
# print(img.shape)
# 腐蚀,有多变少,边界容易被腐蚀,去除噪声
img2 = cv2.erode(img,kernel=kernel,iterations=1)
# 膨胀,变粗,变宽
img3 = cv2.dilate(img2, kernel, iterations=1)
plt.subplot(2,2,1)
plt.title('img')
plt.imshow(img)
plt.subplot(2,2,2)
plt.title('erode')
plt.imshow(img2)
plt.subplot(2,2,3)
plt.title('dilate')
plt.imshow(img3)
plt.show()