Building machines that see: Finding edges in images

With the emergence of increasingly capable low-cost processors and image sensors, it’s becoming practical to incorporate computer vision capabilities into a wide range of embedded systems, enabling them to analyze their environments via image and video inputs.

Products like Microsoft’s Kinect game controller and Mobileye’s driver assistance systems are raising awareness of the incredible potential of embedded vision technology. As a result, many embedded system designers are beginning to think about implementing embedded vision capabilities.

In this article, the second in a series, we introduce edge detection, one of the fundamental techniques of computer vision. Like many aspects of computer vision, edge detection sounds simple but turns out to be complex. We explore some of the common challenges and pitfalls associated with edge detection, and present techniques for addressing them. Then, after explaining edge detection from an algorithmic perspective, we show how to use OpenCV, a free open-source computer vision software component library, to quickly implement application software incorporating edge detection. For an overview of computer vision and OpenCV, read “Introduction to Embedded Vision and the OpenCV Library.”

What is an “Edge” in Computer Vision?

Images, of course, are made up of individual points called pixels. In a grayscale image, the value of each pixel represents the intensity of the light captured when creating the image. An edge is defined as an area of significant change in the image intensity. Figure 1 below shows a grayscale image on the left, with its corresponding binary edge map on the right. If you look carefully, you will notice that the white lines in the edge map delineate the portions of the image separated by pixels of different intensity.

Figure 1. Grayscale image and its corresponding binary edge map

If you graph the values of a single row of pixels containing an edge, the strength of the edge is shown by slope of the line in the graph. We use the term “hard” to describe an edge with a large difference between nearby pixel values, and “soft” to describe small differences in close-proximity pixel values.

Figure 2. Grayscale soft edge

Figure 2 above and Figure 3 below represent eight pixels from two different parts of a grayscale image. The numeric value for each pixel is shown above an expanded view of the actual pixel. Figure 2 represents a “soft” edge while Figure 3 represents a “hard” edge.

Figure 3. Grayscale hard edge

How edges are used in computer vision

The goal of a computer vision application is to extract meaning from images. In general, this objective is first accomplished by finding relevant features in the images. Edges are one type of image feature.

For example, edges can be used to find the boundaries of objects in an image, in order to enable isolating those objects for further processing. This process is known as “segmentation.” After an image is segmented, objects can be individually analyzed or discarded depending on what the application is trying to accomplish.

Unfortunately, in many applications, not all edges in an image actually represent separate objects, and not all objects are separated by clean edges. As mentioned earlier, edges are graded on a scale from no edge to “soft” edge, and finally to “hard” edge. Somewhere in the algorithm, a decision has to be made regarding whether a given edge is “hard” enough to be classified as a true edge versus, for example, just a small change in brightness due to lighting variation.