Sobel-Feldman filter: Edge Detection and Gradient Extraction

The Sobel filter (also called Sobel-Feldman operator) is an edge detection algorithm, that results in image emphasizing edges. Computer vision apps often use this image processing technique to extract the objects contours.

In this article we will discuss what a Sobel operator is, how to find contours in images and how to implement it in your own projects.

Edge Detection App

You can see how the Sobel filter works in our online image analysis demo.

Gradient Non-maximum suppression


See how it works in the browser!

What is Sobel filter?

The Sobel-Feldman operator is a separable edge detection filter. It is named after its discoverers – Irwin Sobel and Gary Feldman. In 1968 Sobel and Feldman presented a novel approach for a 3×3 image gradient operator.

The Sobel operator is applicable in many computer vision algorithms such as Hough transform, Harris corners detection and more.

This image filter is a core part of the popular Canny edge detector where we produce stable object contours for further objects recognition. 

Like the Prewitt operator, the filter consists of two 3×3 convolution masks. Their coefficients are integers and are relatively inexpensive to apply from a computational point of view.

The Sobel masks are with such design that they provide maximum value at horizontal or vertical edge orientation.

Both masks have the same coefficients as they are rotated 90 degrees to each other. Occasionally it is desirable to retrieve only one of the gradient orientation – horizontal or vertical.

Sobel filter 3x3 mask window
Sobel operator with 3×3 mask window

The image blow is an example result of Sobel operator and point out the enhanced objects outlines.

Sobel filter
Result of Sobel operator


Typically, edge recognition results are easily affected by noise in the image. Because of this it is commonly recommended to apply some low-pass filter like Gaussian.

Smoothing filters often smudge the edges as well. Therefore, many articles suggest using nonlinear edge-preserving filtering, such as the Symmetric Nearest Neighbor or Median filter.

How Sobel Filter works?

The Sobel filter works through a simple 3×3 convolution thus it is efficient for both CPU and GPU computing. In addition, the Sobel kernels are separable, which is  an additional optimization option.

Sobel-Feldman horizontal gradient with separable convolution
Sobel-Feldman vertical gradient with separable convolution

Each image pixel is processed by each kernel in order to produce the final gradient value using equation (2). Additionally to gain performance it is acceptable to use the sum of absolute directional values as in equation (3).

Gradient magnitude calculation

After calculating the vertical and horizontal gradients, we can also extract the edge orientation:

Gradient’s orientation

We must note, that usually the detection of edges creates thick contours of the object. In many cases, this is not very useful for object recognition and we need to apply additional processing.

To extract thin and strong edges of the image, we use the gradient magnitude and orientation. These parameters are sufficient to do edge thinning by non-maximum suppression.

Source code

Visit our free online Computer Vision Studio


Related articles