【opencv一日一练】 GaussianBlur

来源:互联网 发布:铁拳7网络对战 编辑:程序博客网 时间:2024/05/01 09:52

GaussianBlur

Blurs an image using a Gaussian filter.

C++: void GaussianBlur(InputArray src, OutputArray dst, Size ksize, double sigmaX, double sigmaY=0,int borderType=BORDER_DEFAULT )

Parameters
              src – input image; the image can have any number of channels, which are processed independently,but the depth should be CV_8U, CV_16U, CV_16S, CV_32F or CV_64F.
              dst – output image of the same size and type as src.
              ksize – Gaussian kernel size. ksize.width and ksize.height can differ but they both must be positive and odd. Or, they can be zero’s and then they are computed from sigma* .
             sigmaX – Gaussian kernel standard deviation in X direction.
             sigmaY – Gaussian kernel standard deviation in Y direction; if sigmaY is zero, it is set to be equal to sigmaX, if both sigmas are zeros, they are computed from ksize.width and ksize.height , respectively (see getGaussianKernel() for details); to fully control the result regardless of possible future modifications of all this semantics, it is recommended to specify all of ksize, sigmaX, and sigmaY.
             borderType – pixel extrapolation method (see borderInterpolate() for details).

The function convolves the source image with the specified Gaussian kernel. In-place filtering is supported.


See Also:
sepFilter2D(), filter2D(), blur(), boxFilter(), bilateralFilter(), medianBlur()

 

///////////////////////////// -------  中文解释   ----------------------  ////////////////////////////////

 

GaussianBlur函数——高斯滤波

GaussianBlur函数的作用是用高斯滤波器来模糊一张图片,对输入的图像src进行高斯滤波后用dst输出。

函数原型如下:

 

参数详解如下:

  • 第一个参数,InputArray类型的src,输入图像,即源图像,填Mat类的对象即可。它可以是单独的任意通道数的图片,但需要注意,图片深度应该为CV_8U,CV_16U, CV_16S, CV_32F 以及 CV_64F之一。
  • 第二个参数,OutputArray类型的dst,即目标图像,需要和源图片有一样的尺寸和类型。比如可以用Mat::Clone,以源图片为模板,来初始化得到如假包换的目标图。
  • 第三个参数,Size类型的ksize高斯内核的大小。其中ksize.width和ksize.height可以不同,但他们都必须为正数和奇数。或者,它们可以是零的,它们都是由sigma计算而来。
  • 第四个参数,double类型的sigmaX,表示高斯核函数在X方向的的标准偏差。
  • 第五个参数,double类型的sigmaY,表示高斯核函数在Y方向的的标准偏差。若sigmaY为零,就将它设为sigmaX,如果sigmaX和sigmaY都是0,那么就由ksize.width和ksize.height计算出来。
  • 为了结果的正确性着想,最好是把第三个参数Size,第四个参数sigmaX和第五个参数sigmaY全部指定到。
  • 第六个参数,int类型的borderType,用于推断图像外部像素的某种边界模式。注意它有默认值BORDER_DEFAULT。

///////////////   -----------   示例代码  --------------   //////////////////////////////

<span style="font-size:18px;">imshow("src",src);GaussianBlur(src,dst,Size(7,7),0,0);imshow("dst - Size(7,7) - sigmaX=0 - sigmaY=0 ",dst);GaussianBlur(src,dst,Size(3,3),1.5,1.5);imshow("dst - Size(3,3) - sigmaX=1.5 - sigmaY=1.5 ",dst);</span>



效果:

 

0 0
原创粉丝点击