对图像矩阵非0值区域操作
kernel = cv.getStructuringElement(shape,
ksize
[,anchor])
获取常用结构元素
shape可选标志:cv.MORPG_RECT、cv.MORPG_CROSS、cv.MORPG_ELLIPSE
简记【0,1,2】,矩形、十字、竖着的椭圆
ksize【一维 】:如(3,3)、(5,5) 取奇数即可,可以不同
anchor默认为图像中心 (-1,-1)
dst = cv.erode(src,
kernel,
[,dst]
[,anchor]
[,iterations]
[,borderType]
[,borderValue])
图像腐蚀
iterations 迭代次数 (操作重复次数)
borderType 像素边界外推法的标志
borderValue 不变的边界值 【?】
dst = cv.dilate(src,
kernel,
[,dst]
[,anchor]
[,iterations]
[,borderType]
[,borderValue])
图像膨胀
dst = cv.morphologyEx(src,
op,
kernel,
[,dst]
[,anchor]
[,iterations]
[,borderType]
[,borderValue])
图像形态学操作
op可选标志
开运算,先腐蚀后膨胀,可消去主区域外部噪声、部分毛刺
闭运算,先膨胀后腐蚀,可消去主区域内部小洞,连接模糊边缘
梯度运算,膨胀减去腐蚀,可获得边线
顶帽运算,原图减去开运算
黑帽运算,闭运算减去原图
击中击不中,使用特定的结构元素,仅当原图区域完全符合结构元素时,anchor位置才为非零值,否则被腐蚀
dst = cv.ximgproc.thinning(src,
[,dst]
[,thinningType])
图像细化(骨架化)
thinningType可选标志
cv.THINNING_ZHANGSUEN 【0】
cv.THINNING_GUOHALL 【1】