一、引入
腐蚀操作也是用卷积核扫描图像,只不过腐蚀操作的卷积核一般都是1(卷积核内的每个数字都为1) ,如果卷积核内所有像素点都是白色,那么**锚点(中心点)**即为白色。

大部分时候腐蚀操作使用的都是全为1的卷积核。

二、代码演示
在OpenCV中使用API---erode(src, kernel[, dst[, anchor[, iterations[, borderType[, borderValue]]]])
其中,iterations是腐蚀操作的迭代次数,次数越多,腐蚀操作执行的次数越多,腐蚀效果越明显。
示例代码如下:
import cv2
import numpy as np
img = cv2.imread("mashibing.png")
kernel = np.ones((3, 3),np.uint8)
new_img = cv2.erode(img, kernel, iterations=3)
cv2.imshow("img", np.hstack((img, new_img)))
cv2.waitKey(0)
cv2.destroyAllWindows()
输出结果如下:
