当前位置:网站首页>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,函数会自行判断最适合尺寸的σ值。
边栏推荐
- Income in the first month of naked resignation
- 王-课外单词
- How gensim freezes some word vectors for incremental training
- Apple added the first iPad with lightning interface to the list of retro products
- Global and Chinese markets for Salmonella typhi nucleic acid detection kits 2022-2028: Research Report on technology, participants, trends, market size and share
- AR system summary harvest
- Replace convolution with full connection layer -- repmlp
- STL速查手册
- 【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
猜你喜欢
How to clean up logs on notebook computers to improve the response speed of web pages
Using super ball embedding to enhance confrontation training
【FastDepth】《FastDepth:Fast Monocular Depth Estimation on Embedded Systems》
11月24号,我们为“满月”庆祝
Hystrix dashboard cannot find hystrix Stream solution
How to back up the configuration before the idea when reinstalling the idea
Specification for package drawing
Dynamic extensible representation for category incremental learning -- der
Income in the first month of naked resignation
【学习笔记】Matlab自编图像卷积函数
随机推荐
How to wrap qstring strings
【TCDCN】《Facial landmark detection by deep multi-task learning》
【雙目視覺】雙目矯正
Global and Chinese market of recovery equipment 2022-2028: Research Report on technology, participants, trends, market size and share
I'll show you why you don't need to log in every time you use Taobao, jd.com, etc?
open3d学习笔记二【文件读写】
【MobileNet V3】《Searching for MobileNetV3》
乐理基础(简述)
Replace convolution with full connection layer -- repmlp
Organigramme des activités
Sequence problem for tqdm and print
Global and Chinese markets for magnetic resonance imaging (MRI) transmission 2022-2028: Research Report on technology, participants, trends, market size and share
Vscode下中文乱码问题
Open3d learning note 5 [rgbd fusion]
【Wing Loss】《Wing Loss for Robust Facial Landmark Localisation with Convolutional Neural Networks》
open3d学习笔记五【RGBD融合】
【MobileNet V3】《Searching for MobileNetV3》
open3d学习笔记三【采样与体素化】
常量指针和指针常量
C # connect to MySQL database