一、膨胀:dilate函数
1 void dilate( InputArray src, OutputArray dst, InputArray kernel, 2 Point anchor = Point(-1,-1), int iterations = 1, 3 int borderType = BORDER_CONSTANT, 4 const Scalar& borderValue = morphologyDefaultBorderValue() );
1 int main() 2 { 3 //载入原图 4 Mat image = imread("C:\Users\Nelsoner\Desktop\Camera Roll\05.jpg"); 5 6 //创建窗口 7 namedWindow("【原图】"); 8 namedWindow("【膨胀效果图】"); 9 10 imshow("【原图】", image); 11 12 //获取自定义核 13 Mat element = getStructuringElement(MORPH_RECT, Size(15, 15)); 14 Mat out; 15 //进行膨胀操作 16 dilate(image, out, element); 17 18 //显示效果图 19 imshow("【膨胀效果图】", out); 20 21 waitKey(); 22 return 0; 23 }
原图:
效果图:
二、腐蚀:erode函数
1 void erode( InputArray src, OutputArray dst, InputArray kernel, 2 Point anchor = Point(-1,-1), int iterations = 1, 3 int borderType = BORDER_CONSTANT, 4 const Scalar& borderValue = morphologyDefaultBorderValue() );
参数和膨胀相同,代码也几乎相同
效果图: