Bookmark and Share

ARM Guide to OpenCL Optimizing Canny Edge Detection: Theory

Register or sign in to access the Embedded Vision Academy's free technical training content.

The training materials provided by the Embedded Vision Academy are offered free of charge to everyone. All we ask in return is that you register, and tell us a little about yourself so that we can understand a bit about our audience. As detailed in our Privacy Policy, we will not share your registration information, nor contact you, except with your consent.

Registration is free and takes less than one minute. Click here to register, and get full access to the Embedded Vision Academy's unique technical training content.

If you've already registered, click here to sign in.

See a sample of this page's content below:

This chapter describes the theory of Canny edge detection.


This stage blurs the source image to remove noise. Without this step, individual pixels which are significantly different from their neighbors would appear as edges.

Blurring reduces the inconsistent effect from random noise by applying a weighted average effect to each pixel, which uses the values from nearby pixels to reduce noise.

A 2D Gaussian matrix convolution operation is used to apply this effect. You can use any size of Gaussian matrix, however for high performance and a good result, a 5 x 5 matrix is recommended. The ideal size of the Gaussian matrix that suits your application might be different, depending on the application using Canny edge detection. The size of the matrix and the coefficients that are used to blur the image affect the smoothness of the result.

The following figure shows the Gaussian 5 x 5 convolution matrix.

Figure 2-1 The 5 x 5 Gaussian convolution matrix

The following figure shows the effect of the Gaussian 5 x 5 convolution matrix on an image.

Figure 2-2 Blur stage input and result

Gradient analysis

The gradient of each dimension, x and y, of the image must be calculated. The results for each dimension must then be combined to show the overall gradient magnitude of the image at each pixel and the direction of change.

This stage uses another convolution matrix type, called the Sobel filter. This is normally performed using two 3 x 3 convolution matrices. Each matrix calculates a partial differential in its given direction to obtain the gradient in that direction, either x or y.

The following figure shows the Sobel horizontal matrix.

Figure 2-3 Sobel horizontal convolution matrix

The following figure shows the Sobel vertical matrix.

Figure 2-4 Sobel vertical convolution matrix

The results from these matrices are combined together to create a total gradient magnitude and direction. The following equation determines the gradient magnitude, magnitude = sqrt(x...