# 梯度=膨胀-腐蚀
pie_t = cv2.imread("pie.png")
kernel_t = np.ones((5,5),np.uint8)
digete_t = cv2.dilate(pie_t,kernel_t,iterations=5)
erosion_t = cv2.erode(pie_t,kernel_t,iterations=5)
res_t = np.hstack((digete_t,erosion_t))
cv2.imshow("res_t",res_t)
cv2.waitKey(0)
cv2.destroyAllWindows()
gradient = cv2.morphologyEx(pie_t,cv2.MORPH_GRADIENT,kernel_t)
cv2.imshow("gradient",gradient)
cv2.waitKey(0)
cv2.destroyAllWindows()
礼帽与黑帽
#礼帽=原始输入-开运算结果
img_lm = cv2.imread("dige.png")
kernel_m = np.ones((5,5),np.uint8)
tophat = cv2.morphologyEx(img_lm,cv2.MORPH_TOPHAT,kernel_m)
cv2.imshow("tophat",tophat)
cv2.waitKey(0)
cv2.destroyAllWindows()
#黑帽=闭运算-原始输入
img_hm = cv2.imread("dige.png")
kernel_m = np.ones((5,5),np.uint8)
blackhat = cv2.morphologyEx(img_hm,cv2.MORPH_BLACKHAT,kernel_m)
cv2.imshow("blackhat",blackhat)
cv2.waitKey(0)
cv2.destroyAllWindows()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)