At the forefront of Artificial Intelligence
  Home Articles Reviews Interviews JDK Glossary Features Discussion Search
Home » Articles » Machine Vision » Beginner

An Introduction to Edge Detection: The Sobel Edge Detector

This article will introduce the basics of edge detection by looking at the simple (but effective) Sobel edge detector. Obviously, the first thing we need to ask is "What exactly is an edge?". If we look at the sample picture below and try to understand what an edge is it is quite easy to figure out. In a picture, an edge is normally defined as an abrupt change in colour intensity.

Of course, humans use a much more complicated method to find edges (so complex, we don't know how it works yet). This is because we have two eyes (therefore stereoscopic vision and depth perception) as well as our incredible inference skills (we can "see" the grey square above, despite it being obscured by the circle).

Despite this, most computer vision systems must do with one (normally greyscale) camera, so change in colour intensity is the next best thing! So, firstly let us look at the Sobel Edge Detector.

The Sobel Edge Detector

The Sobel Edge Detector uses a simple convolution kernel to create a series of gradient magnitudes. For those you of mathematically inclined, applying convolution K to pixel group p can be represented as:

For those of you not so mathematically inclined (like me!), there will be an essay dedicated to convolution soon. So the Sobel Edge Detector uses two convolution kernels, one to detect changes in vertical contrast (hx) and another to detect horizontal contrast (hy).

Here is what the Sobel kernels do to our example picture (inversed to provide better clarity):

The amazing thing is is that this data can now be represented as a vector (gradient vector). The two gradients computed using hx and hy can be regarded as the x and y components of the vector. Therefore we have a gradient magnitude and direction:

Where g is the gradient vector, g is the gradient magnitude and q is the gradient direction. All keen programmers will notice that it is probably more efficient to simple calculate the magnitude by adding the absolute squares - this is indeed what many implementation of the Sobel detector do. You can see that when Gx and Gy are large (big changes in the vertical and horizontal orientation respectively), the gradient magnitude will also be large. It is the gradient magnitudes that are finally plotted. Here is our example diagram passed through a Sobel detector (as generated by Image Analysis Explorer):

While it is subtle, you can how the intensity of the edge between the circle and the square is less than the intensity between the circle and the background.

To understand how the Sobel Edge Detector can pick out smaller details here is a composite picture. Below is a photograph I took in the Meiji Shrine in Tokyo - I have mixed the original photo with the result of the Sobel Edge detector to highlight the results (click for a larger picture).

Click for larger picture

Experiment with the Sobel edge detector by downloading Image Analysis Explorer and trying it with your pictures. You may also download these convolution kernels to try out. Make sure you unzip them to the IAE directory. Load them and use the "Convolution" function.

Problems with the Sobel Detector

There are a few problems with the Sobel algorithm that often need to be ironed out in field applications. Firstly, the Sobel detector is incredibly sensitive to noise in the picture. Most real-world pictures will have noise in them and the Sobel algorithm effectively highlights them as edges. This can yield horribly ineffective results:

Also, if you look at the detected edges, you will notice that they are quite thick. This can occur for a few reasons; one possibility is if the edge is one pixel thick, the Sobel detector will thicken it because there are two consecutive intensity changes.

The Canny edge detector solves these problems by firstly blurring the image slightly then applying an algorithm that effectively thins the edges to one-pixel. This will be covered later.


The Sobel edge detector is a great algorithm to learn the basics of edge detection. Make sure you fully understand how it works and why it has the limitations it does. For the programmers, IAE comes with complete source code so you can see the Sobel Edge Detection code in its respective filter.

Submitted: 27/01/2002

Article content copyright © James Matthews, 2002.
 Article Toolbar
BibTeX entry


Latest News
- The Latest (03/04/2012)
- Generation5 10-year Anniversary (03/09/2008)
- New Generation5 Design! (09/04/2007)
- Happy New Year 2007 (02/01/2007)
- Where has Generation5 Gone?! (04/11/2005)

What's New?
- Back-propagation using the Generation5 JDK (07/04/2008)
- Hough Transforms (02/01/2008)
- Kohonen-based Image Analysis using the Generation5 JDK (11/12/2007)
- Modelling Bacterium using the JDK (19/03/2007)
- Modelling Bacterium using the JDK (19/03/2007)

All content copyright © 1998-2007, Generation5 unless otherwise noted.
- Privacy Policy - Legal - Terms of Use -