Sobel operator

Sobel operator / 索贝尔算子/ Sobel derivatives / Sobel 导数

#


索贝尔算子 (Sobel operator) 是图像处理中的算子之一, 主要用作边缘检测.
在技术上, 它是一离散性差分算子, 用来运算图像亮度函数的梯度之近似值.
在图像的任何一点使用此算子, 将会产生对应的梯度矢量或是其法矢量.

Formulation

该算子包含两组 3×3 的矩阵, 分别为横向及纵向, 将之与图像作平面卷积,
即可分别得出横向及纵向的亮度差分近似值.
如果以 A 代表原始图像, \(G _ x\)及 \(G _ y\)
分别代表经横向及纵向边缘检测的图像, 其公式如下:
\(
{G _ x} =
{{\begin{bmatrix} -1 & 0 & +1 \\ -2 & 0 & +2 \\ -1 & 0 & +1 \end{bmatrix}}
\ast {\text{A}}}
\)

and
\(
{G _ y} =
{{\begin{bmatrix} +1 & +2 & +1 \\ 0 & 0 & 0 \\ -1 & -2 & -1 \end{bmatrix}}
\ast {\text{A}}}
\)

where \(\ast\) here denotes the 2-dimensional signal processing
convolution operation.

Since the Sobel kernels can be decomposed as the products of an averaging and
a differentiation kernel,
they compute the gradient(梯度) with smoothing.
For example, \(G _ x\) can be written as:
\(
{\begin{bmatrix} +1 & +2 & +1 \\ 0 & 0 & 0 \\ -1 & -2 & -1 \end{bmatrix}} =
{{\begin{bmatrix}1 \\ 2 \\ 1\end{bmatrix}}
{\begin{bmatrix}+1 & 0 & -1\end{bmatrix}}}
\)

图像的每一个像素的横向及纵向梯度近似值可用以下的公式结合, 来计算梯度的大小.
The x-coordinate is defined here as increasing in the “right”-direction,
and the y-coordinate is defined as increasing in the “down”-direction.
At each point in the image, the resulting gradient approximations can be
combined to give the gradient magnitude(梯度强度), using:
\({G} = {\sqrt{{{G _ x}^{2}} + {{G _ y}^{2}}}}\)

Although sometimes the following simpler equation is used:
\({G} = {{|{G _ x}|} + {|{G _ y}|}}\)

如果梯度 G 大于某一阈值 则认为该点 (x, y) 为边缘点

然后可用以下公式计算梯度方向:
\({\theta} = {\arctan{\left(\frac{{G _ y}}{G _ x}\right)}}\)
where, for example, \(\theta\) is 0 for a vertical edge
(图像该处拥有纵向边缘) which is lighter on the right side.
若为\(\pi\), 则左方较亮.

Sobel 算子 根据像素点上下、左右邻点灰度加权差,
在边缘处达到极值这一现象检测边缘.
对噪声具有平滑作用, 提供较为精确的边缘方向信息, 边缘定位精度不够高.
当对精度要求不是很高时, 是一种较为常用的边缘检测方法.

Alternative operators

The Sobel–Feldman operator(费尔德曼算子),
while reducing artifacts associated with a pure central differences operator,
does not have perfect rotational symmetry.
Scharr looked into optimizing this property.4
5
Filter kernels up to size 5 x 5 have been presented there,
but the most frequently used one is:
\(\begin{bmatrix}+3&0&-3\\+10&0&-10\\+3&0&-3\end{bmatrix}\)
\(\begin{bmatrix}+3&+10&+3\\0&0&0\\-3&-10&-3\end{bmatrix}\)

Scharr

  • Use the OpenCV function Scharr() to calculate a more accurate derivative
    for a kernel of size 3 × 3

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 standar Sobel function.
It implements the following kernels:
\(
{G _ x} = {\begin{bmatrix}-3&0&+3\\-10&0&+10\\-3&0&+3\end{bmatrix}}
\)
\(
{G _ y} = {\begin{bmatrix}-3&-10&-3\\0&0&0\\+3&+10&+3\end{bmatrix}}
\)

see also https://docs.opencv.org/3.4.0/d2/d2c/tutorial_sobel_derivatives.html


refs