上篇博客写了膨胀和腐蚀能满足基本的图像处理,但是在处理灰度图或者彩色图时,需要额外的操作,这就用到函数cv2.morphologyEx()。
定义
opencv手册上给出的函数定义为:
dst = cv.morphologyEx( src, op, kernel[, dst[, anchor[, iterations[, borderType[, borderValue]]]]] )
src Source image. The number of channels can be arbitrary. The depth should be one of CV_8U, CV_16U, CV_16S, CV_32F or CV_64F.
dst Destination image of the same size and type as source image.
cv.MORPH_ERODE 腐蚀
cv.MORPH_DILATE 膨胀
cv.MORPH_OPEN 开运算 (先腐蚀在膨胀)
dst=open(src,element)=dilate(erode(src,element))
cv.MORPH_CLOSE 闭运算 (先膨胀在腐蚀)
dst=close(src,element)=erode(dilate(src,element))
cv.MORPH_GRADIENT 形态学梯度
dst=morph_grad(src,element)=dilate(src,element)−erode(src,element)
cv.MORPH_TOPHAT 礼帽
dst=tophat(src,elemen