Você está na página 1de 24

Basic image processing: edge detection

Edge detection problem


Edge detection is sometimes an abused notion in image processing. Part of the complication lies in the diculty in dening precisely what is meant by an edge. A set of dierent examples of edges are shown below:

Gradient-based methods
Gradient-based methods are often used to nd edges in images. Consider for example a 1-D function f (x) the derivative f (x) = df dx

takes on values with a large magnitude at the points where the function has a high rate of change. It is reasonable to expect that these points will correspond to edges in the function. The generalisation of f (x) to a 2-D function f (x, y ) is the gradient f (x, y ) = f (x, y ) f (x, y ) ix + iy , x y

where ix and iy are unit vectors in the x and y directions respectively. The magnitude of f (x, y ) is rst computed, and is then compared to a threshold to nd candidate edge points.

Nondirectional edge detector


An edge detection system based on a function such as | f (x, y )| is called a nondirectional edge detector, since such functions favour no particular direction. However, if for example we use |f (x, y )/x| instead of | f (x, y )| then one obtains a directional edge detector, which in this case only detects edges in the vertical direction and does not respond to horizontal edges. For a 2-D sequence f (n1 , n2 ), the partial derivatives may be replaced by a discrete approximation such as f (x, y ) [f (n1 , n2 ) f (n1 1, n2 )]/T x or f (x, y ) [f (n1 + 1, n2 ) f (n1 1, n2 )]/(2T ). x

Convolution

Since the edge detection process involves comparing the computed derivatives to a threshold that can be adjusted, the scaling factors 1/T and 1/(2T ) can be omitted. This operation is equivalent to calculating edges by forming the convolution product between the function f (n 1 , n2 ) an impulse response of one of the forms

+1

+1

Horizontal gradient example


An example of an image and the estimated horizontal derivative is shown below:

50

50

100

100

150

150

200

200

250 50 100 150 200 250

250 50 100 150 200 250

Noise reduction
Derivatives calculated using the method described are typically quite noisy estimates of f (x, y )/x. This can be improved by averaging the derivative over several samples, for example f (x, y ) [f (n1 + 1, n2 + 1) f (n1 1, n2 + 1)] x + [f (n1 + 1, n2 ) f (n1 1, n2 )] + [f (n1 + 1, n2 1) f (n1 1, n2 1)]. This is equivalent to calculating the horizontal derivative by convolving with the kernel

+1 +1 +1

0 0 0

1 1 1

Horizontal gradient reduced noise


An example of applying this process to the previous image is shown below:

50

100

150

200

250 50 100 150 200 250

Operation

By the commutative properties of the convolution product we can smooth the image before calculating the derivatives, or calculate smoothed estimates of the derivative. In either case the required quantities can be obtained by convolving with a combined lter impulse response. Thus the dierencing operations described can be viewed as the convolution of f (n1 , n2 ) with the impulse response of a lter h(n1 , n2 ).

Standard edge detectors


Examples of common lters for detecting edges in the vertical and horizontal direction are Roberts: h1 = Prewitt: 1 0 1 h1 = 1 0 1 , 1 0 1 1 0 1 h1 = 2 0 2 , 1 0 1 1 1 1 0 0 . h2 = 0 1 1 1 1 2 1 0 0 . h2 = 0 1 2 1 0 1 , 1 0 h2 = 1 0 . 0 1

Sobel:

In these relationships h1 corresponds to a lter for detecting horizontal edges, and h2 vertical edges. The formulations dier in terms of their properties, and in some cases their computational complexity.

Nondirectional edge detectors

Nondirectional edge detectors can be developed using a discrete approximation to | f (x, y )|, such as | f (x, y )| = f (x, y ) x
2

f (x, y ) y

Clearly this just involves forming some combination of the edges in the horizontal and vertical directions.

Laplacian-based methods

The objective of an edge detection algorithm is to locate regions where the intensity is changing rapidly. For 1-D functions and gradient-based methods, f (x) is considered large when its magnitude |f (x)| is larger than a threshold. Another way is to assume |f (x)| large whenever it reaches a local extremum, or when f (x) has a zero crossing. Declaring zero-crossing points as edges results in a large number of points being declared edge points. Since the magnitude of f (x) is not considered, any small ripple in f (x, y ) generates a detected edge. Due to this sensitivity to noise, the application of noise reduction is a necessary prerequisite.

Estimating the Laplacian


A generalisation of 2 f (x)/x 2 to a 2-D function f (x, y ) for purposes of edge detection is the Laplacian
2

f (x, y ) =

( f (x, y )) =

2 f (x, y ) 2 f (x, y ) + . x 2 y 2

For a 2-D sequence f (n1 , n2 ) the partial derivatives can be replaced by some form of second-order dierences. As in the case of gradient-based methods, these dierences can be represented by a convolution of f (n1 , n2 ) with the impulse response of a lter h(n1 , n2 ). For example, approximating the derivative by f (x, y ) fx (n1 , n2 ) = f (n1 + 1, n2 ) f (n1 , n2 ), x the term 2 f (x, y )/x 2 can be approximated by 2 f (x, y ) fxx (n1 , n2 ) = fx (n1 , n2 ) fx (n1 1, n2 ) x 2 = f (n1 + 1, n2 ) 2f (n1 , n2 ) + f (n1 1, n2 ).

Estimating the Laplacian (2)

With the derivatives in the y -direction approximated similarly, the estimate of the Laplacian is
2

f (x, y ) fxx (n1 , n2 ) + fyy (n1 , n2 ) = f (n1 + 1, n2 ) + f (n1 1, n2 ) + f (n1 , n2 + 1) + f (n1 , n2 1) 4f (n1 , n2 ).

Laplacian edge detector example


An estimate of the Laplacian for the image shown previously is

50

100

150

200

250 50 100 150 200 250

Locating edges now involves nding zero crossings of this function.

Laplacian operators

Some examples of discrete Laplace operators are 1 1 1 0 1 0 h = 1 4 1 , h = 1 8 1 . 1 1 1 0 1 0

     

 

  

 

  

Perception of edges

Do you think that either of the two methods presented coincide with the way we perceive edges?

Edge linking

Obtaining an estimate of the image gradient is only part of the problem in edge detection, where the nal goal is a binary image indicating the presence of edges. There are many dierent ways of linking regions of high gradient into distinct edges.

Thinning
The simplest method is edge thinning, where the gradient is thresholded, and the resulting regions thinned down to single-pixel-wide closed, connected boundaries:

50

50

100

100

150

150

200

200

250 50 100 150 200 250

250 50 100 150 200 250

Hysteresis approach
This invariably leads to gaps in the edges, which often need to be lled to arrive at a useful edge representation. A very eective alternative is to use the Canny approach to edge linking, where (amongst other things) simple hysteresis is used during the linking of high-gradient ridges:

50

100

150

200

250 50 100 150 200 250

Example: Bottles
The methods described can be generalised to estimating the strength of edges in arbitrary specied directions. This was put to good use in a project where the goal was to identify Coca-cola bottles that had defects on the rim:

Example: Bottles (2)

Estimates of the vertical and horizontal edge gradients are shown below:

Example: Bottles (3)


Standard methods for locating the circular rim of the bottle were applied, and an edge direction mask of the following form was applied to the resulting edge estimates:

Example: Bottles (4)


In this way it was possible to nd the magnitude of the edge strength in a tangential direction.

It is then a relatively simple matter to identify anomalies in the rim prole. The method was used in an industrial system, and runs in about 15ms on a fast PC.

Você também pode gostar