



Image analysis deals with techniques for extracting information from images. The first step is generally to segment an image. Segmentation divides an image into its constituent parts or objects. For example in a military air-to-ground target acquisition application one may want to identify tanks on a road. The first step is to segment the road from the rest of the image and then to segment objects on the road for possible identification. Segmentation algorithms are usually based on one of two properties of gray-level values: discontinuity and similarity. For discontinuity, the approach is to partition an image based on abrupt changes in gray level. Objects of interest are isolated points, lines, and edges.
An edge is the boundary between two regions with relatively distinct gray-level properties. The idea underlying most edge-detection techniques is the computation of a relative derivative operator. The figure below illustrates this concept. The picture on the right shows an image of a light stripe on a dark background, the gray-level profile of a horizontal scan line, and the first and second derivatives of the profile. The first derivative is positive when the image changes from dark to light and zero where the image is constant. The second derivative is positive for the part of the transition associated with the dark side of the edge and negative for the transition associated with the light side of the edge. Thus the magnitude of the first derivative can be used to detect the presence of an edge in the image and the sign of the second derivative can be used to detect whether a pixel lies on the light or dark side of the edge.

We will use two dimensional spatial masks to find lines of different directions in an image. The mask is similar to the filters used in part 2 of this lab except that it operates in two dimensions. The mask is centered upon each pixel in the image and the following weighted calculation is performed (x is the original image pixels, y is the output):

Mask:
| w_1 | w_2 | w_3 |
| w_4 | w_5 | w_6 |
| w_7 | w_8 | w_9 |
The masks shown below respond more strongly to lines of different directions in an image. The first mask would respond very strongly to horizontal lines with a thickness of one pixel. The maximum response would occur when line passed through the middle row of the mask. The direction of a mask can be established by noting that the preferred direction is weighted with a larger coefficient that the other possible directions.
(a)
|
(b)
|
(c)
|
(d)
|
>wa=[-1,-1,-1,2,2,2;-1,-1,-1];
>y_a=spfilt(cicada,wa);
>y_a=round(y_a);
>imagesc(y_a);colormap('gray(256)');
The gradient of an image is the vector, del(f) shown below. The gradient vector points to the direction of maximum rate of change of f at (x,y). In edge detection the important quantity is the magnitude of this vector which is usually referred to as the "gradient." The gradient is the maximum rate of increase of f(x,y) per unit distance in the direction of the gradient vector. This vector is commonly approximated with absolute values as shown below.

Derivatives may be implemented in digital form in many different ways. The Sobel operators given below provide a differentiating and smoothing effect. Computation of the gradient at the location at the center of the masks using the equations given below gives the value of the gradient. To get the next value the mask is moved to the next pixel location and the procedure is repeated.

Gx
|
Gy
|
>G_x=[-1,-2,-1;0,0,0;1,2,1]; >f_x=spfilt(f,G_x);%gradient in the x direction >G_y=[-1,0,1;-2,0,2;-1,0,1]; >f_y=spfilt(f,G_y);%gradient in the y direction >grad=uint8(round(abs(double(f_x)+abs(double(f_y))));% calculates the gradient >imagesc([f,f_x;f_y,grad]);%displays all four images together
The material in this lab is based on section 7.1 of the book Digital Image Processing, by R. C. Gonzalez and R. E. Woods, Addison-Wesley:Reading, MA, 1992.