Presentation is loading. Please wait.

Presentation is loading. Please wait.

Edge Detection Edge detection Convert a 2D image into a set of curves Extracts salient features of the scene More compact than pixels.

Similar presentations


Presentation on theme: "Edge Detection Edge detection Convert a 2D image into a set of curves Extracts salient features of the scene More compact than pixels."— Presentation transcript:

1

2 Edge Detection

3 Edge detection Convert a 2D image into a set of curves Extracts salient features of the scene More compact than pixels

4 Origin of Edges Edges are caused by a variety of factors depth discontinuity surface color discontinuity illumination discontinuity surface normal discontinuity

5 Edge detection How can you tell that a pixel is on an edge?

6 Profiles of image intensity edges

7 Edge detection 1.Detection of short linear edge segments (edgels) 2.Aggregation of edgels into extended edges (maybe parametric description)

8 Edgel detection Difference operators Parametric-model matchers

9 Edge is Where Change Occurs Change is measured by derivative in 1D Biggest change, derivative has maximum magnitude Or 2 nd derivative is zero.

10 Edge Detection Gradient operators Roberts Prewitt Sobel Gradient of Gaussian (Canny) Laplacian of Gaussian (Marr-Hildreth) Facet Model Based Edge Detector (Haralick) Possible detectors:

11 Edge Detection Using the Gradient Definition of the gradient: To save computations, the magnitude of gradient is usually approximated by:

12 Image gradient The gradient of an image: The gradient points in the direction of most rapid change in intensity The gradient direction is given by: how does this relate to the direction of the edge? The edge strength is given by the gradient magnitude

13 Edge Detection Using the Gradient Properties of the gradient: The magnitude of gradient provides information about the strength of the edge The direction of gradient is always perpendicular to the direction of the edge Main idea: Compute derivatives in x and y directions Find gradient magnitude Threshold gradient magnitude

14 Edge Detection Using the Gradient Estimating the gradient with finite differences Approximation by finite differences:

15 Edge Detection Using the Gradient Using pixel-coordinate notation (remember: j corresponds to the x direction and i to the negative y direction):

16 Edge Detection Using the Gradient Example: Suppose we want to approximate the gradient magnitude at z 5 We can implement  I/  x and  I/  y using the following masks: Note: M x is the approximation at (i, j + 1/2) and M y is the approximation at (i + 1/2, j)

17 Edge Detection Using the Gradient The Roberts edge detector This approximation can be implemented by the following masks: Note: M x and M y are approximations at (i + 1/2, j + 1/2)

18 Edge Detection Using the Gradient The Prewitt edge detector The partial derivatives can be computed by: Note: M x and M y are approximations at (i, j)) Consider the arrangement of pixels about the pixel (i, j): The constant c implies the emphasis given to pixels closer to the center of the mask. Setting c = 1, we get the Prewitt operator:

19 Edge Detection Using the Gradient The Sobel edge detector Note: M x and M y are approximations at (i, j)) Setting c = 2, we get the Sobel operator:

20 Edge Detection Using the Gradient Main steps in edge detection using masks:

21 Edge Detection Using the Gradient (an example using the Prewitt edge detector - don’t divide by 2)

22 Edge Detection Using the Gradient Example:

23 Edge Detection Using the Gradient Example – cont.:

24 Edge Detection Using the Gradient Example – cont.:

25 Edge Detection Using the Gradient

26

27 Isotropic property of gradient magnitude: The magnitude of gradient is an isotropic operator (it detects edges in any direction !!)

28 The discrete gradient How can we differentiate a digital image f[x,y]? Option 1: reconstruct a continuous image, then take gradient Option 2: take discrete derivative (finite difference) How would you implement this as a cross-correlation?

29 The Sobel operator Better approximations of the derivatives exist The Sobel operators below are very commonly used 01 -202 01 121 000 -2 The standard defn. of the Sobel operator omits the 1/8 term –doesn’t make a difference for edge detection –the 1/8 term is needed to get the right gradient value, however

30 Basic Relationship of Pixels x y (0,0) Conventional indexing method (x,y)(x,y)(x+1,y)(x-1,y) (x,y-1) (x,y+1) (x+1,y-1)(x-1,y-1) (x-1,y+1)(x+1,y+1)

31 Neighbors of a Pixel p (x+1,y) (x-1,y) (x,y-1) (x,y+1) 4-neighbors of p: N 4 (p) = (x  1,y) (x+1,y) (x,y  1) (x,y+1) Neighborhood relation is used to tell adjacent pixels. It is useful for analyzing regions. Note: q  N 4 (p) implies p  N 4 (q) 4-neighborhood relation considers only vertical and horizontal neighbors.

32 p(x+1,y)(x-1,y) (x,y-1) (x,y+1) (x+1,y-1)(x-1,y-1) (x-1,y+1)(x+1,y+1) Neighbors of a Pixel (cont.) 8-neighbors of p: (x  1,y  1) (x,y  1) (x+1,y  1) (x  1,y) (x+1,y) (x  1,y+1) (x,y+1) (x+1,y+1) N 8 (p) = 8-neighborhood relation considers all neighbor pixels.

33 p (x+1,y-1)(x-1,y-1) (x-1,y+1)(x+1,y+1) Diagonal neighbors of p: N D (p) = (x  1,y  1) (x+1,y  1) (x  1,y  1) (x+1,y+1) Neighbors of a Pixel (cont.) Diagonal -neighborhood relation considers only diagonal neighbor pixels.

34 Template, Window, and Mask Operation Sometime we need to manipulate values obtained from neighboring pixels Example: How can we compute an average value of pixels in a 3x3 region center at a pixel z? 4 4 67 6 1 9 2 2 2 7 5 2 26 4 4 5 212 1 3 3 4 2 9 5 7 7 358222 Pixel z Image

35 Template, Window, and Mask Operation (cont.) 4 4 67 6 1 9 2 2 2 7 5 2 26 4 4 5 212 1 3 3 4 2 9 5 7 7 358222 Pixel z Step 1. Selected only needed pixels 4 67 6 9 1 3 3 4 …… … …

36 4 67 6 9 1 3 3 4 …… … … Template, Window, and Mask Operation (cont.) Step 2. Multiply every pixel by 1/9 and then sum up the values 11 1 1 1 1 1 1 1 X Mask or Window or Template

37 Template, Window, and Mask Operation (cont.) Question: How to compute the 3x3 average values at every pixels? 4 4 67 6 1 9 2 2 2 7 5 2 26 4 4 5 212 1 3 3 4 2 9 5 7 7 Solution: Imagine that we have a 3x3 window that can be placed everywhere on the image Masking Window

38 4.3 Template, Window, and Mask Operation (cont.) Step 1: Move the window to the first location where we want to compute the average value and then select only pixels inside the window. 4 4 67 6 1 9 2 2 2 7 5 2 26 4 4 5 212 1 3 3 4 2 9 5 7 7 Step 2: Compute the average value Sub image p Original image 41 9 2 2 3 2 9 7 Output image Step 3: Place the result at the pixel in the output image Step 4: Move the window to the next location and go to Step 2

39 Template, Window, and Mask Operation (cont.) The 3x3 averaging method is one example of the mask operation or Spatial filtering.  The mask operation has the corresponding mask (sometimes called window or template).  The mask contains coefficients to be multiplied with pixel values. w(2,1)w(3,1) w(3,3) w(2,2) w(3,2) w(1,1) w(1,2) w(3,1) Mask coefficients 11 1 1 1 1 1 1 1 Example : moving averaging The mask of the 3x3 moving average filter has all coefficients = 1/9

40 Template, Window, and Mask Operation (cont.) The mask operation at each point is performed by: 1. Move the reference point (center) of mask to the location to be computed 2. Compute sum of products between mask coefficients and pixels in subimage under the mask. p(2,1) p(3,2)p(2,2) p(2,3) p(2,1) p(3,3) p(1,1) p(1,3) p(3,1) …… … … Subimage w(2,1)w(3,1) w(3,3) w(2,2) w(3,2) w(1,1) w(1,2) w(3,1) Mask coefficients Mask frame The reference point of the mask

41 Template, Window, and Mask Operation (cont.) The mask operation on the whole image is given by: 1.Move the mask over the image at each location. 2.Compute sum of products between the mask coefficeints and pixels inside subimage under the mask. 3.Store the results at the corresponding pixels of the output image. 4.Move the mask to the next location and go to step 2 until all pixel locations have been used.

42 Template, Window, and Mask Operation (cont.) Examples of the masks Sobel operators 01 1 0 0 2 -2 -2 1 0 2 0 0 1 11 1 1 1 1 1 1 1 3x3 moving average filter 8 3x3 sharpening filter

43 Gradient operators (a): Roberts’ cross operator (b): 3x3 Prewitt operator (c): Sobel operator (d) 4x4 Prewitt operator

44 Effects of noise Consider a single row or column of the image Plotting intensity as a function of position gives a signal Where is the edge?

45 Solution: smooth first Look for peaks in

46 Derivative theorem of convolution This saves us one operation:

47 Laplacian of Gaussian Consider Laplacian of Gaussian operator Where is the edge?Zero-crossings of bottom graph

48 2D edge detection filters is the Laplacian operator: Laplacian of Gaussian Gaussianderivative of Gaussian

49 Edge Detection Practical issues: Differential masks act as high-pass filters – tend to amplify noise. Reduce the effects of noise - first smooth with a low-pass filter. The noise suppression-localization tradeoff a larger filter reduces noise, but worsens localization (i.e., it adds uncertainty to the location of the edge) and vice-versa.

50 Edge Detection How should we choose the threshold?

51 Edge Detection Edge thinning and linking required to obtain good contours

52 Edge Detection Good detection: the optimal detector must minimize the probability of false positives (detecting spurious edges caused by noise), as well as that of false negatives (missing real edges) Good localization: the edges detected must be as close as possible to the true edges. Single response constraint: the detector must return one point only for each true edge point; that is, minimize the number of local maxima around the true edge Criteria for optimal edge detection:

53 Edge Detection Examples: True edge Poor robustness to noise Poor localization Too many responses

54 The Canny Edge Detector This is probably the most widely used edge detector in computer vision. Canny has shown that the first derivative of the Gaussian closely approximates the operator that optimizes the product of signal-to-noise ratio and localization. His analysis is based on "step-edges" corrupted by "additive Gaussian noise". The Canny edge detector:

55 The Canny Edge Detector

56 The derivative of the Gaussian:

57 The Canny Edge Detector Canny – smoothing and derivatives:

58 The Canny Edge Detector Canny – gradient magnitude: imagegradient magnitude

59 Edge Detection To find the edge points, we need to find the local maxima of the gradient magnitude. Broad ridges must be thinned so that only the magnitudes at the points of greatest local change remain. All values along the direction of the gradient that are not peak values of a ridge are suppressed. Non-maxima suppression

60 Edge Detection Non-maxima suppression – cont.

61 Edge Detection Non-maxima suppression – cont. What are the neighbors? –Look along gradient normal Quantization of normal directions: 0 1 2 3

62 Edge Detection Canny – Non-maxima suppression: gradient magnitudethinned

63 Edge Detection The output of non-maxima suppression still contains the local maxima created by noise. Can we get rid of them just by using a single threshold? –if we set a low threshold, some noisy maxima will be accepted too. –if we set a high threshold, true maxima might be missed (the value of true maxima will fluctuate above and below the threshold, fragmenting the edge). Hysteresis thresholding / Edge linking A more effective scheme is to use two thresholds: –a low threshold t l –a high threshold t h –usually, t h ≈ 2t l

64 Optimal Edge Detection: Canny Assume: Linear filtering Additive iid Gaussian noise Edge detector should have: Good Detection. Filter responds to edge, not noise. Good Localization: detected edge near true edge. Single Response: one per edge.

65 Optimal Edge Detection: Canny (continued) Optimal Detector is approximately Derivative of Gaussian. Detection/Localization trade-off More smoothing improves detection And hurts localization. This is what you might guess from (detect change) + (remove noise)

66 The Canny edge detector original image (Lena)

67 The Canny edge detector norm of the gradient

68 The Canny edge detector thresholding

69 The Canny edge detector thinning (non-maximum suppression)

70 Non-maximum suppression Check if pixel is local maximum along gradient direction requires checking interpolated pixels p and r

71 Predicting the next edge point Assume the marked point is an edge point. Then we construct the tangent to the edge curve (which is normal to the gradient at that point) and use this to predict the next points (here either r or s). (Forsyth & Ponce)

72 Hysteresis Check that maximum value of gradient value is sufficiently large drop-outs? use hysteresis –use a high threshold to start edge curves and a low threshold to continue them.

73 Effect of  (Gaussian kernel size) Canny with original The choice of depends on desired behavior large detects large scale edges small detects fine features

74 (Forsyth & Ponce) Scale Smoothing Eliminates noise edges. Makes edges smoother. Removes fine detail.

75

76 fine scale high threshold

77 coarse scale, high threshold

78 coarse scale low threshold

79 Scale space (Witkin 83) Properties of scale space (w/ Gaussian smoothing) edge position may shift with increasing scale (  ) two edges may merge with increasing scale an edge may not split into two with increasing scale larger Gaussian filtered signal first derivative peaks

80 Edge detection by subtraction original

81 Edge detection by subtraction smoothed (5x5 Gaussian)

82 Edge detection by subtraction smoothed – original (scaled by 4, offset +128) Why does this work? filter demo

83 Gaussian - image filter Laplacian of Gaussian Gaussian delta function

84 An edge is not a line... How can we detect lines ?

85 Finding lines in an image Option 1: Search for the line at every possible position/orientation What is the cost of this operation? Option 2: Use a voting scheme: Hough transform

86 Finding lines in an image Connection between image (x,y) and Hough (m,b) spaces A line in the image corresponds to a point in Hough space To go from image space to Hough space: –given a set of points (x,y), find all (m,b) such that y = mx + b x y m b m0m0 b0b0 image spaceHough space

87 Finding lines in an image Connection between image (x,y) and Hough (m,b) spaces A line in the image corresponds to a point in Hough space To go from image space to Hough space: –given a set of points (x,y), find all (m,b) such that y = mx + b What does a point (x 0, y 0 ) in the image space map to? x y m b image spaceHough space –A: the solutions of b = -x 0 m + y 0 –this is a line in Hough space x0x0 y0y0

88 Hough transform algorithm Typically use a different parameterization d is the perpendicular distance from the line to the origin  is the angle this perpendicular makes with the x axis Why?

89 Hough transform algorithm Typically use a different parameterization d is the perpendicular distance from the line to the origin  is the angle this perpendicular makes with the x axis Why? Basic Hough transform algorithm 1.Initialize H[d,  ]=0 2.for each edge point I[x,y] in the image for  = 0 to 180 H[d,  ] += 1 3.Find the value(s) of (d,  ) where H[d,  ] is maximum 4.The detected line in the image is given by What’s the running time (measured in # votes)?

90 Extensions Extension 1: Use the image gradient 1.same 2.for each edge point I[x,y] in the image compute unique (d,  ) based on image gradient at (x,y) H[d,  ] += 1 3.same 4.same What’s the running time measured in votes? Extension 2 give more votes for stronger edges Extension 3 change the sampling of (d,  ) to give more/less resolution Extension 4 The same procedure can be used with circles, squares, or any other shape

91 Extensions Extension 1: Use the image gradient 1.same 2.for each edge point I[x,y] in the image compute unique (d,  ) based on image gradient at (x,y) H[d,  ] += 1 3.same 4.same What’s the running time measured in votes? Extension 2 give more votes for stronger edges Extension 3 change the sampling of (d,  ) to give more/less resolution Extension 4 The same procedure can be used with circles, squares, or any other shape

92 Hough Transform for Curves The H.T. can be generalized to detect any curve that can be expressed in parametric form: Y = f(x, a1,a2,…ap) a1, a2, … ap are the parameters The parameter space is p-dimensional The accumulating array is LARGE!

93 Generalizing the H.T. The H.T. can be used even if the curve has not a simple analytic form! 1.Pick a reference point (x c,y c ) 2.For i = 1,…,n : 1.Draw segment to P i on the boundary. 2. Measure its length r i, and its orientation  i. 3.Write the coordinates of (x c,y c ) as a function of r i and  i 4.Record the gradient orientation  i at P i. 3.Build a table with the data, indexed by  i. (x c,y c ) iiii riririri PiPiPiPi iiii x c = x i + r i cos(  i ) y c = y i + r i sin(  i )

94 Generalizing the H.T. (x c,y c ) PiPiPiPi iiii riririri iiii x c = x i + r i cos(  i ) y c = y i + r i sin(  i ) Suppose, there were m different gradient orientations: (m <= n) 1122......mm1122......mm... (r 1 1,  1 1 ),(r 1 2,  1 2 ),…,(r 1 n1,  1 n1 ) (r 2 1,  2 1 ),(r 2 2,  1 2 ),…,(r 2 n2,  1 n2 )... (r m 1,  m 1 ),(r m 2,  m 2 ),…,(r m nm,  m nm ) jjjj rjrjrjrj jjjj H.T. table

95 Generalized H.T. Algorithm: x c = x i + r i cos(  i ) y c = y i + r i sin(  i ) Finds a rotated, scaled, and translated version of the curve: (x c,y c ) PiPiPiPi iiii Sr i iiii  PjPjPjPj jjjj Sr j jjjj  PkPkPkPk iiii Sr k kkkk  1.Form an A accumulator array of possible reference points (x c,y c ), scaling factor S and Rotation angle . 2.For each edge (x,y) in the image: 1.Compute  (x,y) 2.For each (r,  ) corresponding to  (x,y) do: 1.For each S and  : 1.x c = x i + r(  ) S cos[  (  ) +  ] 2.y c = y i + r(  ) S sin[  (  ) +  ] 3.A(x c,y c,S,  ) ++ 3.Find maxima of A.

96 H.T. Summary H.T. is a “voting” scheme points vote for a set of parameters describing a line or curve. The more votes for a particular set the more evidence that the corresponding curve is present in the image. Can detect MULTIPLE curves in one shot. Computational cost increases with the number of parameters describing the curve.

97 Corners contain more edges than lines. A point on a line is hard to match. Corner detection

98 Corners contain more edges than lines. A corner is easier

99 Edge Detectors Tend to Fail at Corners

100 Finding Corners Intuition: Right at corner, gradient is ill defined. Near corner, gradient has two different values.

101 Formula for Finding Corners We look at matrix: Sum over a small region, the hypothetical corner Gradient with respect to x, times gradient with respect to y Matrix is symmetric WHY THIS?

102 First, consider case where: This means all gradients in neighborhood are: (k,0) or (0, c) or (0, 0) (or off-diagonals cancel). What is region like if:    and   and 

103 General Case: From Linear Algebra, it follows that because C is symmetric: With R a rotation matrix. So every case is like one on last slide.

104 So, to detect corners Filter image. Compute magnitude of the gradient everywhere. We construct C in a window. Use Linear Algebra to find  and  If they are both big, we have a corner.

105 10. Convolution-based Edge Detection Why do edge detection? What is an edge? What is a good edge? How do you find an edge?

106 Laplacian

107 Why Laplacian? because it is zero when the rate of intensity change in the image plane is zero or linear.

108 Log filters=prefilter+laplacian

109 Mexican Hat (LoG Kernel)

110 The Log kernel

111 Oriented Filters are steerable

112 Changing Scale at 0 Degrees

113 Changing Phase at 0 degrees


Download ppt "Edge Detection Edge detection Convert a 2D image into a set of curves Extracts salient features of the scene More compact than pixels."

Similar presentations


Ads by Google