Finding the Edge: Canny and Sobel Edge Detectors (Part 1)

Saisha
SRM MIC
Published in
4 min readSep 6, 2020

While working on a project for Real-Time Road Lane Detection, I sat down to learn about various edge detection techniques. I came across some rather fascinating algorithms called “Canny Edge Detection and Sobel Edge Operator”. In the spirit of reinforcing my understanding by explaining, I decided to cover the topic: What are Canny and Sobel Edge Detectors, and how do they work?

The Canny Edge Detector is an edge detection operator that is used to detect a wide range of edges in images. It uses a multi-stage algorithm to do so.

The Canny edge detector applied to a color photograph of a steam engine.
The original image -https://en.wikipedia.org/wiki/Canny_edge_detector

The Sobel operator is used in image processing and computer vision, particularly within edge detection algorithms where it creates an image emphasising edges.

The Sobel operator applied to that image-https://en.wikipedia.org/wiki/Sobel_operator

Edge detection is simply the case of finding regions in an image, where we have a sharp change in intensity. These changes happen between the boundaries of an object in the image, what we’d refer to as an “edge” in 3d space, and so the terminology carries over to an image as well.

The process of edge detection is carried out in three simple steps i.e image smoothening, edge point detection and edge localisation. We will see these steps applied to the canny as well as the sobel edge detector as we move on with this article.

The Canny Edge Detector was published in 1986 by John F.Canny. It is a technique that is used to extract the structural information from various vision objects and reduce significantly the amount of data that is to be processed. It has been widely used in computer vision systems.

The Sobel Edge Operator is named after Irwin Sobel and Gary Feldman, who presented the idea of an “Isotropic 3x3 Image Gradient Operator” at a talk at SAIL(Stanford Artificial Intelligence Laboratory) in 1968. This method calculates the approximate gradient of the image intensity at each point of an image by convolution with an integer value filter.

There are many other edge detection operators such as Sobel, Prewitt, Laplacian, etc. Out of these algorithms, efficiency of Canny and Sobel edge detection algorithms is higher than other algorithms.

Canny Edge Operator handily produces an orientation at every point which can be very useful for the post-processing of the image. The Canny edge detector takes the Sobel edge operator and makes it just a step better. What I mean by that is, we can get rid of the edges which we aren’t interested in and keep only the ones that are useful to us. Canny works by taking the output image of the Sobel Operator and thinning the edges so that they are just 1 pixel wide.

So let me first start by briefing you about the Sobel Edge Operator.

In the Sobel Edge Detector, the image is processed in both the X and Y directions. This forms a new image which would be the sum of X and Y edges of the image. Keep in mind that these can be processed separately as well.

We start off by converting the image from an RGB scale to a Grayscale image. Then from there, we shall use what is called kernel convolution. There are various pairs of Sobel operators such as 3×3, 5x5 convolution.

In this case, I shall refer to a kernel (3x3) matrix, consisting of differently weighted indexes. This will represent the filter that we will be implementing for edge detection.

When we want to scan across the X direction of an image, for example, we will want to use the following X Direction Kernel to scan for large changes in the gradient and vice versa.

The two kernels-https://www.projectrhea.org/rhea/index.php/An_Implementation_of_Sobel_Edge_Detection

The kernels applied to the input image, produce separate gradient component measurements in each orientation (Gx and Gy). The magnitude of the gradient at every pixel and the direction of the gradient is computed by combining Gx and Gy together.

Absolute magnitude of the gradient-https://file.scirp.org/Html/5-9301774_42100.htm

A pictorial representation below will explain what i stated above wrt X and Y direction.

X and Y direction images-https://www.projectrhea.org/rhea/index.php/An_Implementation_of_Sobel_Edge_Detection

The image below is when the two filter results are added together to create an accurate representation of all of the edges (X and Y Direction) in the image.

The final image-https://www.projectrhea.org/rhea/index.php/An_Implementation_of_Sobel_Edge_Detection

There is tons more to discuss, but it’ll be a bit too much for a single article, so I have decided to make it a two part series. We’ll be getting into the comparisons of the two filters, a little more of the math behind it, and finally the code for it. Stay tuned for part two!

--

--