图像Smoothing/Blurring
2017-12-18 13:41
155 查看
Smooth/Blurring是图片预处理的一种技术,这样可以减弱图片中突变点对后续处理的影响,像噪音这样的突变点是需要处理的;也可以降低图像的分辨率,因为图像变模糊了。这种技术相对于图像锐化,增强突变点。
1. 普通的smoothing
输出的像素为周围一定范围内的像素算数平均值;boxFilter是blur的一般形式,前者可以指定输出的深度,数据格式,比如:CV_32F
Simple Blur and the Box Filter
void cv::blur(
cv::InputArray src, // Input image
cv::OutputArray dst, // Result image
cv::Size ksize, // Kernel size
cv::Point anchor = cv::Point(-1,-1), // Location of anchor point
int borderType = cv::BORDER_DEFAULT // Border extrapolation to use
);
void cv::boxFilter(
cv::InputArray src, // Input image
cv::OutputArray dst, // Result image
int ddepth, // Output depth (e.g., CV_8U)
cv::Size ksize, // Kernel size
cv::Point anchor = cv::Point(-1,-1), // Location of anchor point
bool normalize = true, // If true, divide by box area
int borderType = cv::BORDER_DEFAULT // Border extrapolation to use
);
2.中值滤波/Median Filter
采用周围一定范围内像素值的中值作为输出;
中值和平均值没有必然的关系。中值是将所给的一组数从小到大或从大到小排列,奇数个数的话取中间的数字,偶数个数的话取中间两个数的平均数;而平均值就是把这组数相加,然后除以这组数的个数。
中值的优点是不受偏大或偏小数据的影响,很多情况下用它代表全体数据的一般水平更合适。如果数列中存在极端变量值,用中位数做代表值就比平均数更好
void cv::medianBlur(
cv::InputArray src, // Input image
cv::OutputArray dst, // Result image
cv::Size ksize // Kernel size
);
3.高斯滤波/Gaussian Filter
输出的像素是原像素与2D高斯函数模板进行卷积的结果;
2D高斯模板需要确定M、N,sigma(M:长,N:宽,sigma:标准差),python代码例子如下:M=5,N=5,sigma=0.6
******************************************************************************
import numpy as np
x, y = np.meshgrid(np.linspace(-2,2,5), np.linspace(-2,2,5))
sigma=0.6
coefficient=1/(2*np.pi*sigma**2)
value1=np.exp(-( x**2+y**2)/ ( 2.0 * sigma**2 ) )
g=coefficient*value1
******************************************************************************
void cv::GaussianBlur(
cv::InputArray src, // Input image
cv::OutputArray dst, // Result image
cv::Size ksize, // Kernel size
double sigmaX, // Gaussian half-width in x-direction
double sigmaY = 0.0, // Gaussian half-width in y-direction
int borderType = cv::BORDER_DEFAULT // Border extrapolation to use
);
4.双边滤波/bilateral filter
相对于高斯滤波,能够更好的保存边缘信息;
void cv::bilateralFilter(
cv::InputArray src, // Input image
cv::OutputArray dst, // Result image
int d, // Pixel neighborhood size (max distance)
double sigmaColor, // Width param for color weight function
double sigmaSpace, // Width param for spatial weight function
int borderType = cv::BORDER_DEFAULT // Border extrapolation to use
);
1. 普通的smoothing
输出的像素为周围一定范围内的像素算数平均值;boxFilter是blur的一般形式,前者可以指定输出的深度,数据格式,比如:CV_32F
Simple Blur and the Box Filter
void cv::blur(
cv::InputArray src, // Input image
cv::OutputArray dst, // Result image
cv::Size ksize, // Kernel size
cv::Point anchor = cv::Point(-1,-1), // Location of anchor point
int borderType = cv::BORDER_DEFAULT // Border extrapolation to use
);
void cv::boxFilter(
cv::InputArray src, // Input image
cv::OutputArray dst, // Result image
int ddepth, // Output depth (e.g., CV_8U)
cv::Size ksize, // Kernel size
cv::Point anchor = cv::Point(-1,-1), // Location of anchor point
bool normalize = true, // If true, divide by box area
int borderType = cv::BORDER_DEFAULT // Border extrapolation to use
);
2.中值滤波/Median Filter
采用周围一定范围内像素值的中值作为输出;
中值和平均值没有必然的关系。中值是将所给的一组数从小到大或从大到小排列,奇数个数的话取中间的数字,偶数个数的话取中间两个数的平均数;而平均值就是把这组数相加,然后除以这组数的个数。
中值的优点是不受偏大或偏小数据的影响,很多情况下用它代表全体数据的一般水平更合适。如果数列中存在极端变量值,用中位数做代表值就比平均数更好
void cv::medianBlur(
cv::InputArray src, // Input image
cv::OutputArray dst, // Result image
cv::Size ksize // Kernel size
);
3.高斯滤波/Gaussian Filter
输出的像素是原像素与2D高斯函数模板进行卷积的结果;
2D高斯模板需要确定M、N,sigma(M:长,N:宽,sigma:标准差),python代码例子如下:M=5,N=5,sigma=0.6
******************************************************************************
import numpy as np
x, y = np.meshgrid(np.linspace(-2,2,5), np.linspace(-2,2,5))
sigma=0.6
coefficient=1/(2*np.pi*sigma**2)
value1=np.exp(-( x**2+y**2)/ ( 2.0 * sigma**2 ) )
g=coefficient*value1
******************************************************************************
void cv::GaussianBlur(
cv::InputArray src, // Input image
cv::OutputArray dst, // Result image
cv::Size ksize, // Kernel size
double sigmaX, // Gaussian half-width in x-direction
double sigmaY = 0.0, // Gaussian half-width in y-direction
int borderType = cv::BORDER_DEFAULT // Border extrapolation to use
);
4.双边滤波/bilateral filter
相对于高斯滤波,能够更好的保存边缘信息;
void cv::bilateralFilter(
cv::InputArray src, // Input image
cv::OutputArray dst, // Result image
int d, // Pixel neighborhood size (max distance)
double sigmaColor, // Width param for color weight function
double sigmaSpace, // Width param for spatial weight function
int borderType = cv::BORDER_DEFAULT // Border extrapolation to use
);
相关文章推荐
- Blurring/Smoothing
- 图像处理滤波器(三)——高斯平滑滤波器(Gaussian Smoothing Filter)
- 图像处理滤波器(四)——最值滤波器(Conservative Smoothing Filter)
- 使用Mumford Shah 函数平滑图像Smoothing images with the Mumford Shah functional
- html设置图像垂直间距
- 数字图像处理之最近邻内插算法的实现
- Qt的4个图像类QImage/QPixmap/QBitmap/QPicture 转
- 计算机图像
- IE版图像处理工具-不需下载的照片处理软件,图象处理工具
- png图像有哪几种属性?
- MFC获取rgb图像数据后动态显示及保存图片的方法
- 关于多通道图像分离与混合的一个实例
- 【图像识别】心得小结(育儿手册)
- 2、图像灰度变换,加法减法乘法除法差异最大处理
- 关于 android 6.0 上的 nuplayer 播放时的图像卡顿
- caffe学习系列:python下对图像进行批量预测
- OpenCV改变图像大小的操作,resize与图像金字塔方法
- 一个很有用的图像处理工具箱
- 在asp.net中如何从视频文件中抓取一桢并生成图像文件
- asp.net2.0(C#)图像处理类[转]