 
 


An Introduction to Edge Detection: The Sobel Edge DetectorThis 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 DetectorThe 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 (h_{x}) and another to detect horizontal contrast (h_{y}). 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 h_{x} and h_{y} 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). 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.
Problems with the Sobel DetectorThere 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 realworld 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 onepixel. This will be covered later.
ConclusionThe 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.


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