230 likes | 406 Views
Digital Image Processing Lecture 17: Segmentation: Canny Edge Detector & Hough Transform. Prof. Charlene Tsai. Review. Detection of discontinuity using 1 st derivative Providing gradient and magnitude Zero crossing (2 nd derivative using Laplacian) For edge location
E N D
Digital Image Processing Lecture 17: Segmentation: Canny Edge Detector & Hough Transform Prof. Charlene Tsai
Review • Detection of discontinuity using • 1st derivative • Providing gradient and magnitude • Zero crossing (2nd derivative using Laplacian) • For edge location • No gradient information • Sensitive to noise • Smoothing using Gaussian filter (LoG)
What is missing? • Q1: Is a pixel an edge element or not? • Canny Edge Detection • Q2: If the edge elements are not connect, how to establish the boundary between regions? • Hough Transform
Canny Edge Detector • Canny edge detector answers the first question. • Characteristics of the edge detector: • Low error rate -- finding all edges and nothing but edges. • Localization of edges – distance between edges found and actual edges should be minimized. • Single response – no multiple edge pixels when only a single edge exists.
Steps for Canny Edge Detector • Step 1: generating edge image. • Create 1D Gaussian filter g (for smoothing) • Create 1D filter dg (derivative of the Gaussian) • What for? • Convolve g with dg to obtain gdg. • Apply gdg to image x producing x1 • Apply gdg’ to image x producing x2 • Edge magnitude image is
(con’d) • Step 2: marking the edge element using non-maximum suppression • A pixel p is an edge if its magnitude is greater than its neighbors in direction (edge gradient) • Edge gradient image is
Non-maximum Suppression • See any difficulty with step2? • Qantization issue 45 degrees 135 degrees 0 degrees 90 degrees
(con’d) 67.5 to 112.5 112.5 to 157.5 22.5 to 67.5 0 to 22.5 157.5 to 180 Any edge direction falling within the yellow rangeis set to 0. Any edge direction falling in thegreen rangeis set to 45. Any edge direction falling in theblue rangeis set to 90 . And any edge direction falling within thered rangeis set to 135.
Hysteresis Thresholding (final step) • After non-max suppression, threshold to produce a binary edge image. • Hysteresis thresholding has two values: • Low value tL and • High value tH • Conditions under which p is marked as edge: • If xe(p) > tH, • If p is adjacent to an edge pixel, and
Edge Function in Matlab sensitivity thresholds • I intensity image, BW binary image • THRESH is a two-element vector in which the first element is the low threshold, and the second element is the high threshold. • The Canny method uses 2 thresholds, to detect strong and weak edges, and includes the weak edges in the output only if they are connected to strong edges. • This method is therefore less likely than the others to be "fooled" by noise, and more likely to detect true weak edges. BW = edge(I,'canny') BW = edge(I,'canny',thresh) BW = edge(I,'canny',thresh,sigma) Syntax smoothing
I = imread(‘Will.jpg’); bw = edge(I,'canny'); I = imread(‘Lena.tif’); bw = edge(I,'canny');
sigma A =edge(I,'canny',[], 1); B =edge(I,'canny',[], 2); C =edge(I,'canny',[], 3); D =edge(I,'canny',[], 4); E =[A B C D]; imshow(E)
Summary of Canny Algorithm The Canny Edge Detection Algorithm has the following steps: • Smooth the image with a Gaussian filter, • Compute the gradient magnitude and orientation using finite-difference approximations for the partial derivatives, • Apply non-maximum suppression to the gradient magnitude, • Use the double thresholding algorithm to detect and link edges.
Why is Canny so dominant? • Still widely used after 20 years. • Theory is nice (but end result same). • Details good (magnitude of gradient). • Hysteresis an important heuristic. • Code was distributed. • Perhaps this is about all you can do with linear filtering.
Hough Transform • Results of edge-detection methods may contain sparse points, instead of straight lines or curves. • Therefore, need to fit a line to the edge points. • Efficient solution: Hough Transform • Originally for finding lines • Easily varied to find other shapes
Simple Example • Consider a point (xi,yi) and the general equation of a straight line in slope-intercept form: • Q: How many lines may pass through (xi,yi)? • Re-writing the equation in ab-plane • How many lines do we get for a fixed (xi,yi)? intercept slope
Finding (a,b) • Now given another point (xj, yj), how to find the parameter (a’,b’) which defines the line that contains both points?
(con’d) • All points on this line have lines in parameter space that intersect at (a’,b’).
What is the problem? • How about a vertical line? • Gradient/slope is infinite • Need another parameterization scheme. Now consider r is the shortest distance from the line to the origin, and is the angle New parameterization:
Computation for Hough Transform • Choosing a discrete set of values of r and . • Construct an accumulator array, initialized with 0 for each entry. • Picture this process as a voting process rmin rmax r
(con’d) • For each edge point (x,y) in the image, • we compute for each • Increment the counter for the cell of the resulting (r, ) • At the end, the (r, ) with highest count correspond to strongest line in the image.