Lably
Skip to content

Sobel operator

Image edge detection algorithm

  • 6 min read
  • 7 chapters

Related on Lably

Through Digital image processing, Computer vision and Recurrence relation

Formulation

The operator uses two 3×3 kernels which are convolved with the original image to calculate approximations of the derivatives – one for horizontal changes, and one for vertical. If we define A as the source image, and Gx and Gy are two images which at each point contain the horizontal and vertical derivative approximations respectively, the computations are as follows:

Gx=[−10+1−20+2−10+1]∗AGy=[−1−2−1000+1+2+1]∗A

where ∗ here denotes the 2-dimensional signal processing convolution operation.

In his text describing the origin of the operator, Sobel shows different signs for these kernels. He defined the operators as neighborhood masks (i.e. correlation kernels), and therefore are mirrored from what described here as convolution kernels. He also assumed the vertical axis increasing upwards instead of downwards as is common in image processing nowadays, and hence the vertical kernel is flipped.

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, Gx and Gy can be written as

Gx=[121]∗([10−1]∗A)Gy=[+10−1]∗([121]∗A)

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 Pythagorean addition:

G=Gx2+Gy2

Using this information, we can also calculate the gradient's direction:

Θ=atan2⁡(Gy,Gx)

where, for example, Θ is 0 for a vertical edge which is lighter on the right side (for atan2 see atan2).

Sign in to keep reading

6 more chapters are free with a Lably account.

More in Robotics