腐蚀
dst=cv2.erode(src, kernel, dst=…, anchor=…,iterations=…, borderType=…, borderValue=…)
- src:原始图像,通道数任意,但是图像深度必须是 CV_8U,CV_16U,CV_16S,CV_16S,CV_32F,CV_64F。
- kernel:腐蚀操作采用的结构类型。
- anchor:锚点的位置。默认为(-1,-1),在核的中心位置。
- iterations:腐蚀操作的次数。
- borderType:边界样式。
下面是腐蚀操作的代码和操作后的图像对比。
例中erode
因为我只需要src
,kernel
,所以其他值为默认值。
能看到图二的边框有着明显的改变,通过改变kernel
,iterations
可以产生不一样的效果。
膨胀
dst= cv2.dilate: (src, kernel, dst=…, anchor=…, iterations=…, borderType=…, borderValue=…)
膨胀除了element
与腐蚀不同,其余都与腐蚀相同。
- element:膨胀操作采用的结构类型。
下面是膨胀操作的代码和操作后的图像对比。
能看到经过膨胀操作,图像边缘发生了变化,效果和腐蚀操作正好相反。