当前位置:网站首页>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);
边栏推荐
- Classify boost libraries by function
- sql优化之查询优化器
- MySQL stored procedure exercise
- 统计php程序运行时间及设置PHP最长运行时间
- 第十七章 进程内存
- Leetcode T48:旋转图像
- ML之shap:基于boston波士顿房价回归预测数据集利用shap值对XGBoost模型实现可解释性案例
- Abnormal value detection using shap value
- [MySQL from introduction to proficiency] [advanced chapter] (IV) MySQL permission management and control
- Leetcode t49: grouping of alphabetic words
猜你喜欢
Talk about 10 tips to ensure thread safety
【信息检索】分类和聚类的实验
leetcode:6110. The number of incremental paths in the grid graph [DFS + cache]
Explain of SQL optimization
Sqlserver functions, creation and use of stored procedures
Scratch Castle Adventure Electronic Society graphical programming scratch grade examination level 3 true questions and answers analysis June 2022
Real time data warehouse
Digi restarts XBee Pro S2C production. Some differences need to be noted
No servers available for service: xxxx
一文概览2D人体姿态估计
随机推荐
Explain of SQL optimization
First experience of ViewModel
R language ggplot2 visualization: gganimate package creates animated graph (GIF) and uses anim_ The save function saves the GIF visual animation
Detailed index of MySQL
失败率高达80%,企业数字化转型路上有哪些挑战?
10. (map data) offline terrain data processing (for cesium)
一种架构来完成所有任务—Transformer架构正在以一己之力统一AI江湖
The game goes to sea and operates globally
sql优化之explain
One architecture to complete all tasks - transformer architecture is unifying the AI Jianghu on its own
Ultrasonic distance meter based on 51 single chip microcomputer
Use of arouter
Data warehouse interview question preparation
Detailed analysis of pytorch's automatic derivation mechanism, pytorch's core magic
scratch古堡历险记 电子学会图形化编程scratch等级考试三级真题和答案解析2022年6月
RK1126平台OSD的实现支持颜色半透明度多通道支持中文
迅为IMX6Q开发板QT系统移植tinyplay
开发中常见问题总结
leetcode:6109. 知道秘密的人数【dp的定义】
LVGL 8.2 Menu