Skip to content
doubtly

1 answer

The Sobel operator approximates the image gradient by combining a central difference in one direction with a [1 2 1] smoothing in the perpendicular direction; its advantage is that it detects edges while also suppressing noise.

Derivation. For a 3×3 neighbourhood

z1  z2  z3
z4  z5  z6
z7  z8  z9

the gradient is \(\nabla f = (G_x, G_y)\), where \(G_x = \partial f/\partial x\) and \(G_y = \partial f/\partial y\). Here x runs down the rows and y across the columns, as in Gonzalez and Woods.

  1. A central difference in the x direction (bottom row minus top row) for one column is \(f(x+1,y) - f(x-1,y)\), e.g. \(z_8 - z_2\).
  2. To reduce noise, take this difference for the three columns and average them with weights 1, 2, 1, giving more weight to the centre column (the [1 2 1] smoothing, a simple approximation of a Gaussian):

\[G_x = (z_7 + 2z_8 + z_9) - (z_1 + 2z_2 + z_3)\]

Similarly, in the y direction (right column minus left column):

\[G_y = (z_3 + 2z_6 + z_9) - (z_1 + 2z_4 + z_7)\]

These give the Sobel masks:

   Gx               Gy
-1  -2  -1       -1   0   1
 0   0   0       -2   0   2
 1   2   1       -1   0   1

Each mask is the outer product of a smoothing vector and a difference vector, e.g. \(G_y\) mask \(= [1\ 2\ 1]^T [-1\ 0\ 1]\). The coefficients of each mask add up to zero, so the response is zero in regions of constant intensity.

Gradient magnitude and direction:

\[M = \sqrt{G_x^2 + G_y^2} \approx |G_x| + |G_y|\]

\[\theta = \tan^{-1}(G_y/G_x)\]

A pixel is marked as an edge if \(M\) exceeds a threshold.

Advantages of the Sobel operator

  • Built-in smoothing makes it less sensitive to noise than the Roberts or simple difference operators, and slightly better than Prewitt, because of the weight 2 on the centre.
  • Gives both edge strength and edge direction.
  • Simple 3×3 integer masks, so it is fast and easy to implement.
Tutor AI · 23 Oct 2026 AI-verified AI-generated Report

Your answer

Log in or create a free account to answer this question.