Edges and Contours– Chapter 7 continued. Edge detection All of the previously studied edge...

30
Edges and Contours– Chapter 7 continued

Transcript of Edges and Contours– Chapter 7 continued. Edge detection All of the previously studied edge...

Page 1: Edges and Contours– Chapter 7 continued. Edge detection All of the previously studied edge detection filters worked on finding local gradients (1 st derivative)

Edges and Contours– Chapter 7

continued

Page 2: Edges and Contours– Chapter 7 continued. Edge detection All of the previously studied edge detection filters worked on finding local gradients (1 st derivative)

Edge detection

• All of the previously studied edge detection filters worked on finding local gradients (1st derivative)

• As such, all had to make decisions regarding the actual existence of an edge based on local information

Page 3: Edges and Contours– Chapter 7 continued. Edge detection All of the previously studied edge detection filters worked on finding local gradients (1 st derivative)

Sobel edges – threshold on magnitude

Page 4: Edges and Contours– Chapter 7 continued. Edge detection All of the previously studied edge detection filters worked on finding local gradients (1 st derivative)

Sobel edges – threshold on magnitude• The preceding images were edge-detected

with a Sobel operator then binarized with various thresholds

• The overall trend is predictable but the individual results are not

• This threshold dependency is the curse of image processing– Difficult to isolate “real” edges– Difficult to find accurate edge location

• We need smarter algorithms

Page 5: Edges and Contours– Chapter 7 continued. Edge detection All of the previously studied edge detection filters worked on finding local gradients (1 st derivative)

Scale space processing

• One method of dealing with the threshold dependency is through scale-space processing– An image is processed at various scales

(sizes/resolution) revealing different sets of features at each scale

– Features common to all [or many] sets are deemed “important”

Page 6: Edges and Contours– Chapter 7 continued. Edge detection All of the previously studied edge detection filters worked on finding local gradients (1 st derivative)

The Gaussian Pyramid

• Select a set of Gaussian filter parameters (sigma and width) and blur the image

• Save the image

• Reduce it’s size by subsampling (eliminating every other row/column)

• Do it again

Page 7: Edges and Contours– Chapter 7 continued. Edge detection All of the previously studied edge detection filters worked on finding local gradients (1 st derivative)

The Gaussian Pyramid

• You end up with a series of images (a pyramid) each exposing different features– Coarse features at the top of the pyramid– Fine features at the bottom

• You can now use the coarse features to select where to concentrate your processing of the fine features

Page 8: Edges and Contours– Chapter 7 continued. Edge detection All of the previously studied edge detection filters worked on finding local gradients (1 st derivative)

Better (different) algorithms• Another method of dealing with the

threshold dependency is through more complex algorithms

Page 9: Edges and Contours– Chapter 7 continued. Edge detection All of the previously studied edge detection filters worked on finding local gradients (1 st derivative)

A better kernel

• The Sobel mask is a derivative mask (computes the weighted difference of neighborhood pixels)

• So is the Laplacian (negative in the middle, positive around the rest)

• From calculus: the 2nd derivative of a signal is zero when the derivative magnitude is extremal

Page 10: Edges and Contours– Chapter 7 continued. Edge detection All of the previously studied edge detection filters worked on finding local gradients (1 st derivative)

A better kernel

• Combining these observations we can derive the Laplacian-Gaussian filter due to Marr and Hildreth– Also known as a DoG (Difference of

Gaussians) because it can be approximated by subtracting two Gaussian kernels of same width and differing sigmas

Page 11: Edges and Contours– Chapter 7 continued. Edge detection All of the previously studied edge detection filters worked on finding local gradients (1 st derivative)

The Gaussian kernel

• Sigma 1.6, Filter Width 15

eGyx

yx 2

22

22

1, 2

2,2widthyxwidth

0.00E+00

1.00E-02

2.00E-02

3.00E-02

4.00E-02

5.00E-02

6.00E-02

7.00E-02

1 3 5 7 9 11 13 15

Page 12: Edges and Contours– Chapter 7 continued. Edge detection All of the previously studied edge detection filters worked on finding local gradients (1 st derivative)

The Laplacian-Gaussian kernel

• Bypassing the math and jumping to the results of applying the rules of calculus…

eyx yx

2

22

22

22

42

11

• Similar in form to the Gaussian kernel

Page 13: Edges and Contours– Chapter 7 continued. Edge detection All of the previously studied edge detection filters worked on finding local gradients (1 st derivative)

The Laplacian-Gaussian kernel• In 1 dimension…

• Can be approximated by difference of two Gaussians

Convolution Filter (1 Line)

-0.2

0

0.2

0.4

0.6

0.8

1

1.2

0 2 4 6 8 10 12 14 16

Page 14: Edges and Contours– Chapter 7 continued. Edge detection All of the previously studied edge detection filters worked on finding local gradients (1 st derivative)

The Laplacian-Gaussian kernel• Convolution with this kernel results in

edge magnitudes of both positive and negative values

• We’re interested in where the sign changes occur (the zero crossing)

• These are where the edges are (recall the calculus result)

Page 15: Edges and Contours– Chapter 7 continued. Edge detection All of the previously studied edge detection filters worked on finding local gradients (1 st derivative)

Sobel vs. Laplacian-Gaussian

• L-G does not detect as much “noise” as Sobel – why not?

Page 16: Edges and Contours– Chapter 7 continued. Edge detection All of the previously studied edge detection filters worked on finding local gradients (1 st derivative)

Still something missing…• What are we ignoring in the following

edge detection processes?1. Gaussian filter

2. Sobel edge detection

3. Threshold based binarization of Sobel magnitude

And1. Laplacian-Gaussian filter

2. Zero crossing detection

Page 17: Edges and Contours– Chapter 7 continued. Edge detection All of the previously studied edge detection filters worked on finding local gradients (1 st derivative)

We need a smarter algorithm• We merely selected each edge based on its

magnitude and zero-crossing• We completely ignored its immediate surroundings• Why is this bad?

– Detects edges we don’t want• Prone to noise• Prone to clutter

– Doesn’t detect edges we do want• Weak magnitude edges are thresholded (thresheld?)

away

• We need a smarter algorithm!

Page 18: Edges and Contours– Chapter 7 continued. Edge detection All of the previously studied edge detection filters worked on finding local gradients (1 st derivative)

The Canny edge detector• John Canny – MIT 1986• Developed a process (series of steps)

for identifying edges in an image– Gaussian smoothing of input image– Local derivative operator to detect edge

candidates– Removal of edges that are clustered

around a single location– Adaptive thresholding algorithm for final

edge selection

Page 19: Edges and Contours– Chapter 7 continued. Edge detection All of the previously studied edge detection filters worked on finding local gradients (1 st derivative)

Concepts

• Gaussian smooth original image– Reduce the effects of noise

• Local derivative operator– Simple neighbor pixel subtraction to detect gradients (1st

derivative)

• Non-maximal suppression– Thin out the edges around a given point

• Threshold– Use two thresholds combined with spatial continuity

Page 20: Edges and Contours– Chapter 7 continued. Edge detection All of the previously studied edge detection filters worked on finding local gradients (1 st derivative)

Spatial continuity

• aka contour following– Apply the high threshold to get “obvious”

edges– Search for a neighboring edge above the low

threshold in the direction of the strong edge • We’re using a strong edge as an anchor point for a

contour of weak and strong edges – known as Hysteresis

Page 21: Edges and Contours– Chapter 7 continued. Edge detection All of the previously studied edge detection filters worked on finding local gradients (1 st derivative)

Canny results

• With very conservative high/low thresholds

Page 22: Edges and Contours– Chapter 7 continued. Edge detection All of the previously studied edge detection filters worked on finding local gradients (1 st derivative)

Results

All edges Weak edges

Strong edges Contours

Page 23: Edges and Contours– Chapter 7 continued. Edge detection All of the previously studied edge detection filters worked on finding local gradients (1 st derivative)

Summary

• Through more complex processing we arrive at a set of edges in which we have confidence– Minimal reliance on thresholds

• The cost is complex (slow, memory intensive) processing

• We must trade resources for accuracy!

Page 24: Edges and Contours– Chapter 7 continued. Edge detection All of the previously studied edge detection filters worked on finding local gradients (1 st derivative)

ImageJ

• Download/install plugins for– Sobel, Prewitt, Roberts, Kirsch, Nevatia-

Babu

• Plugins->FeatureJ->Edges– Canny implementation

Page 25: Edges and Contours– Chapter 7 continued. Edge detection All of the previously studied edge detection filters worked on finding local gradients (1 st derivative)

Edge Sharpening

• An process for making an image look “better”– In this case “better” means “sharper”

• The general approach is to amplify the high-frequency components (the edges) to create a “perceived” sharpness

Page 26: Edges and Contours– Chapter 7 continued. Edge detection All of the previously studied edge detection filters worked on finding local gradients (1 st derivative)

Method 1 – subtract 2nd derivative

• This causes a step edge to undershoot at the bottom and overshoot at the top

• The Laplacian works well for the 2nd derivative

vuIwvuIvuI sharp ,'',,

010

141

010

Page 27: Edges and Contours– Chapter 7 continued. Edge detection All of the previously studied edge detection filters worked on finding local gradients (1 st derivative)

ImageJ

• Note that this is difficult to do in ImageJ since the convolution operation clamps negative pixel values to 0

Page 28: Edges and Contours– Chapter 7 continued. Edge detection All of the previously studied edge detection filters worked on finding local gradients (1 st derivative)

Unsharp mask

• Steps– Subtract a Gaussian-smoothed version of

the image from the original creating a mask– Add a weighted version of the mask to the

original image

Page 29: Edges and Contours– Chapter 7 continued. Edge detection All of the previously studied edge detection filters worked on finding local gradients (1 st derivative)

ImageJ

• Plugins->Chapter07->Filter UnsharpMask

Page 30: Edges and Contours– Chapter 7 continued. Edge detection All of the previously studied edge detection filters worked on finding local gradients (1 st derivative)