EDGE_DETECTION_part2

advertisement
1. The Canny edge detector
Date: 07/16/04
For any edge detector, there is a trade –off between noise reduction and edge localization. The reduction is
typically achieved at the expense of good localization, and vice versa. The Canny edge detector can be shown to
provide the best possible compromise between these two conflicting requirements.
The mask we want to ue for edge detection should have certain desirable characteristics, called Canny’s criteria:
1. Good signal to noise ratio
2. Good locality, i.e the edge should be detected where it actually is.
3. Small number of false alarms, i.e. the maxima of the filter response should be mainly due to the
presence of the true edges in the image rather than to noise.
For the smoothing step, the Canny detector employs a Gaussian low pass filter. The standard deviation,
determines the width of the filter and hence the amount of smoothing. Let f(x,y) denote the input image. The
result from convolving the image with Gaussian smoothing filter using separable filtering is an array of
smoothed data,
S ( x, y )  G ( x, y ,  )  f ( x, y )
(1)
where is the spread of the Gaussian and controls the degree of smoothing.
The edge enhancement step simply involves calculation of the gradient vector at each pixel of the smoothed
image.
Consider the arrangement of the pixels 3 x 3 about the pixel (x,y). The x and y components of a gradient vector
are :
g x ( x, y)  S ( x  1, y)  S ( x  1, y) and g y ( x, y )  S ( x, y  1)  S ( x, y  1)
(2)
where the kernels are
 1 0 1
hx   1 0 1
 1 0 1
and
 1  1  1
h y   0 0 0 
 1 1 1 
(3)
The magnitude and orientation of the gradient can be also computed from the standard formulas
Magnitude( x, y )
 gy
 gx
  tan 1 
 g  g x2  g y2



Efficient implementation of the Canny detector combine the smoothing and enhancement steps by convolving
the image with derivative of Gaussian kernel.
The localization step has two stages: non-maximal suppression and hysteresis thresholding
To identify edges , the broad ridges in the magnitude array must be thinned so that only the magnitudes at the
points of greatest local change remain. As a result we receive a thinned edges.
Non maximal suppression thins the ridges of gradient magnitude in magnitude image area g(x,y) by suppressing
all values along the line of the gradient that are not peak values of a ridge .
The algorithm begins by reducing the angle of the gradient (x,y) to one of the four sectors shown in FIG . The
angle is converted to a direction from 0 to 8. 0 meaning no direction, 1 is from 0 to 45 degrees, and 2 through
eight follow counter clockwise.
 s  Sector[ ( x, y)] (4)
The basic idea is that edge pixel have a direction of associated with them. The magnitude of the gradient at an
edge pixel should be greater than the magnitude of the gradient of the pixels on each side of the edge.
The algorithm passes a 3x 3 neighborhood across the Magnitude array g(x,y)
At each point , the center element g(x,y) of the neighborhood is compared with its two neighbors along the
gradient direction. If the magnitude value at the center point is not greater than both of the neighbor magnitudes
along the gradient direction, then g(x,y) is set zero. The values for the height of the ridge are retained in the non
- maximal-suppressed magnitude.
.gsuppressed image = nms [g(x,y), s] (5)
For example :Figure shows a 3 x 3 region centered on an edge pixel, which in his case is vertical. The arrows
indicate the direction of the gradient at each pixel ( edge direction is perpendicular to direction of the gradient),
and the length of the arrows is proportional to the magnitude of the gradient . Here non-maximal suppression
means that the center pixel, the one under consideration must have a larger gradient magnitude than its
neighbors in the gradient direction; there are two pixels marked with an “x”. That is : for the center pixel, travel
in the direction of the gradient until another pixel is encountered . Now, again starting at the center pixel, travel
in the direction opposite to that of the gradient until another pixel is encountered; this is the second neighbor.
Moving from one of these to the other passes though the edge pixel in a direction that crosses the edge, so the
gradient magnitude should be largest at the edge pixel. In this specific case , the situation is clear. The direction
of the gradient is horizontal, and the neighboring pixels used in the comparison are exactly the left and right
neighbors.
x
Thresholding
The typical procedure used to reduce the number of false edge fragments in the non maximal suppressed
gradient magnitude is to apply a threshold to gsupressed image All values below the threshold are changed to zero.
We have noted already the problems associates with applying a single, fixed threshold to gradient maxima .
Choosing a low threshold ensures that we capture the weak yet meaningful edges in the image. Too high a
threshold , on the other hand, will lead to excessive fragmentation of the chains of pixels that represent
significant contours in the image. Hysteresis thresholding offers a solution to these problems It uses two
thresholds Tlow and Thigh , with Thigh =2 Tlow . Thigh is use to mark the best edge pixel candidates .
Canny edge detector
1. Smooth the image with a Gaussian filter
2. Compute the gradient magnitude and orientation using smoothed image and calculating
difference approximations for the partial derivatives.
3. Apply non - maxima suppression to the gradient magnitude.
4. Use the double thresholding algorithm to detect and link edges .
finite –
The effect of the Canny operator is determined by three parameters --- the width of the Gaussian kernel used in
the smoothing phase, and the upper and lower thresholds used by the tracker. Increasing the width of the
Gaussian kernel reduces the detector's sensitivity to noise, at the expense of losing some of the finer detail in the
image. The localization error in the detected edges also increases slightly as the Gaussian width is increased.
Usually, the upper tracking threshold can be set quite high, and the lower threshold quite low for good results.
Setting the lower threshold too high will cause noisy edges to break up. Setting the upper threshold too low
increases the number of spurious and undesirable edge fragments appearing in the output.
2. Unsharp Filter
The unsharp filter is a simple sharpening operator which derives its name from the fact that it enhances edges
(and other high frequency components in an image) via a procedure which subtracts an unsharp, or smoothed,
version of an image from the original image. The unsharp filtering technique is commonly used in the
photographic and printing industries for crispening edges.
How It Works
Unsharp masking produces an edge image
where
is a smoothed version of
from an input image
via
. (See Figure 1.)
Figure 1 Spatial sharpening.
We can better understand the operation of the unsharp sharpening filter by examining its frequency response
characteristics. If we have a signal as shown in Figure 2(a), subtracting away the lowpass component of that
signal (as in Figure 2(b)), yields the highpass, or `edge', representation shown in Figure 2(c).
Figure 2 Calculating an edge image for unsharp filtering.
This edge image can be used for sharpening if we add it back into the original signal, as shown in Figure 3.
Figure 3 Sharpening the original signal using the edge image.
Thus, the complete unsharp sharpening operator is shown in Figure 4.
Figure 4 The complete unsharp filtering operator.
We can now combine all of this into the equation:
where k is a scaling constant. Reasonable values for k vary between 0.2 and 0.7, with the larger values providing
increasing amounts of sharpening.
3. Adaptive Unsharp Masking
A powerful technique for sharpening images in the presence of low noise levels is via an adaptive filtering
algorithm. Here we look at a method of re-defining a highpass filter (such as the one shown in Figure 5) as the
sum of a collection of edge directional kernels.
Figure 5 Sharpening filter.
This filter can be re-written as
times the sum of the eight edge sensitive kernels shown in Figure 6.
Figure 6 Sharpening filter re-defined as eight edge directional kernels
Adaptive filtering using these kernels can be performed by filtering the image with each kernel, in turn, and then
summing those outputs that exceed a threshold. As a final step, this result is added to the original image. (See
Figure 7)
Figure 7 Adaptive
sharpening.
This use of a threshold makes the filter adaptive in the sense that it overcomes the directionality of any single
kernel by combining the results of filtering with a selection of kernels --- each of which is tuned to an edge
direction inherent in the image.
Edge detection - Conclusions
o
o
o

want to identify edges of scene objects
one step towards the recognition of objects in an image
typically comprises three steps:
 noise removal
 edge enhancement
 edge localization - which edges are meaningful?
Edge detection using the gradient of image gray levels
o think of the gray-level image as a height field
o first-order derivative gives you the slope of the surface
o first-order differentiation can be used to sharpen an image
o we can estimate the gradient in the x direction with
f(x+1, y) - f(x-1, y)
o
we can estimate the gradient in the y direction with
f(x, y+1) - f(x, y-1)
o
we take an average of these (which performs some smoothing) by performing convolution
Gx = hx * f(x,y)
Gy = hy * f(x,y)
o
Prewitt kernels give an average of the gradient in a 3 x 3 neighborhood
hx = -1 0 1
-1 0 1
-1 0 1
o
Sobel kernels give the on-axis pixels a higher weight
hx = -1 0 1
-2 0 2
-1 0 1
o
o
hy = -1 -1 -1
0 0 0
1 1 1
hy = -1 -2 -1
0 0 0
1 2 1
this pair of convolutions gives us a gradient vector at each pixel - an x gradient and a y gradient
from this we can compute the magnitude of the gradient vector
g = sqrt(gx2 + yx2)
o
or a less expensive estimate of the magnitude
g = |gx| +|gy|
o
and we can compute the angle of the gradient vector relative to the x axis
theta = tan-1(gy/gx)
o
o

one approach to edge localization is to threshold the gradient magnitude
thresholding of gradient magnitude has several problems
 diffuse boundaries may not be detected
 noise can generate very large gradient magnitudes
 the edges produced in the resulting edge map are wide lines
Edge localization using the Laplacian of image gray levels
o second-order derivative gives you the rate of change of the slope of the surface
o second-order differentiation can be used to localize edges
o localize the edge by finding the zero crossings of the second-order derivatives
o the Laplacian sums the second-order partial derivatives in the x and y directions
o a kernel which approximates the Laplacian is
0 -1 0
-1 4 -1
0 -1 0
o




Laplacian of Gaussian filter - combines this approach with a Gaussian kernel to remove noise
and detect edges
o Difference of Gaussian filter - approximates the Laplacian of Gaussian filter by subtracting two
Gaussians and is separable
Canny edge detector
o remove noise with a Gaussian low pass filter
o calculate gradient vector magnitude and angle at each pixel
o perform edge localization
 non-maximal suppression - thin the wide edges down to one pixel width
 look at neighbors of the pixel in the directions approximately parallel to the
gradient direction
 hysteresis thresholding - use two thresholds, t-high and t-low
 use t-high to mark pixels as edge candidates
 process edge candidates by looking for neighbors with gradient magnitude
greater than t-low
Implementation of kernels for gradient computation
o use with ConvolutionOp because output may be negative
o HorizontalPrewittKernel ; VerticalPrewittKernel ; HorizontalSobelKernel ; VerticalSobelKernel
Implementation of edge detection classes
o SobelEdgeOp - extends StandardGreyOp
o CannyEdgeOp - extends StandardGreyOp
DEMOS:
http://www.cs.washington.edu/research/imagedatabase/demo/edge/
http://www.ehere.com/eheretec/jip/wljipdemo4.html
Download