lecture 2: edge detection and resampling

66
Lecture 2: Edge detection and resampling CS6670: Computer Vision Noah Snavely From Sandlot Science

Upload: selena

Post on 12-Feb-2016

50 views

Category:

Documents


0 download

DESCRIPTION

CS6670: Computer Vision. Noah Snavely. Lecture 2: Edge detection and resampling. From Sandlot Science. Administrivia. New room starting Thursday: HLS B11. Administrivia. Assignment 1 (feature detection and matching) will be out Thursday Turning via CMS: https://cms.csuglab.cornell.edu/ - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Lecture 2: Edge detection and resampling

Lecture 2: Edge detection and resampling

CS6670: Computer VisionNoah Snavely

From Sandlot Science

Page 2: Lecture 2: Edge detection and resampling

Administrivia

• New room starting Thursday: HLS B11

Page 3: Lecture 2: Edge detection and resampling

Administrivia

• Assignment 1 (feature detection and matching) will be out Thursday– Turning via CMS: https://cms.csuglab.cornell.edu/

• Mailing list: please let me know if you aren’t on it

Page 4: Lecture 2: Edge detection and resampling

Reading

• Szeliski: 3.4.1, 3.4.2

Page 5: Lecture 2: Edge detection and resampling

Last time: Cross-correlation

This is called a cross-correlation operation:

Let be the image, be the kernel (of size 2k+1 x 2k+1), and be the output image

Page 6: Lecture 2: Edge detection and resampling

Last time: Convolution• Same as cross-correlation, except that the

kernel is “flipped” (horizontally and vertically)

This is called a convolution operation:

Page 7: Lecture 2: Edge detection and resampling

Linear filters: examples

000

010

000

Original Identical image

Source: D. Lowe

* =

Page 8: Lecture 2: Edge detection and resampling

Linear filters: examples

000

001

000

Original Shifted leftBy 1 pixel

Source: D. Lowe

* =

Page 9: Lecture 2: Edge detection and resampling

Linear filters: examples

Original

111

111

111

Blur (with a mean filter)

Source: D. Lowe

* =

Page 10: Lecture 2: Edge detection and resampling

Linear filters: examples

Original

111111111

000020000 -

Sharpening filter (accentuates edges)

Source: D. Lowe

=*

Page 11: Lecture 2: Edge detection and resampling

Image noise

http://theory.uchicago.edu/~ejm/pix/20d/tests/noise/index.html

Original image Gaussian noise Salt and pepper noise(each pixel has some chance of being switched to zero or one)

Page 12: Lecture 2: Edge detection and resampling

Gaussian noise

= 1 pixel = 2 pixels = 5 pixels

Smoothing with larger standard deviations suppresses noise, but also blurs the image

Page 13: Lecture 2: Edge detection and resampling

Salt & pepper noise – Gaussian blur

= 1 pixel = 2 pixels = 5 pixels

• What’s wrong with the results?

p = 10%

Page 14: Lecture 2: Edge detection and resampling

Alternative idea: Median filtering• A median filter operates over a window by

selecting the median intensity in the window

• Is median filtering linear?Source: K. Grauman

Page 15: Lecture 2: Edge detection and resampling

Median filter• What advantage does median filtering have

over Gaussian filtering?

Source: K. Grauman

Page 16: Lecture 2: Edge detection and resampling

Salt & pepper noise – median filtering

= 1 pixel = 2 pixels = 5 pixels

3x3 window 5x5 window 7x7 window

p = 10%

Page 17: Lecture 2: Edge detection and resampling

Questions?

Page 18: Lecture 2: Edge detection and resampling

Edge detection

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

Page 19: Lecture 2: Edge detection and resampling

Origin of Edges

• Edges are caused by a variety of factors

depth discontinuity

surface color discontinuity

illumination discontinuity

surface normal discontinuity

Page 20: Lecture 2: Edge detection and resampling

Characterizing edges• An edge is a place of rapid change in the

image intensity function

imageintensity function

(along horizontal scanline) first derivative

edges correspond toextrema of derivativeSource: L. Lazebnik

Page 21: Lecture 2: Edge detection and resampling

• How can we differentiate a digital image F[x,y]?– Option 1: reconstruct a continuous image, f, then

compute the derivative– Option 2: take discrete derivative (finite

difference)

1 -1

How would you implement this as a linear filter?

Image derivatives

-11

: :

Source: S. Seitz

Page 22: Lecture 2: Edge detection and resampling

The gradient points in the direction of most rapid increase in intensity

Image gradient• The gradient of an image:

The edge strength is given by the gradient magnitude:

The gradient direction is given by:

• how does this relate to the direction of the edge?Source: Steve Seitz

Page 23: Lecture 2: Edge detection and resampling

Image gradient

Source: L. Lazebnik

Page 24: Lecture 2: Edge detection and resampling

Effects of noise

Where is the edge?Source: S. Seitz

Noisy input image

Page 25: Lecture 2: Edge detection and resampling

Solution: smooth first

f

h

f * h

Source: S. SeitzTo find edges, look for peaks in

Page 26: Lecture 2: Edge detection and resampling

• Differentiation is convolution, and convolution is associative:

• This saves us one operation:

Associative property of convolution

f

Source: S. Seitz

Page 27: Lecture 2: Edge detection and resampling

2D edge detection filters

Gaussianderivative of Gaussian (x)

Page 28: Lecture 2: Edge detection and resampling

Derivative of Gaussian filter

x-direction y-direction

Page 29: Lecture 2: Edge detection and resampling

The Sobel operator• Common approximation of derivative of Gaussian

-1 0 1

-2 0 2

-1 0 1

1 2 1

0 0 0

-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

Page 30: Lecture 2: Edge detection and resampling

Sobel operator: example

Source: Wikipedia

Page 31: Lecture 2: Edge detection and resampling

Example

• original image (Lena)

Page 32: Lecture 2: Edge detection and resampling

Finding edges

gradient magnitude

Page 33: Lecture 2: Edge detection and resampling

thresholding

Finding edges

where is the edge?

Page 34: Lecture 2: Edge detection and resampling

• Check if pixel is local maximum along gradient direction– requires interpolating pixels p and r

Non-maximum supression

Page 35: Lecture 2: Edge detection and resampling

thresholding

Finding edges

Page 36: Lecture 2: Edge detection and resampling

thinning(non-maximum suppression)

Finding edges

Page 37: Lecture 2: Edge detection and resampling

Canny edge detector1. Filter image with derivative of Gaussian

2. Find magnitude and orientation of gradient

3. Non-maximum suppression

4. Linking and thresholding (hysteresis):– Define two thresholds: low and high– Use the high threshold to start edge curves and

the low threshold to continue them

Source: D. Lowe, L. Fei-Fei

MATLAB: edge(image,‘canny’)

Page 38: Lecture 2: Edge detection and resampling

Canny edge detector

• Still one of the most widely used edge detectors in computer vision

• Depends on several parameters:

J. Canny, A Computational Approach To Edge Detection, IEEE Trans. Pattern Analysis and Machine Intelligence, 8:679-714, 1986.

: width of the Gaussian blur

high thresholdlow threshold

Page 39: Lecture 2: Edge detection and resampling

Canny edge detector

Canny with Canny with original

• The choice of depends on desired behavior– large detects “large-scale” edges– small detects fine edges

Source: S. Seitz

Page 40: Lecture 2: Edge detection and resampling

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

Page 41: Lecture 2: Edge detection and resampling

Questions?

Page 42: Lecture 2: Edge detection and resampling

Image Scaling

This image is too big to fit on the screen. How can we generate a half-sized version?

Source: S. Seitz

Page 43: Lecture 2: Edge detection and resampling

Image sub-sampling

Throw away every other row and column to create a 1/2 size image

- called image sub-sampling

1/4

1/8

Source: S. Seitz

Page 44: Lecture 2: Edge detection and resampling

Image sub-sampling

1/4 (2x zoom) 1/8 (4x zoom)

Why does this look so crufty?

1/2

Source: S. Seitz

Page 45: Lecture 2: Edge detection and resampling

Image sub-sampling

Source: F. Durand

Page 46: Lecture 2: Edge detection and resampling

Even worse for synthetic images

Source: L. Zhang

Page 47: Lecture 2: Edge detection and resampling

Aliasing

• Occurs when your sampling rate is not high enough to capture the amount of detail in your image

• Can give you the wrong signal/image—an alias

• To do sampling right, need to understand the structure of your signal/image

• Enter Monsieur Fourier…

• To avoid aliasing:– sampling rate ≥ 2 * max frequency in the image

• said another way: ≥ two samples per cycle– This minimum sampling rate is called the Nyquist rate Source: L. Zhang

Page 48: Lecture 2: Edge detection and resampling

Wagon-wheel effect

(See http://www.michaelbach.de/ot/mot_wagonWheel/index.html) Source: L. Zhang

Page 49: Lecture 2: Edge detection and resampling

Gaussian pre-filtering

G 1/4

G 1/8

Gaussian 1/2

• Solution: filter the image, then subsample

Source: S. Seitz

Page 50: Lecture 2: Edge detection and resampling

Subsampling with Gaussian pre-filtering

G 1/4 G 1/8Gaussian 1/2

• Solution: filter the image, then subsample

Source: S. Seitz

Page 51: Lecture 2: Edge detection and resampling

Compare with...

1/4 (2x zoom) 1/8 (4x zoom)1/2

Source: S. Seitz

Page 52: Lecture 2: Edge detection and resampling

Gaussian pre-filtering• Solution: filter

the image, then subsample

blur

F0 H*

subsample blur subsample …F1

F1 H*

F2F0

Page 53: Lecture 2: Edge detection and resampling

blur

F0 H*

subsample blur subsample …F1

F1 H*

F2F0

{Gaussian pyramid

Page 54: Lecture 2: Edge detection and resampling

Gaussian pyramids [Burt and Adelson, 1983]

• In computer graphics, a mip map [Williams, 1983]• A precursor to wavelet transform

Gaussian Pyramids have all sorts of applications in computer vision Source: S. Seitz

Page 55: Lecture 2: Edge detection and resampling

Gaussian pyramids [Burt and Adelson, 1983]

• How much space does a Gaussian pyramid take compared to the original image?

Source: S. Seitz

Page 56: Lecture 2: Edge detection and resampling

Questions?

Page 57: Lecture 2: Edge detection and resampling

Upsampling

• This image is too small for this screen:• How can we make it 10 times as big?• Simplest approach:

repeat each row and column 10 times

• (“Nearest neighbor interpolation”)

Page 58: Lecture 2: Edge detection and resampling

Image interpolation

Recall how a digital image is formed

• It is a discrete point-sampling of a continuous function• If we could somehow reconstruct the original function, any new

image could be generated, at any resolution and scale

1 2 3 4 5

Adapted from: S. Seitz

d = 1 in this example

Page 59: Lecture 2: Edge detection and resampling

Image interpolation

1 2 3 4 5

d = 1 in this example

Recall how a digital image is formed

• It is a discrete point-sampling of a continuous function• If we could somehow reconstruct the original function, any new

image could be generated, at any resolution and scale

Adapted from: S. Seitz

Page 60: Lecture 2: Edge detection and resampling

Image interpolation

1 2 3 4 52.5

1

• Convert to a continuous function:

• Reconstruct by convolution with a reconstruction filter, h

• What if we don’t know ?• Guess an approximation:• Can be done in a principled way: filtering

d = 1 in this example

Adapted from: S. Seitz

Page 61: Lecture 2: Edge detection and resampling

Image interpolation

“Ideal” reconstruction

Nearest-neighbor interpolation

Linear interpolation

Gaussian reconstruction

Source: B. Curless

Page 62: Lecture 2: Edge detection and resampling

Reconstruction filters• What does the 2D version of this hat function look like?

Often implemented without cross-correlation• E.g., http://en.wikipedia.org/wiki/Bilinear_interpolation

Better filters give better resampled images• Bicubic is common choice

performs linear interpolation

(tent function) performs bilinear interpolation

Cubic reconstruction filter

Page 63: Lecture 2: Edge detection and resampling

Image interpolation

Nearest-neighbor interpolation Bilinear interpolation Bicubic interpolation

Original image: x 10

Page 64: Lecture 2: Edge detection and resampling

Image interpolation

Also used for resampling

Page 65: Lecture 2: Edge detection and resampling

Questions?

Page 66: Lecture 2: Edge detection and resampling

Next time: image features