当前位置:网站首页>Opencv learning notes - edge detection and Canny operator, Sobel operator, lapiacian operator, ScHARR filter
Opencv learning notes - edge detection and Canny operator, Sobel operator, lapiacian operator, ScHARR filter
2022-07-26 03:49:00 【cc_ rong】
Catalog
LapIacian operator ( Laplace )
edge detection
edge detection step :
1、 wave filtering :
The algorithm of edge detection is mainly First and second derivatives based on image intensity , But derivatives are usually sensitive to noise , Therefore must Filter is used to improve the performance of edge detector related to noise . Common filtering methods mainly include Gauss filtering , using The discretized Gaussian function produces a set of normalized Gaussian kernels , Then, each point of the image gray matrix is weighted and summed based on Gaussian kernel function .
2、 enhance :
The basis of edge enhancement is to determine the change value of neighborhood intensity of each point in the image . The enhancement algorithm can highlight the points with significant changes in the intensity value of the neighborhood of image gray points . Determine by calculating the gradient amplitude . Gradient correlation algorithm : inflation 、 corrosion 、 Open operation 、 Closed operation 、 Morphological gradients 、 Top hat ( formal hat )、 Black hat .
3、 testing :
Enhanced image , Often, the gradient value of many points in the neighborhood is relatively large , And in a particular application , These points are not the edge points we are looking for , So we should use some method to choose these points . In practical engineering , The common method is through Threshold method to detect .
canny operator
canny The goal of the operator is : Find an optimal edge detection algorithm .
The best edge detection evaluation standard :
1. Low error rate : Identify as many actual edges as possible , At the same time, the false alarm caused by noise shall be reduced as much as possible .
2. High positioning : The marked edge should be as close as possible to the actual edge in the image .
3. Minimum response : Edges in an image can only be identified once , And the possible image noise should not be identified as edge .
canny Steps of edge detection :
1. Eliminate noise . In general , Convolution noise reduction using Gaussian smoothing filter .
The following shows a size = 5 Gaussian kernel example :
2. Calculate the gradient amplitude and direction . according to Sobel Filter steps .
i、 Using a pair of convolution arrays ( Act on respectively x and y Direction ):
ii、 Calculate the gradient amplitude and direction using the following formula :
The gradient direction approximates to one of four possible angles ( It's usually 0°, 45°, 90°, 135°)
3. Non maximum suppression . This step excludes non edge pixels , Only some thin lines are retained ( Candidate edges ).
4. Lag threshold .Canny Hysteresis threshold is used , Hysteresis threshold requires two thresholds ( High threshold and low threshold ):
i. If the magnitude of a pixel position exceeds a high threshold , The pixel is retained as an edge pixel .
ii. If the amplitude of a pixel position is less than the low threshold , The pixel is excluded .
iii. If the amplitude of a pixel position is between two thresholds , The pixel is only connected to a higher threshold
image Prime time is reserved .
void canny(InputArray image, OutputArray edges, double threshold1, double threshold2, int apertureSize = 3, bool L2gradient = false )Parameters 1,InputArray Type of image, The input image , fill Mat Class object , And it needs to be a single channel 8 Bit image .
Parameters 2,OutputArray Type of edges, Output edge graph , It needs to be the same size and type as the source image .
Parameters 3,double Type of threshold1, The first hysteresis threshold .
Parameters 4,double Type of threshold2, The second hysteresis threshold .
Parameters 5,int Type of apertureSize, Show application Sobel The aperture size of the operator , It has a default value 3.
Parameters 6,bool Type of L2gradient, An identifier for calculating the gradient amplitude of an image , Have default values false.
Be careful :
threshold1 and threshold2 The smaller of the two is used for edge connection , The larger one is used to control the strong edge
The initial segment , The recommended threshold ratio is 2:1 To 3:1 Between .
// Higher order canny usage , Turn to grayscale , Noise reduction , use canny,
// Finally, the obtained edge is used as a mask , Copy the original drawing to the effect drawing ,
// Get a color edge map
sobel operator
The main As a discrete differential operator for edge detection .
Sobel The operator combines Gaussian smoothing with differential derivation , It is used to calculate the approximate gradient of image gray function . Use this operator at any point in the image , The corresponding gradient vector or its normal vector will be generated .
advantage : Simple method 、 Fast processing speed , And the resulting edge is smooth 、 continuity .
shortcoming : Thick edge , Due to the need for binary processing , Therefore, the obtained edge is also closely related to the selection of threshold
sobel Operator steps :
1. Respectively in x and y Derivation in two directions .
i、 Level change : take I With an odd size kernel Gx Convolution . such as , When the kernel size is 3 when ,
Gx The result of the calculation is :
ii、 Vertical change : take I With an odd size kernel Gx Convolution . such as , When the kernel size is 3 when ,
Gx The result of the calculation is :
2. At every point in the image , Combined with the above two results, the approximate gradient :
perhaps
Use extended Sobel operator , To calculate the first order 、 Second order 、 Third order or mixed image difference .
void Sobel(InputArray src, OutputArray dst, int ddepth, int dx, int dy, int ksize = 3, double scale = 1, double delta = 0, int borderType = BORDER_DEFAULT);Parameters 1,InputArray Type of src, Input image for , fill Mat The type is enough .
Parameters 2,OutputArray Type of dst, The target image , Need the same size and type as the source image .
Parameters 3,int Type of ddepth, The depth of the output image , Support the following src.depth() and ddepth The combination of :
if src.depth() = CV_8U, take ddepth = -1/CV_16S/CV_32F/CV_64F
if src.depth() = CV_16U/CV_16S, take ddepth = -1/CV_32F/CV_64F
if src.depth() = CV_32F, take ddepth = -1/CV_32F/CV_64F
if src.depth() = CV_64F, take ddepth = -1/CV_64F
Parameters 4,int type dx,x The order of difference in the direction ,1 perhaps 0.
Parameters 5,int type dy,y The order of difference in the direction ,1 perhaps 0.
Parameters 6,int type ksize, Have default values 3, Express Sobel Nuclear size ; Value for 1,3,5 or 7.
Parameters 7,double Type of scale, Optional scaling factor when calculating derivative values , The default value is 1,
Indicates that scaling is not applied by default .
Parameters 8,double Type of delta, Indicates that the result is stored in the target graph ( The second parameter dst) Previously optional delta value ,
Have default values 0.
Parameters 9, int Type of borderType, The boundary model , The default value is BORDER_DEFAULT.
In general , It's all used ksize X ksize Kernel to calculate the derivative .
There is a special case ------ When ksize by 1 when , Often use 3 X 1 perhaps 1 X 3 The kernel of . And in this case , No Gaussian smoothing operation .
1. When the kernel size is 3 when , Sobel The kernel may produce obvious errors (Sobel The operator just takes the approximate value of the derivative ). To solve this problem ,OpenCV Provides Scharr function , but This function only works with sizes of 3 The kernel of . The operation of this function is related to Sobel As fast as a function , But the results are more accurate , The kernel is like this :
2.Sobel operator Combines Gaussian smoothing and differentiation , therefore The result will be more Noise resistance . Most of the time , Use sobel Function time , take 【xorder = 1,yorder = 0,ksize = 3】 To calculate the image X Derivative of direction ,【xorder = 0,yorder = 1,ksize = 3】 To calculate the image y Derivative of direction .
Calculate the image X Derivative of direction , take 【xorder= 1,yorder = 0,ksize = 3】 Corresponding kernel :
Calculate the image Y Derivative of direction , take 【xorder= 0,yorder = 1,ksize = 3】 Corresponding kernel :
LapIacian operator ( Laplace )
LapIacian operator yes n A second-order differential operator in a vieogrid space , Defined as gradient grad() Divergence of div(). If f It's a second-order differentiable real function , be f The Laplace operator of is defined as :
1、f The Laplace operator of is also Cartesian coordinate system Summation of all unmixed second-order partial derivatives in .
2 、 As a second-order differential operator , Laplacian put C The function maps to C function , about k ≥ 2. expression (1)( or (2)) Defines an operator Δ :C(R) → C(R), For any open set Ω, Defines an operator C(Ω) →C(Ω).
Laplacian The definition of operator :
because Laplacian Using image gradients ,Laplacian The internal code calls Sobel Operator's .
Let an image subtract its Laplacian Operators can Enhance contrast .
void Laplacian(InputArray src, OutputArray dst, int ddepth, int ksize = 1, double scale = 1, double delta = 0, int borderType = BORDER_DEFAULT );Parameters 1, The input image Mat Class object , And it needs to be a single channel 8 Bit image .
Parameters 2, Output edge graph , You need to have the same size and number of channels as the source image .
Parameters 3,int Type of ddept, The depth of the target image .
Parameters 4, The aperture size of the filter used to calculate the second derivative ( Gaussian kernel size ), Size must be positive odd ,
And there are default values 1.
Parameters 5, Optional scale factor when calculating Laplacian value , Have default values 1.
Parameters 6, Indicates that the result is stored in the target graph ( The second parameter dst) Previously optional delta value , Have default values 0.
Parameters 7, The boundary model , The default value is BORDER_DEFAULT. This parameter can be in borderInterpolate()
View in .
Laplacian() Functions are mainly utilize sobel The operation of the operator . By adding sobel The image calculated by the operator x Direction and y Derivative in direction , Get the Laplace transform result of the loaded image . among ,sobel operator (ksize>1) as follows :
When ksize=1 when ,Laplacian() The function uses the following 3 X 3 The aperture of :
scharr filter
The main thing is to cooperate with Sobel The operation of the operator exists .
Use Scharr Filter operator calculation x or y Image difference in direction .
void Scharr( InputArray src, // Source graph OutputArray dst, // Goal map , You need the same size and type as the source image int ddepth, // Image depth int dx, // x The order of difference in the direction int dy, // y The order of difference in the direction double scale=1, // Zoom factor double delta=0, // delta value int borderType = BORDER_DEFAULT // The boundary model )Parameters 3,int Type of ddepth, The depth of the output image , Support the following src.depth() and ddepth The combination of :
if src.depth() = CV_8U, take ddepth = -1/CV_16S/CV_32F/CV_64F
if src.depth() = CV_16U/CV_16S, take ddepth = -1/CV_32F/CV_64F
if src.depth() = CV_32F, take ddepth = -1/CV_32F/CV_64F
if src.depth() = CV_64F, take ddepth = -1/CV_64F
Parameters 6, Optional scaling factor when calculating derivative values , The default value is 1, Indicates that scaling is not applied by default .
Scharr(src, dst, ddepth, dx, dy, scale, delta, borderType); Equivalent
Sobel(src, dst, ddepth, dx, dy, CV_SCHARR, scale, delta, borderType);
边栏推荐
- C语言函数(2)
- [create interactive dice roller application]
- The B2B2C multi merchant system has rich functions and is very easy to open
- One stop monitoring of the software and hardware infrastructure of the whole university, and Suzhou University replaces PostgreSQL with time series database
- 安装VMware报错failed to install the hcmon driver
- 5年1.4W倍,NFT OG 的封神之路|Web3专栏
- php 保存数组到文件 var_export、serialize
- Use VRRP technology to realize gateway equipment redundancy, with detailed configuration experiments
- leetcode-202.快乐数
- 微信小程序实现音乐播放器(5)
猜你喜欢

sersync/lsync实时同步

booking.com缤客上海面经
![[programmers must] Tanabata confession strategy:](/img/55/0b43dd18c8682250db13ad94cd2c2c.png)
[programmers must] Tanabata confession strategy: "the moon meets the cloud, the flowers meet the wind, and the night sky is beautiful at night". (with source code Collection)

C language functions (2)

基于Caffe ResNet-50网络实现图片分类(仅推理)的实验复现

容器跑不动?网络可不背锅

Find My技术|物联网资产跟踪市场规模达66亿美元,Find My助力市场发展

A large factory developed and tested one, and strangled its neck with a mouse line

Visio: how do Gantt charts merge cells? Solution: overwrite cells

Summary of basic knowledge of C language pointer (I)
随机推荐
第十八章:2位a~b进制中均位奇观探索,指定整数的 3x+1 转化过程,指定区间验证角谷猜想,探求4份黑洞数,验证3位黑洞数
Multi merchant mall system function disassembly lecture 15 - platform side member label
Why are more and more users of Bing search?
Offline data warehouse from 0 to 1 - phase I resource purchase configuration
软考 系统架构设计师 简明教程 | 案例分析解题技巧
PHP connects to MySQL database, and database connects to static tool classes to simplify the connection.
File upload error: current request is not a multipart request
容器跑不动?网络可不背锅
MPLS basic experiment configuration
tf.truncated_ Normal() usage
Uncaught TypeError: $(...).onmouseenter is not a function js错误,解决办法:
booking.com缤客上海面经
STM32状态机编程实例——全自动洗衣机(下)
【云原生之kubernetes】kubernetes集群下ConfigMap使用方法
基本折线图:最直观呈现数据的趋势和变化
电商运营小白,如何快速入门学习数据分析?
某大厂开发和测试干了一架,还用鼠标线勒脖子...
Network model and protocol
php中可以使用取绝对值函数 abs() 将负数转成正数
[programmers must] Tanabata confession strategy: "the moon meets the cloud, the flowers meet the wind, and the night sky is beautiful at night". (with source code Collection)





perhaps 





