Edge Detection
Image segmentation is an important task in image analysis. Its goal is to separate objects of interest from the image background. Since objects often differ from the background in color or brightness, segmentation can frequently be based on detecting object boundaries.
These boundaries correspond to edges—locations in the image where the color or brightness function changes significantly. Therefore, edges can be detected by analyzing derivatives of the image intensity function (see Fig. 1).
In this exercise, you will implement three basic edge-detection methods.
Fig. 1: The brightness function and its first and second derivatives.
First Derivative
As shown in Fig. 1, the absolute value of the first derivative is high at locations where an edge occurs.
The edge response can therefore be estimated using the derivatives
which describe changes in the brightness function in the and directions.
Since digital images are discrete, the derivatives are approximated by finite differences:
The edge magnitude is then computed as
Compute this value for every image pixel. If is greater than a chosen threshold, the pixel is considered to belong to an edge.
The result of this method, normalized for visualization, is shown in Fig. 4 (top right).
Second Derivative
Figure 1 also illustrates how an edge can be detected using the second derivative. Around an edge, the second derivative typically reaches a positive and a negative extremum, and the zero crossing between them indicates the edge location.
For this purpose, the Laplacian operator can be used.
As before, the brightness function is analyzed in the and directions:
The Laplacian is defined as
Because the image domain is discrete, the second derivatives are approximated using finite differences:
Substituting these expressions into the Laplacian gives
The result of this method, normalized for visualization, is shown in Fig. 4 (bottom left).
Sobel Operator
The Sobel operator is also based on differences between pixel values in the and directions. However, instead of using only two neighboring pixels, it estimates the edge response from a neighborhood.
The labeling of neighboring pixels is shown in Fig. 2.
Fig. 2: Labeling of neighboring image pixels.
The Sobel kernels for the and directions are shown in Fig. 3.
Fig. 3: Sobel kernels for the and directions.
Using the labels from Fig. 2, the horizontal and vertical responses are computed as
These formulas can be represented by convolution kernels, as shown in Fig. 3. Therefore, the Sobel response can be computed using image convolution.
The edge magnitude can then be obtained in the same way as for the first-derivative method:
The result of the Sobel operator is shown in Fig. 4 (bottom right).
Fig. 4: Input image (top left); edges detected using the first derivative (top right), the second derivative (bottom left), and the Sobel operator (bottom right).