当前位置:网站首页>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);
边栏推荐
- Detailed analysis of pytorch's automatic derivation mechanism, pytorch's core magic
- MySQL的存储过程练习题
- Xcode 异常图片导致ipa包增大问题
- Learn kernel 3: use GDB to track the kernel call chain
- LVGL 8.2 Menu
- Ml: introduction, principle, use method and detailed introduction of classic cases of snap value
- 【C语言】指针笔试题
- LVGL 8.2 text shadow
- opencv3.2 和opencv2.4安装
- Red envelope activity design in e-commerce system
猜你喜欢
[MySQL from introduction to proficiency] [advanced chapter] (IV) MySQL permission management and control
电商系统中红包活动设计
SqlServer函数,存储过程的创建和使用
(1) The standard of performance tuning and the correct posture for tuning - if you have performance problems, go to the heapdump performance community!
【MySQL从入门到精通】【高级篇】(四)MySQL权限管理与控制
LVGL 8.2 LED
【信息检索】分类和聚类的实验
Test process arrangement (2)
No servers available for service: xxxx
实战解惑 | OpenCV中如何提取不规则ROI区域
随机推荐
数据湖(十三):Spark与Iceberg整合DDL操作
聊聊保证线程安全的 10 个小技巧
nowcoder重排链表
Detailed explanation of visual studio debugging methods
Industrial Internet has greater development potential and more industry scenarios
Data center concept
10. (map data) offline terrain data processing (for cesium)
第十七章 进程内存
SqlServer函数,存储过程的创建和使用
Compile oglpg-9th-edition source code with clion
Free, easy-to-use, powerful lightweight note taking software evaluation: drafts, apple memo, flomo, keep, flowus, agenda, sidenote, workflow
ML:SHAP值的简介、原理、使用方法、经典案例之详细攻略
电商系统中红包活动设计
2022 game going to sea practical release strategy
WT588F02B-8S(C006_03)单芯片语音ic方案为智能门铃设计降本增效赋能
失败率高达80%,企业数字化转型路上有哪些挑战?
R language uses follow up of epidisplay package The plot function visualizes the longitudinal follow-up map of multiple ID (case) monitoring indicators, and uses stress The col parameter specifies the
R language uses dplyr package group_ The by function and the summarize function calculate the mean and standard deviation of the target variables based on the grouped variables
Map of mL: Based on Boston house price regression prediction data set, an interpretable case of xgboost model using map value
Leetcode T47: 全排列II