python-opencv(8):图像的腐蚀与膨胀

语法:

dst=cv2.erode(src,kernel,iterations) 
dst=cv2.dilate(src,kernel,iterations)

kernel:卷积核     kernel=np.ones((5,5),np.uint8)

程序示例:

import cv2
import numpy as np
img=cv2.imread("2.png",cv2.IMREAD_UNCHANGED)
k=np.ones((5,5),np.uint8)
result1=cv2.erode(img,k,5)
result2=cv2.dilate(img,k,5)
cv2.imshow("original",img)
cv2.imshow("result1",result1)
cv2.imshow("result2",result2)
cv2.waitKey()
cv2.destroyAllWindows()

结果:

python-opencv(8):图像的腐蚀与膨胀_第1张图片

你可能感兴趣的:(python-opencv)