dilate函数

来源:互联网 发布:网络舆论的影响答案 编辑:程序博客网 时间:2024/05/29 14:07

dilate函数

函数的调用形式:
void dilate(InputArray src, OutputArray dst, InputArray kernel, Point anchor=Point(-1,-1), int iterations=1, intborderType=BORDER_CONSTANT, const Scalar& borderValue=morphologyDefaultBorderValue() )

函数参数的详解:

src:原图像。

dst:目标图像。

element:腐蚀操作的内核。 如果不指定,默认为一个简单的 bubuko.com,布布扣 矩阵。否则,我们就要明确指定它的形状,可以使用函数getStructuringElement().

anchor:默认为Point(-1,-1),内核中心点。省略时为默认值。

iterations:腐蚀次数。省略时为默认值1。

borderType:推断边缘类型,具体参见borderInterpolate函数。默认为BORDER_DEFAULT,省略时为默认值。

borderValue:边缘值,具体可参见createMorphoogyFilter函数。可省略。



函数的含义:
使用腐蚀操作中的核,对相应的像素进行相乘,取最大的乘积

The function dilates the source image using the specified structuring element that determines the shape of a pixel neighborhood over which the maximum is taken:

\texttt{dst} (x,y) =  \max _{(x',y'):  \, \texttt{element} (x',y') \ne0 } \texttt{src} (x+x',y+y')



opencv代码:

#include <opencv2/core/core.hpp>#include <opencv2/highgui/highgui.hpp>#include <opencv2/imgproc/imgproc.hpp>#include <iostream>using namespace std;using namespace cv;int main(){Mat img = imread("d:6.jpg");Mat dst(img.size(),8,1);cvtColor(img, img, CV_BGR2GRAY);threshold(img, img, 100, 255, CV_THRESH_BINARY);dilate(img, dst, NULL, Point(-1, -1), 10, BORDER_DEFAULT, Scalar(0, 0, 255));namedWindow("shiyan");imshow("shiyan", dst);waitKey(0);return 0;}
实验结果:

0 0