Python-openCV腐蚀膨胀

#coding=utf-8
import numpy as np
import cv2
'''腐蚀操作'''
img=cv2.imread('timg.jpeg',cv2.CV_LOAD_IMAGE_COLOR)
#创建矩形结构单元
g=cv2.getStructuringElement(cv2.MORPH_RECT,(5,7))
#腐蚀图像,迭代次数采用默认1
img_erode=cv2.erode(img,g)
#边界提取
edge_erode=img-img_erode

#膨胀操作
img_dilate=cv2.dilate(img,g)
edge_dilate=img_dilate-img

edge=img_dilate-img_erode

cv2.imshow('timg.jpeg',img)
#cv2.imshow('erode',edge_dilate)
cv2.imshow('edge',edge)
cv2.waitKey(0)
cv2.destroyAllWindows()


你可能感兴趣的:(Python)