当前位置:网站首页>Opencv learning notes - linear filtering: box filtering, mean filtering, Gaussian filtering
Opencv learning notes - linear filtering: box filtering, mean filtering, Gaussian filtering
2022-07-04 14:33:00 【cc_ rong】
Smoothing ( blurred )
Generally used Reduce noise or distortion on the image . When reducing the image resolution , Use smoothing .
Eliminating noise components in an image is called Image smoothing or Filtering operation .
The purpose of image filtering is :
1、 Extract the feature of the object as the feature pattern of image recognition ;
2、 In order to meet the requirements of image processing , Eliminate the noise in image digitization .
Smooth filtering It's low-frequency enhanced spatial filtering technology . It has two purposes :
1、 Fuzzy ; 2、 Eliminate noise .
Common image smoothing operation methods :
linear :
Box filtering ---------BoxBlur function
Mean filtering ( Neighborhood average filtering )---------Blur function
Gauss filtering ---------GaussianBlur function
nonlinear :
median filtering ---------medianBlur function
Bilateral filtering ---------bilateralFilter function
Linear filter
Linear filters are often used to eliminate unwanted frequencies in input signals or to select a desired frequency from many frequencies .
Common linear filters are as follows :
low pass filter : Allow low frequencies to pass through ;
High pass filter : Allow high frequency passage ;
Bandpass filter : Allow a certain range of frequencies to pass ;
Band stop filter : Prevent a certain range of frequencies from passing and allow other frequencies to pass ;
All pass filter : Allow all frequencies to pass through , Just change the phase relationship ;
Notch filter : Prevent a narrow frequency range from passing through , It is a special band stop filter .
Box filtering
boxBlur function sources\modules\imgproc\src Under the smooth.cpp
void boxFilter(InputArray src, OutputArray dst, int ddepth, Size ksize, Point anchor = Point(-1,-1), bool normalize = true, int borderType = BORDER_DEFAULT )
Parameters 1,src, The input image , Source image , fill Mat Class object . This function is independent of the channel , And can Process pictures with any number of channels . Be careful , The depth of the image to be processed should be CV_8U、CV_16U、 CV_16S、CV_32F as well as CV_64F One of .
Parameters 2,dst, The target image , Need the same size and type as the source image .
Parameters 3,ddepth, The depth of the output image ,-1 Represents the depth of the original image , namely src.depth().
Parameters 4,ksize, The size of the kernel . It's usually used Size(w, h) To represent the size of the kernel , among w For pixel width ,h by Pixel height .Size(3, 3) It means 3 x 3 The nuclear size of ,Size(5, 5) It means 5 x 5 The nuclear size of .
Parameters 5,anchor, Represents an anchor ( The point that is smoothed ). The default value is Point(-1,-1). If the coordinate of this point is negative If it's worth it , It means that the center of the core is the anchor point , So the default value is Point(-1,-1) Indicates that this anchor is in the core heart .
Parameters 6,normalize, The default value is true, Indicates whether the kernel is normalized by its region (normalized)
Parameters 7,borderType, Some kind of boundary pattern used to infer pixels outside the image . The default value is : BORDER_DEFAULT, Generally not used .
boxFilter The kernel representation of the function :
among
According to the effect :
ksize The bigger it is , The more blurred the picture is .
Code :
Mat srcImg1; Mat srcImg2; srcImg1 = imread("E:\\img\\logo3.png"); imshow(" Source graph srcImg1", srcImg1); boxFilter(srcImg1, srcImg2, -1, Size(14, 18)); imshow(" Box filtering srcImg2", srcImg2);
Mean filtering
Each pixel of the output image of the mean filter is the average value of the corresponding pixel of the input image in the kernel window ( All pixels are weighted equally ), That is, normalized block filtering .Mean filtering is A typical linear filtering algorithm . The main method is Neighborhood averaging , That is to use the average value of each pixel in an image area to replace the value of each pixel in the original image .defects :Cannot protect image details well , While denoising the image, it also destroys the details of the image , Make the image blurred , It can't remove the noise very well .void blur(InputArray src, outputArraydst, Size ksize, Point anchor = Point(-1, -1), int borderType = BORDER_DEFAULT)
Parameters 1, The input image , Source image ,Mat Class object . This function is independent of the channel , And can handle any Picture of the number of channels . Be careful , The depth of the image to be processed should be CV_8U、CV_16U、CV_16S、 CV_32F as well as CV_64F One of .
Parameters 2, Target image , Need the same size and type as the source image . It can be used Mat::Clone, Take the source image as the model plate , To initialize the target graph .
Parameters 3, The size of the kernel . It's usually used Size(w, h) To represent the size of the kernel , among w For pixel width ,h Is pixel high degree .Size(3,3) It means 3x3 The nuclear size of ,Size(5,5) It means 5x5 The nuclear size of .
Parameters 4, Represents an anchor ( The point that is smoothed ). The default value is Point(-1,-1). If the coordinates of this point are negative , It means that the center of the core is the anchor point , So the default value is Point(-1,-1) It means that the anchor is in the center of the core .
Parameters 5, Some kind of boundary pattern used to infer pixels outside the image . The default value is BORDER_DEFAULT, Generally do not make use .
According to the effect :
Code :
Mat srcImg1; Mat srcImg2; srcImg1 = imread("E:\\img\\logo3.png"); imshow(" Source graph srcImg1", srcImg1); blur(srcImg1, srcImg2, Size(18, 18)); imshow(" Mean filtering srcImg2", srcImg2);
Gauss filtering
Gaussian filtering refers to the filtering operation using Gaussian function as the filtering function ;
Application scenarios : Noise reduction process of image processing .
The specific implementation of Gaussian filtering :
Use a template ( Convolution 、 Mask ) Scan every pixel in the image , Using the weighted average gray value of the pixels in the neighborhood determined by the template to replace the value of the central pixel of the template .
Gaussian blur of image is the convolution of image and normal distribution .Gaussian blur is a Gaussian low-pass filter .GaussianBlur function : Blur an image with a Gaussian filterConvolute the source image with the specified Gaussian kernel function , And support local filtering .void GaussianBlur(InputArray src, outputArray dst, Size ksize, double sigmaX, double sigmaY = 0, int borderType = BORDER_DEFAULT )
Parameters 1, The input image , fill Mat Class object . It can be a single picture with any number of channels ,
Be careful , The picture depth should be CV_8U、CV_16U、CV_16S、CV_32F as well as CV_64F One of .
Parameters 2, Target image , Need the same size and type as the source image . It can be used Mat::Clone, Take the source image as the model plate , To initialize the target graph .
Parameters 3, The size of the Gaussian kernel . among ksize.width and ksize.height Can be different , Must be positive and odd ,
Or zero , All by sigma Come by calculation .
Parameters 4, Denotes that the Gaussian kernel function is in X The standard deviation of the direction .
Parameters 5, Denotes that the Gaussian kernel function is in Y The standard deviation of the direction . if sigmaY zero , Set it to sigmaX;
If sigmaX and sigmaY All are 0, from ksize.width and ksize.height Work it out .
Parameters 6, Some kind of boundary pattern used to infer pixels outside the image . The default value is BORDER_DEFAULT, Generally do not make use .
According to the effect :
Code :
Mat srcImg1; Mat srcImg2; srcImg1 = imread("E:\\img\\logo3.png"); imshow(" Source graph srcImg1", srcImg1); GaussianBlur(srcImg1, srcImg2, Size(5, 5), 0, 0); imshow(" Gauss filtering srcImg2", srcImg2);
边栏推荐
- MySQL stored procedure exercise
- Docker compose public network deployment redis sentinel mode
- leetcode:6110. The number of incremental paths in the grid graph [DFS + cache]
- R language dplyr package summary_ If function calculates the mean and median of all numerical data columns in dataframe data, and summarizes all numerical variables based on conditions
- Ml: introduction, principle, use method and detailed introduction of classic cases of snap value
- R language uses bwplot function in lattice package to visualize box plot and par Settings parameter custom theme mode
- 92.(cesium篇)cesium楼栋分层
- Nowcoder reverse linked list
- 流行框架:Glide的使用
- The game goes to sea and operates globally
猜你喜欢
Gin integrated Alipay payment
Node mongodb installation
RK1126平台OSD的实现支持颜色半透明度多通道支持中文
Map of mL: Based on Boston house price regression prediction data set, an interpretable case of xgboost model using map value
WT588F02B-8S(C006_03)单芯片语音ic方案为智能门铃设计降本增效赋能
商業智能BI財務分析,狹義的財務分析和廣義的財務分析有何不同?
Detailed explanation of visual studio debugging methods
92. (cesium chapter) cesium building layering
Digi XBee 3 rf: 4 protocols, 3 packages, 10 major functions
LVGL 8.2 Line wrap, recoloring and scrolling
随机推荐
LiveData
Test process arrangement (3)
(1) The standard of performance tuning and the correct posture for tuning - if you have performance problems, go to the heapdump performance community!
ML之shap:基于boston波士顿房价回归预测数据集利用shap值对XGBoost模型实现可解释性案例
sql优化之查询优化器
Docker compose public network deployment redis sentinel mode
【MySQL从入门到精通】【高级篇】(四)MySQL权限管理与控制
第十六章 字符串本地化和消息字典(二)
[information retrieval] experiment of classification and clustering
92.(cesium篇)cesium楼栋分层
leetcode:6109. Number of people who know the secret [definition of DP]
【信息检索】链接分析
Some problems and ideas of data embedding point
深度学习7 Transformer系列实例分割Mask2Former
關於miui12.5 紅米k20pro用au或者povo2出現問題的解决辦法
迅为IMX6Q开发板QT系统移植tinyplay
Detailed index of MySQL
The failure rate is as high as 80%. What are the challenges on the way of enterprise digital transformation?
Detailed explanation of visual studio debugging methods
GCC [6] - 4 stages of compilation