当前位置:网站首页>OpenCV3 6.2 低通滤波器的使用
OpenCV3 6.2 低通滤波器的使用
2022-07-02 06:28:00 【Villanelle#】
频域、频率的概念
观察图像强度值变化的频率的方法称为频域,观察灰度分布描述图像特征的方法称为空域。
图像中灰度强度值变化慢的区域产生低频率,而强度值变化快的区域产生高频率,频率分为垂直频率(垂直方向上的变化)和水平频率(水平方向上的变化)。
可以用傅里叶变换或余弦变换等方法显示图像的频率成分。
滤波器
滤波即选择性地提取图像某项方面的内容,可以放大图像中某些频段,同时滤掉其他频段的算子。
滤波器可以分为低通滤波器和高通滤波器,本节中主要介绍块滤波器(box filter)和高斯滤波器(gaussian filter)。
块滤波器
块滤波器cv::blur
可以将每个函数的值替换成该像素邻域(矩形)的平均值。
块滤波器使用了邻域像素的加权累加值来替换像素值,所以这种滤波器是线性的,且块滤波器是一种均值滤波器,由于本例使用了5*5的内核,其内核可以写为:
1/25 | 1/25 | 1/25 | 1/25 | 1/25 |
---|---|---|---|---|
1/25 | 1/25 | 1/25 | 1/25 | 1/25 |
1/25 | 1/25 | 1/25 | 1/25 | 1/25 |
1/25 | 1/25 | 1/25 | 1/25 | 1/25 |
1/25 | 1/25 | 1/25 | 1/25 | 1/25 |
利用线性滤波器将内核移动到图像 的每个像素上,并将对应像素乘以权重,在数学上称为卷积。
高斯滤波器
高斯滤波器cv::GaussianBlur
也是线性滤波器,但与块滤波器不同,高斯滤波器像素对应的权重与它到中心像素之间的距离成正比,即正态分布函数。一维高斯函数的公式为:
参数σ决定高斯函数曲线的形状,σ越大,函数曲线越扁平,即周围像素占的权重越小;σ越小,函数曲线越陡峭,即周围像素占的权重越大。
要在图像(二维空间)上应用二维高斯滤波器,只需在横向线条上应用一维高斯滤波器(过滤水平方向的频率),再在纵向线条上应用一维高斯滤波器(过滤竖直方向的频率)。原理是高斯滤波器是一种可分离滤波器,可以分为两个一维滤波器。
具体实现
cv::Mat image = cv::imread("boldt.jpg");
cv::Mat boxblur, gaussianblur;
cv::blur(image, //原图像
boxblur, //经过块滤波器滤波后的图像
cv::Size(5, 5)); //尺寸定为5*5的滤波器
cv::GaussianBlur(image, //原图像
gaussianblur, //经过高斯滤波后的图像
cv::Size(5, 5), //尺寸定为5*5的滤波器
1.5, //控制高斯曲线形状的参数sigmaX,sigmaX越大,附近像素占的比例越小
0); //控制高斯曲线形状的参数sigmaY,如指定为0或不指定默认与sigmaX相同
cv::imshow("image", image);
cv::imshow("boxblur", boxblur);
cv::imshow("gaussianblur", gaussianblur);
效果展示
cv::blur
函数的使用
函数签名
CV_EXPORTS_W void blur( InputArray src, OutputArray dst,
Size ksize, Point anchor = Point(-1,-1),
int borderType = BORDER_DEFAULT );
参数分别为:输入图像,输出图像,滤波器尺寸,初始点(默认为矩形中间点),边界的类型(一般默认)。
cv::GaussianBlur
函数的使用
函数签名
CV_EXPORTS_W void GaussianBlur( InputArray src, OutputArray dst, Size ksize,
double sigmaX, double sigmaY = 0,
int borderType = BORDER_DEFAULT );
参数分别为:输入图像,输出图像,滤波器尺寸,x方向σ参数sigmaX,y方向σ参数sigmaY,边界的类型(一般默认)。
注:这里如只填sigmaX(或者sigmaY设为0)也可以,会默认sigmaY等于sigmaX。如果sigmaX和sigmaY都设为0,函数会自行判断最适合尺寸的σ值。
边栏推荐
- Daily practice (19): print binary tree from top to bottom
- EKLAVYA -- 利用神经网络推断二进制文件中函数的参数
- 【Sparse-to-Dense】《Sparse-to-Dense:Depth Prediction from Sparse Depth Samples and a Single Image》
- Global and Chinese market of snow sweepers 2022-2028: Research Report on technology, participants, trends, market size and share
- 简易打包工具的安装与使用
- The hystrix dashboard reported an error hystrix Stream is not in the allowed list of proxy host names solution
- C#与MySQL数据库连接
- [learning notes] numerical differentiation of back error propagation
- 【学习笔记】Matlab自编图像卷积函数
- Comparison between setTimeout and requestanimationframe (page refresh)
猜你喜欢
用MLP代替掉Self-Attention
【Cutout】《Improved Regularization of Convolutional Neural Networks with Cutout》
[binocular vision] binocular correction
On the confrontation samples and their generation methods in deep learning
Cvpr19 deep stacked hierarchical multi patch network for image deblurring paper reproduction
乐理基础(简述)
使用C#语言来进行json串的接收
I'll show you why you don't need to log in every time you use Taobao, jd.com, etc?
用全连接层替代掉卷积 -- RepMLP
应对长尾分布的目标检测 -- Balanced Group Softmax
随机推荐
【Batch】learning notes
業務架構圖
How to wrap qstring strings
图像增强的几个方法以及Matlab代码
Global and Chinese market of recovery equipment 2022-2028: Research Report on technology, participants, trends, market size and share
【MagNet】《Progressive Semantic Segmentation》
Graph Pooling 简析
服务器的内网可以访问,外网却不能访问的问题
On the back door of deep learning model
Network metering - transport layer
【MnasNet】《MnasNet:Platform-Aware Neural Architecture Search for Mobile》
【Sparse-to-Dense】《Sparse-to-Dense:Depth Prediction from Sparse Depth Samples and a Single Image》
最长等比子序列
Array and string processing, common status codes, differences between PHP and JS (JS)
Summary of open3d environment errors
Open3d learning note 3 [sampling and voxelization]
The hystrix dashboard reported an error hystrix Stream is not in the allowed list of proxy host names solution
Target detection for long tail distribution -- balanced group softmax
【DIoU】《Distance-IoU Loss:Faster and Better Learning for Bounding Box Regression》
包图画法注意规范