OpenCV: Sobel Derivatives

摘自https://docs.opencv.org/4.2.0/d2/d2c/tutorial_sobel_derivatives.html

摘自https://docs.opencv.org/4.2.0/d4/d86/group__imgproc__filter.html#gacea54f142e81b6758cb6f375ce782c8d

In an edge, the pixel intensity changes in a notorious way. A good way to express changes is by using derivatives.

Sobel Operator

  1. The Sobel Operator is a discrete differentiation operator. It computes an approximation of the gradient of an image intensity function.
  2. The Sobel Operator combines Gaussian smoothing and differentiation.

Formulation

Assuming that the image to be operated is I. We calculate two derivatives:

Horizontal changes: This is computed by convolving I with a kernel with odd size. For example, a kernel size of 3:

Vertical changes

At each point of the image we calculate an approximation of the gradient in that point by combining both results above:

G = \sqrt{G_{x}^2 + G_{y}^2}

Although sometimes the following simpler equation is used:

G=|Gx|+|Gy|

Note: When the size of the kernel is 3, the Sobel kernel shown above may produce noticeable inaccuracies (after all, Sobel is only an approximation of the derivative). OpenCV addresses this inaccuracy for kernels of size 3 by using the Scharr() function. This is as fast but more accurate than the standard Sobel function. It implements the following kernels:

 

dst=cv.Sobel(src, ddepth, dx, dy[, dst[, ksize[, scale[, delta[, borderType]]]]])

srcinput image.
dstoutput image of the same size and the same number of channels as src .
ddepthoutput image depth, see combinations; in the case of 8-bit input images it will result in truncated derivatives.
dxorder of the derivative x.
dyorder of the derivative y.
ksizesize of the extended Sobel kernel; it must be 1, 3, 5, or 7.
scaleoptional scale factor for the computed derivative values; by default, no scaling is applied.
deltaoptional delta value that is added to the results prior to storing them in dst.
borderTypepixel extrapolation method, see BorderTypes

Calculates the first, second, third, or mixed image derivatives using an extended Sobel operator.

The function calculates an image derivative by convolving the image with the appropriate kernel:

The Sobel operators combine Gaussian smoothing and differentiation, so the result is more or less resistant to the noise. Most often, the function is called with ( xorder = 1, yorder = 0, ksize = 3) or ( xorder = 0, yorder = 1, ksize = 3) to calculate the first x- or y- image derivative.

In all cases except 1, the ksize×ksize separable kernel is used to calculate the derivative. When ksize = 1, the 3×1 or 1×3 kernel is used (that is, no Gaussian smoothing is done). ksize = 1 can only be used for the first or the second x- or y- derivatives.

There is also the special value ksize = -1that corresponds to the 3×3 Scharr filter that may give more accurate results than the 3×3 Sobel.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值