opencv中常用的线性滤波器--boxFilter(),blur(),GaussianBlur()
2017-07-04 22:17
3731 查看
1. boxFilter()
下面是opencv官方对boxFilter()函数的介绍。如果均衡化(即normalize==ture,这也是默认值),则其本质是均值滤波。
C++: void boxFilter(InputArray src,
OutputArray dst, int ddepth, Size ksize, Point anchor=Point(-1,-1), boolnormalize=true, int borderType=BORDER_DEFAULT )
Python: cv2.boxFilter(src,
ddepth, ksize[, dst[, anchor[, normalize[,
borderType]]]]) → dst
The function smoothes an image using the kernel:
where
2. blur()
调用blur()等效于调用将normalize=true的boxFilter().
Blurs an image using the normalized box filter.
C++: void blur(InputArray src,
OutputArray dst, Size ksize, Point anchor=Point(-1,-1), intborderType=BORDER_DEFAULT )
Python: cv2.blur(src,
ksize[, dst[, anchor[, borderType]]]) →
dst
The function smoothes an image using the kernel:
The call blur(src, dst, ksize, anchor, borderType) is
equivalent to boxFilter(src, dst, src.type(), anchor,true, borderType) .
3.GaussianBlur()
高斯滤波可以消除高斯噪声,广泛应用于图像处理的减噪过程。需要注意的是opencv中的GaussianBlur()是高斯低通滤波器,用来模糊减噪,所以叫高斯模糊。
整数模板用的比较多,常见的3x3或者5x5的整数模板如下。更多高斯滤波的讲解可以参考下面这篇博客http://blog.csdn.net/yansmile1/article/details/46275791
4. 应用实例
分别调用上面提到的三个函数对一副图像进行模糊操作,选取的kernel size为5x5。代码如下
运行结果如下,明显在相同的kernel size的情况下,GaussianBlur()的结果对原图的失真比较少(当然还和sigmaX & sigmaY有关),而boxFilter & blur()得到的结果是相同的,因为都是均值滤波。
下面是opencv官方对boxFilter()函数的介绍。如果均衡化(即normalize==ture,这也是默认值),则其本质是均值滤波。
C++: void boxFilter(InputArray src,
OutputArray dst, int ddepth, Size ksize, Point anchor=Point(-1,-1), boolnormalize=true, int borderType=BORDER_DEFAULT )
Python: cv2.boxFilter(src,
ddepth, ksize[, dst[, anchor[, normalize[,
borderType]]]]) → dst
Parameters: | src – input image. dst – output image of the same size and type as src. ddepth – the output image depth (-1 to use src.depth()). ksize – blurring kernel size. anchor – anchor point; default value Point(-1,-1) means that the anchor is at the kernel center. normalize – flag, specifying whether the kernel is normalized by its area or not. borderType – border mode used to extrapolate pixels outside of the image. |
---|
where
2. blur()
调用blur()等效于调用将normalize=true的boxFilter().
Blurs an image using the normalized box filter.
C++: void blur(InputArray src,
OutputArray dst, Size ksize, Point anchor=Point(-1,-1), intborderType=BORDER_DEFAULT )
Python: cv2.blur(src,
ksize[, dst[, anchor[, borderType]]]) →
dst
Parameters: | src – input image; it 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 – blurring kernel size. anchor – anchor point; 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 call blur(src, dst, ksize, anchor, borderType) is
equivalent to boxFilter(src, dst, src.type(), anchor,true, borderType) .
3.GaussianBlur()
高斯滤波可以消除高斯噪声,广泛应用于图像处理的减噪过程。需要注意的是opencv中的GaussianBlur()是高斯低通滤波器,用来模糊减噪,所以叫高斯模糊。
整数模板用的比较多,常见的3x3或者5x5的整数模板如下。更多高斯滤波的讲解可以参考下面这篇博客http://blog.csdn.net/yansmile1/article/details/46275791
4. 应用实例
分别调用上面提到的三个函数对一副图像进行模糊操作,选取的kernel size为5x5。代码如下
#include<opencv.hpp> #include<iostream> int main(void) { cv::Mat src = cv::imread("d:/Opencv Picture/Lena.jpg", CV_LOAD_IMAGE_GRAYSCALE); if (!src.data) { std::cout << "image read error!!!\n"; } cv::imshow("src",src); //call boxFilter() cv::Mat boxFilterDst; cv::boxFilter(src, boxFilterDst, -1, cv::Size(5, 5)); cv::imshow("boxFilterResult", boxFilterDst); //call blur() cv::Mat blurDst; cv::blur(src, blurDst, cv::Size(5, 5)); cv::imshow("blurResult", blurDst); //call GaussianBlur() cv::Mat GaussianDst; cv::GaussianBlur(src, blurDst, cv::Size(5, 5),0.8,0.8); cv::imshow("GaussianBlurResult", blurDst); cvWaitKey(0); return 0; }
运行结果如下,明显在相同的kernel size的情况下,GaussianBlur()的结果对原图的失真比较少(当然还和sigmaX & sigmaY有关),而boxFilter & blur()得到的结果是相同的,因为都是均值滤波。
相关文章推荐
- opencv2函数学习之blur,GaussianBlur,medianBlur和bilateralFilter:实现图像平滑处理
- 使用OpenCV中的几种线性滤波器对图像平滑处理
- opencv-线性滤波器filer2D
- OpenCV之imgproc 模块. 图像处理(2)实现自己的线性滤波器 给图像添加边界 Sobel 导数 Laplace 算子 Canny 边缘检测
- opencv 线性滤波器
- (24)Air Band OpenCV2.4.13_自定义线性滤波器
- OpenCV Tutorial: 影像平滑(blur、GaussianBlur)
- Python OpenCV 线性滤波器 简介(七)
- Opencv中的3种线性滤波器
- Css的filter常用滤波器属性及语句大全
- OpenCV中滤波器学习笔记(一)--CvSepFilter
- CSS的filter常用滤波器属性及语句大全
- 线性表,链表,哈希表是常用的数据结构,在进行Java开发时
- java实现常用的查找(线性查找,折半查找)
- OpenCV 图像处理常用函数
- OpenCV: 线性插值方法进行图像放大
- Css的filter常用滤波器属性及语句大全
- Opencv中常用的几个函数
- [转]openCV: 线性插值方法进行图像放大
- OpenCV常用连接