一、膨胀
dilate函数使用像素邻域内的局部极大运算符来膨胀一张图片。
void dilate(InputArray src,OutputArray dst,InputArray kernel,Point anchor=Point(-1,-1),ini iterations=1.int borderType=BORDER_CONSTANT,const Scalar &borderValue=morphologyDefaultBorderValue());
src | 输入图像 |
dst | 目标图像 |
kernel | 膨胀操作的核。当为NULL时,表示的是使用参考点位于中心3*3的核、一般使用getStructuringElement配合 |
anchor | 锚的位置,其有默认值(-1,-1),表示锚位于中心 |
iterations | 迭代使用erode()函数的次数 |
borderType | 默认值 |
borderValue | 默认值 |
一般只需填前面的三个参数,后面四个参数都有默认值。调用范例:
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include<iostream>
using namespace cv;
int main()
{
Mat image = imread("F:\\C++project\\picturetest\\2.jpg");
namedWindow("膨胀(原图)");
namedWindow("膨胀(效果图)");
imshow("膨胀(原图)", image);
Mat element = getStructuringElement(MORPH_RECT, Size(15, 15));
Mat out;
dilate(image, out, element);
imshow("膨胀(效果图)", out);
waitKey(0);
return 0;
}
二、腐蚀
erode函数使用像素邻域内的局部极小运算符来腐蚀一张图片。
void erode(InputArray src,OutputArray dst,InputArray kernel,Point anchor=Point(-1,-1),ini iterations=1.int borderType=BORDER_CONSTANT,const Scalar &borderValue=morphologyDefaultBorderValue());
src | 输入图像 |
dst | 目标图像 |
kernel | 腐蚀操作的核。当为NULL时,表示的是使用参考点位于中心3*3的核、一般使用getStructuringElement配合 |
anchor | 锚的位置,其有默认值(-1,-1),表示锚位于中心 |
iterations | 迭代使用erode()函数的次数 |
borderType | 默认值 |
borderValue | 默认值 |
Mat element = getStructuringElement(MORPH_RECT, Size(15, 15));
Mat out;
erode(image, out, element);