我就废话不多说了,大家还是直接看代码吧~ #coding=utf-8 import cv2 import numpy as np img=cv2.imread('timg.jpeg',cv2.CV_LOAD_IMAGE_GRAYSCALE) #创建矩形结构单元 g=cv2.getStructuringElement(cv2.MORPH_RECT,(9,9)) #形态学处理,开运算 img_open=cv2.morphologyEx(img,cv2.MORPH_OPEN,g) img_hat=img-img_open cv2.imshow('img',img) #cv2.imshow('ero