Edge Detection Edge detection Convert a 2 D

  • Slides: 108
Download presentation
Edge Detection

Edge Detection

Edge detection Convert a 2 D image into a set of curves • Extracts

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

Origin of Edges surface normal discontinuity depth discontinuity surface color discontinuity illumination discontinuity Edges

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

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

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

Profiles of image intensity edges

Profiles of image intensity edges

Edge detection 1. Detection of short linear edge segments (edgels) 2. Aggregation of edgels

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

Edgel detection • Difference operators • Parametric-model matchers

Edgel detection • Difference operators • Parametric-model matchers

Edge is Where Change Occurs Change is measured by derivative in 1 D Biggest

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

Edge Detection Possible detectors: Gradient operators • Roberts • Prewitt • Sobel Gradient of

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

Edge Detection Using the Gradient Definition of the gradient: To save computations, the magnitude

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

Image gradient The gradient of an image: The gradient points in the direction of

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

Edge Detection Using the Gradient Properties of the gradient: • The magnitude of gradient

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

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

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

Edge Detection Using the Gradient Using pixel-coordinate notation (remember: j corresponds to the x

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

Edge Detection Using the Gradient Example: • Suppose we want to approximate the gradient

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: Mx is the approximation at (i, j + 1/2) and My is the approximation at (i + 1/2, j)

Edge Detection Using the Gradient The Roberts edge detector This approximation can be implemented

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

Edge Detection Using the Gradient The Prewitt edge detector • Consider the arrangement of

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

Edge Detection Using the Gradient The Sobel edge detector • Setting c = 2,

Edge Detection Using the Gradient The Sobel edge detector • Setting c = 2, we get the Sobel operator: Note: Mx and My are approximations at (i, j))

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

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

Edge Detection Using the Gradient (an example using the Prewitt edge detector - don’t

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

Edge Detection Using the Gradient Example:

Edge Detection Using the Gradient Example:

Edge Detection Using the Gradient Example – cont. :

Edge Detection Using the Gradient Example – cont. :

Edge Detection Using the Gradient Example – cont. :

Edge Detection Using the Gradient Example – cont. :

Edge Detection Using the Gradient

Edge Detection Using the Gradient

Edge Detection Using the Gradient

Edge Detection Using the Gradient

Edge Detection Using the Gradient Isotropic property of gradient magnitude: • The magnitude of

Edge Detection Using the Gradient Isotropic property of gradient magnitude: • The magnitude of gradient is an isotropic operator (it detects edges in any direction !!)

The discrete gradient How can we differentiate a digital image f[x, y]? • Option

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?

The Sobel operator Better approximations of the derivatives exist • The Sobel operators below

The Sobel operator Better approximations of the derivatives exist • The Sobel operators below are very commonly used -1 0 1 1 2 1 -2 0 0 0 -1 0 1 -1 -2 -1 • 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

Basic Relationship of Pixels (0, 0) y x (x-1, y-1) (x+1, y-1) (x-1, y)

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

Neighbors of a Pixel Neighborhood relation is used to tell adjacent pixels. It is

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

Neighbors of a Pixel (cont. ) (x-1, y-1) (x+1, y-1) (x-1, y) p (x+1,

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

Neighbors of a Pixel (cont. ) (x-1, y-1) (x+1, y-1) Diagonal neighbors of p:

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

Template, Window, and Mask Operation Sometime we need to manipulate values obtained from neighboring

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 3 x 3 region center at a pixel z? 2 9 7 5 7 2 4 2 2 2 4 5 1 2 3 4 9 7 3 6 2 5 2 3 Image 6 4 6 1 1 2 2 4 7 5 2 8 Pixel z

Template, Window, and Mask Operation (cont. ) Step 1. Selected only needed pixels 1

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

Template, Window, and Mask Operation (cont. ) … Step 2. Multiply every pixel by

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

Template, Window, and Mask Operation (cont. ) Question: How to compute the 3 x

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

Template, Window, and Mask Operation (cont. ) Step 1: Move the window to the

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. Step 2: Compute 2 4 1 2 6 2 2 4 1 the average value 9 2 3 4 4 4 9 2 3 7 2 5 2 7 4 9 3 2 7 6 5 6 7 1 5 1 2 7 2 Sub image p Original image Step 4: Move the window to the next location and go to Step 2 9 4. 3 Step 3: Place the result at the pixel in the output image Output image

Template, Window, and Mask Operation (cont. ) The 3 x 3 averaging method is

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

… Template, Window, and Mask Operation (cont. ) The mask operation at each point

… 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. Mask frame w(1, 1) w(2, 1) w(3, 1) p(1, 1) p(2, 1) p(3, 1) … p(2, 1) p(2, 2) p(3, 2) … p(1, 3) p(2, 3) p(3, 3) Subimage The reference point of the mask … w(1, 2) w(2, 2) w(3, 1) w(3, 2) w(3, 3) Mask coefficients

Template, Window, and Mask Operation (cont. ) The mask operation on the whole image

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 3. and pixels inside subimage under the mask. 3. Store the results at the corresponding pixels of the 4. output image. 4. Move the mask to the next location and go to step 2 5. until all pixel locations have been used.

Template, Window, and Mask Operation (cont. ) Examples of the masks Sobel operators 3

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

Gradient operators (a): Roberts’ cross operator (b): 3 x 3 Prewitt operator (c): Sobel

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

Effects of noise Consider a single row or column of the image • Plotting

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?

Solution: smooth first Where is the edge? Look for peaks in

Solution: smooth first Where is the edge? Look for peaks in

Derivative theorem of convolution This saves us one operation:

Derivative theorem of convolution This saves us one operation:

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

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

2 D edge detection filters Laplacian of Gaussian derivative of Gaussian is the Laplacian

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

Edge Detection Practical issues: • Differential masks act as high-pass filters – tend to

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.

Edge Detection How should we choose threshold?

Edge Detection How should we choose threshold?

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

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

Edge Detection Criteria for optimal edge detection: • Good detection: the optimal detector must

Edge Detection Criteria for optimal 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

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

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

The Canny Edge Detector The Canny edge detector: • This is probably the most

The Canny Edge Detector 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

The Canny Edge Detector

The Canny Edge Detector The derivative of the Gaussian:

The Canny Edge Detector The derivative of the Gaussian:

The Canny Edge Detector Canny – smoothing and derivatives:

The Canny Edge Detector Canny – smoothing and derivatives:

The Canny Edge Detector Canny – gradient magnitude: image gradient magnitude

The Canny Edge Detector Canny – gradient magnitude: image gradient magnitude

Edge Detection Non-maxima suppression • To find the edge points, we need to find

Edge Detection Non-maxima suppression • 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.

Edge Detection Non-maxima suppression – cont.

Edge Detection Non-maxima suppression – cont.

Edge Detection Non-maxima suppression – cont. • What are the neighbors? – Look along

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

Edge Detection Canny – Non-maxima suppression: gradient magnitude thinned

Edge Detection Canny – Non-maxima suppression: gradient magnitude thinned

Edge Detection Hysteresis thresholding / Edge linking • The output of non-maxima suppression still

Edge Detection Hysteresis thresholding / Edge linking • 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). • A more effective scheme is to use two thresholds: – a low threshold tl – a high threshold th – usually, th ≈ 2 tl

Optimal Edge Detection: Canny Assume: • Linear filtering • Additive iid Gaussian noise Edge

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.

Optimal Edge Detection: Canny (continued) Optimal Detector is approximately Derivative of Gaussian. Detection/Localization trade-off

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)

The Canny edge detector original image (Lena)

The Canny edge detector original image (Lena)

The Canny edge detector norm of the gradient

The Canny edge detector norm of the gradient

The Canny edge detector thresholding

The Canny edge detector thresholding

The Canny edge detector thinning (non-maximum suppression)

The Canny edge detector thinning (non-maximum suppression)

Non-maximum suppression Check if pixel is local maximum along gradient direction • requires checking

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

Predicting the next edge point Assume the marked point is an edge point. Then

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)

Hysteresis Check that maximum value of gradient value is sufficiently large • drop-outs? use

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.

Effect of (Gaussian kernel size) original Canny with The choice of • large •

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

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

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

fine scale high threshold

fine scale high threshold

coarse scale, high threshold

coarse scale, high threshold

coarse scale low threshold

coarse scale low threshold

Scale space (Witkin 83) first derivative peaks larger Gaussian filtered signal Properties of scale

Scale space (Witkin 83) first derivative peaks larger Gaussian filtered signal 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

Edge detection by subtraction original

Edge detection by subtraction original

Edge detection by subtraction smoothed (5 x 5 Gaussian)

Edge detection by subtraction smoothed (5 x 5 Gaussian)

Edge detection by subtraction Why does this work? smoothed – original (scaled by 4,

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

Gaussian - image filter Gaussian delta function Laplacian of Gaussian

Gaussian - image filter Gaussian delta function Laplacian of Gaussian

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

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

Finding lines in an image Option 1: • Search for the line at every

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

Finding lines in an image y b b 0 x image space m 0

Finding lines in an image y b b 0 x image space m 0 m Hough space 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

Finding lines in an image y b y 0 x image space m Hough

Finding lines in an image y b y 0 x image space m Hough space 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? – A: the solutions of b = -x 0 m + y 0 – this is a line in Hough space

Hough transform algorithm Typically use a different parameterization • • • d is the

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?

Hough transform algorithm Typically use a different parameterization • • • d is the

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)?

Extensions Extension 1: Use the image gradient 1. same 2. for each edge point

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 1. What’s the running time measured in votes? 2. 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

Extensions Extension 1: Use the image gradient 1. same 2. for each edge point

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 1. What’s the running time measured in votes? 2. 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

Hough Transform for Curves The H. T. can be generalized to detect any curve

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

Corner detection Corners contain more edges than lines. A point on a line is

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

Corners contain more edges than lines. A corner is easier

Corners contain more edges than lines. A corner is easier

Edge Detectors Tend to Fail at Corners

Edge Detectors Tend to Fail at Corners

Finding Corners Intuition: • Right at corner, gradient is ill defined. • Near corner,

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

Formula for Finding Corners We look at matrix: Sum over a small region, the

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

First, consider case where: This means all gradients in neighborhood are: (k, 0) or

First, consider case where: This means all gradients in neighborhood are: (k, 0) or (0, c) or What is region like if: 1. l 1 = 0? 2. l 2 = 0? 3. l 1 = 0 and l 2 = 0? 4. l 1 > 0 and l 2 > 0? (0, 0) (or off-diagonals cancel).

General Case: From Linear Algebra, it follows that because C is symmetric: With R

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

So, to detect corners Filter image. Compute magnitude of the gradient everywhere. We construct

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

10. Convolution-based Edge Detection Why do edge detection? What is an edge? What is

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

Laplacian

Laplacian

Why Laplacian? because it is zero when the rate of intensity change in the

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

Log filters=prefilter+laplacian

Log filters=prefilter+laplacian

Mexican Hat (Lo. G Kernel)

Mexican Hat (Lo. G Kernel)

The Log kernel

The Log kernel

Oriented Filters are steerable

Oriented Filters are steerable

Changing Scale at 0 Degrees

Changing Scale at 0 Degrees

Changing Phase at 0 degrees

Changing Phase at 0 degrees