import cv2
import numpy as np
img = cv2.imread('pic7.PNG', 0)
img1 = cv2.imread('pic8.PNG', 0)
img2 = cv2.imread('pic9.PNG', 0)
kernel = np.ones((5, 5), np.uint8)
# 腐蚀
erosion = cv2.erode(img, kernel, iterations=1)
# 膨胀
dilation = cv2.dilate(img, kernel, iterations=1)
# 开运算
opening = cv2.morphologyEx(img1, cv2.MORPH_OPEN, kernel)
# 闭运算
closing = cv2.morphologyEx(img2, cv2.MORPH_CLOSE, kernel)
# 形态学梯度
gradient = cv2.morphologyEx(img, cv2.MORPH_GRADIENT, kernel)
# 礼帽
tophat = cv2.morphologyEx(img, cv2.MORPH_TOPHAT, kernel)
# 黑帽
blackhat = cv2.morphologyEx(img, cv2.MORPH_BLACKHAT, kernel)
cv2.imshow('img', img)
cv2.imshow('erosion', erosion)
cv2.imshow('dilation', dilation)
cv2.imshow('gradient', gradient)
cv2.imshow('tophat', tophat)
cv2.imshow('blackhat', blackhat)
cv2.imshow('opening', opening)
cv2.imshow('closing', closing)
cv2.waitKey(0)
cv2.destroyAllWindows()
Python 16.OpenCV 腐蚀,膨胀,开运算, 闭运算,礼帽,黑帽
最新推荐文章于 2023-08-08 23:48:59 发布