Edge Detection

Learn how to detect edges in an image.

What is edge detection?

Edge detection is a handy function in image processing. Edge detection means identifying where the boundariesof an object in an image are. The algorithm looks for things like changes in color and brightness to find the edges. Dr. John Canny authored “A Variational Approach to Edge Detection” and is the creator of the widely used Canny edge detector. We’ll be using his algorithm below.

Let’s start with the given code widget. The first argument is the image in line 8 of the code widget. Next, we’re going to convert it to grayscale as we did in the previous lesson. After that, we’ll blur it as we can see in line 14 of the code. Next in line 16, we’ll do something new.

Using Canny edge detection

The function for Canny edge detection is, unsurprisingly, called Canny(). It takes three arguments:

  1. The first is the image.

  2. The second is the lower threshold.

  3. The third is the upper threshold.

The Canny edge detector detects edges by looking at the difference in pixel intensities. For the first example below, we’re using low thresholds of 10 and 30. This entails that many thresholds will be detected.

Get hands-on with 1200+ tech skills courses.