图像处理之平滑处理

在Opencv1.0中用于平滑处理的是:

  void cvSmooth(const CvArr* src,    CvArr*  dst,    int smoothtype = CV_GAUSSIAN,  int param1 = 3, int param2 = 0, int param3 = 0, int param4 = 0);

 

smoothtype 各种类型是:

1、 CV_BLUR:简单模糊, 在以后高级版本中是:

C++: void blur(InputArray src, OutputArray dst, Size ksize, Point anchor=Point(-1,-1), int borderType=BORDER_DEFAULT );

 

Parameters:
  • src – Source image.
  • dst – Destination image of the same size and type as  src .
  • ksize – Smoothing kernel size.
  • anchor – Anchor point. The default value  Point(-1,-1)  means that the anchor is at the kernel center.
  • borderType – Border mode used to extrapolate pixels outside of the image

 

The function smoothes an image using the kernel:

\texttt{K} =  \frac{1}{\texttt{ksize.width*ksize.height}} \begin{bmatrix} 1 & 1 & 1 &  \cdots & 1 & 1  \\ 1 & 1 & 1 &  \cdots & 1 & 1  \\ \hdotsfor{6} \\ 1 & 1 & 1 &  \cdots & 1 & 1  \\ \end{bmatrix}

The call blur(src, dst, ksize, anchor, borderType) is equivalent to boxFilter(src, dst, src.type(), anchor, true, borderType) .

 

    其输出图像的每个像素是输入图像对应像素的简单平均。

 2、CV_BLUR_NO_SCALE: 简单无缩放变换的模糊

     它与 simple blur本质上是相同的,但并没有计算其平均值的造作, 不支持in place 方式:输入图像与输出图像必须不同(还没看懂)

 3、CV_MEDIAN:中值滤波器

 C++: void medianBlur(InputArray src, OutputArray dst, int ksize);

 

Parameters:
  • src – Source 1-, 3-, or 4-channel image. When  ksize  is 3 or 5, the image depth should be  CV_8UCV_16U ,  or  CV_32F . For larger aperture sizes, it can only be  CV_8U .
  • dst – Destination array of the same size and type as  src .
  • ksize – Aperture linear size. It must be odd and greater than 1, for example: 3, 5, 7 ...

The function smoothes an image using the median filter with the\texttt{ksize} \times \texttt{ksize} aperture. Each channel of a multi-channel image is processed independently. In-place operation is supported.

   中值滤波器将中心像素的正方形邻域内的每个像素值用中间像素值替换。 简单模糊对噪声图像特别是有大的孤立点的图像非常敏感,即使有极少数量点存在较大差异也会导致平均值的明显波动,中值滤波可以选择中间值避免这些点的影响。

4、CV_GAUSSIAN:高斯滤波器

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

 

Parameters:
  • src – Source image.
  • dst – Destination 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.

  高斯滤波用卷积核与输入图像的每个点进行卷积,将最终计算结果之和作为输出图像的像素值。

5、CV_BILATERAL:双边滤波

    C++: void bilateralFilter(InputArray src, OutputArray dst, int d, double sigmaColor, double sigmaSpace, int borderType=BORDER_DEFAULT );

 

Parameters:
  • src – Source 8-bit or floating-point, 1-channel or 3-channel image.
  • dst – Destination image of the same size and type as  src .
  • d – Diameter of each pixel neighborhood that is used during filtering. If it is non-positive, it is computed from  sigmaSpace .
  • sigmaColor – Filter sigma in the color space. A larger value of the parameter means that farther colors within the pixel neighborhood (see  sigmaSpace ) will be mixed together, resulting in larger areas of semi-equal color.
  • sigmaSpace – Filter sigma in the coordinate space. A larger value of the parameter means that farther pixels will influence each other as long as their colors are close enough (see  sigmaColor ). When  d>0 , it specifies the neighborhood size regardless of  sigmaSpace . Otherwise,  d  is proportional to  sigmaSpace .

This filter does not work inplace.

Sigma values: For simplicity, you can set the 2 sigma values to be the same. If they are small (< 10), the filter will not have much effect, whereas if they are large (> 150), they will have a very strong effect, making the image look “cartoonish”.

Filter size: Large filters (d > 5) are very slow, so it is recommended to use d=5 for real-time applications, and perhaps d=9 for offline applications that need heavy noise filtering.

   

    进行高斯滤波的通常原因是真是图像在空间内的像素是缓慢变化的,因此临近点的像素变化不会很明显,但是随即的两个订就可能形成很大的像素差,因此高斯滤波在保留信号的条件下减少噪声。但是在接近边缘处就无效了,在那里不希望像素与相邻像素相关,所以高斯滤波会磨平边缘。 而双边滤波能够提供一种不会讲边缘平花掉的方法,代价是需要更多的处理时间。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值