linear filtering – part ii selim aksoy department of computer engineering bilkent university...

44
Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University [email protected]

Upload: kayli-cornfield

Post on 31-Mar-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

Linear Filtering – Part II

Selim AksoyDepartment of Computer Engineering

Bilkent [email protected]

Page 2: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Fall 2012 ©2012, Selim Aksoy 2

Fourier theory Jean Baptiste Joseph Fourier had a crazy

idea: Any periodic function can be written as a weighted sum of sines and cosines of different frequencies (1807). Fourier series

Even functions that are not periodic (but whose area under the curve is finite) can be expressed as the integral of sines and cosines multiplied by a weighing function. Fourier transform

Page 3: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Fall 2012 ©2012, Selim Aksoy 3

Fourier theory The Fourier theory

shows how most real functions can be represented in terms of a basis of sinusoids.

The building block: A sin( ωx + Φ )

Add enough of them to get any signal you want.

Adapted from Alexei Efros, CMU

Page 4: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Fall 2012 ©2012, Selim Aksoy 4

Fourier transform

Page 5: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Fall 2012 ©2012, Selim Aksoy 5

Fourier transform

Page 6: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Fall 2012 ©2012, Selim Aksoy 6

Fourier transform

Page 7: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Fall 2012 ©2012, Selim Aksoy 7

Fourier transform

Page 8: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Fall 2012 ©2012, Selim Aksoy 8

Fourier transform

Page 9: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Fall 2012 ©2012, Selim Aksoy 9

Fourier transform

Page 10: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

Fourier transform

CS 484, Fall 2012 ©2012, Selim Aksoy 10

To get some sense of what basis elements look like, we plot a basis element --- or rather, its real part ---as a function of x,y for some fixed u, v. We get a function that is constant when (ux+vy) is constant. The magnitude of the vector (u, v) gives a frequency, and its direction gives an orientation. The function is a sinusoid with this frequency along the direction, and constant perpendicular to the direction.

u

v vyuxie

vyuxie

Adapted from Antonio Torralba

Page 11: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

Fourier transform

CS 484, Fall 2012 ©2012, Selim Aksoy 11

Adapted from Antonio Torralba

Here u and v are larger than in the previous slide.

u

v vyuxie

vyuxie

Page 12: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

Fourier transform

CS 484, Fall 2012 ©2012, Selim Aksoy 12

Adapted from Antonio Torralba

And larger still...

u

v

vyuxie

vyuxie

Page 13: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Fall 2012 ©2012, Selim Aksoy 13

Fourier transform

Adapted from Alexei Efros, CMU

Page 14: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Fall 2012 ©2012, Selim Aksoy 14

Fourier transform

Adapted from Gonzales and Woods

Page 15: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Fall 2012 ©2012, Selim Aksoy 15

Fourier transform

Adapted from Gonzales and Woods

Page 16: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Fall 2012 ©2012, Selim Aksoy 16

Fourier transform

Page 17: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Fall 2012 ©2012, Selim Aksoy 17

Fourier transform

Page 18: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

Fourier transform

CS 484, Fall 2012 ©2012, Selim Aksoy 18

Adapted from Antonio Torralba

Horizontalorientation

Vertical orientation

45 deg.

0 fmax

0

fx in cycles/image

Low spatial frequencies

High spatial frequencies

Log power spectrum

How to interpret a Fourier spectrum:

Page 19: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

Fourier transform

CS 484, Fall 2012 ©2012, Selim Aksoy 19

Adapted from Antonio Torralba

A B C

1 2 3

Page 20: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Fall 2012 ©2012, Selim Aksoy 20

Fourier transform

Adapted from Shapiro and Stockman

Page 21: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Fall 2012 ©2012, Selim Aksoy 21

Fourier transform

Example building patterns in a satellite image and their Fourier spectrum.

Page 22: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Fall 2012 ©2012, Selim Aksoy 22

Convolution theorem

Page 23: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Fall 2012 ©2012, Selim Aksoy 23

Frequency domain filtering

Adapted from Shapiro and Stockman,and Gonzales and Woods

Page 24: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Fall 2012 ©2012, Selim Aksoy 24

Frequency domain filtering

Since the discrete Fourier transform is periodic, padding is needed in the implementation to avoid aliasing (see section 4.6 in the Gonzales-Woods book for implementation details).

Page 25: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Fall 2012 ©2012, Selim Aksoy 25

Frequency domain filtering

f(x,y)

h(x,y)

g(x,y)

|F(u,v)|

|H(u,v)|

|G(u,v)|

Adapted from Alexei Efros, CMU

Page 26: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Fall 2012 ©2012, Selim Aksoy 26

Smoothing frequency domain filters

Page 27: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Fall 2012 ©2012, Selim Aksoy 27

Smoothing frequency domain filters

The blurring and ringing caused by the ideal low-pass filter can be explained using the convolution theorem where the spatial representation of a filter is given below.

Page 28: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Fall 2012 ©2012, Selim Aksoy 28

Sharpening frequency domain filters

Page 29: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Fall 2012 ©2012, Selim Aksoy 29

Sharpening frequency domain filters

Adapted from Gonzales and Woods

Page 30: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Fall 2012 ©2012, Selim Aksoy 30

Sharpening frequency domain filters

Adapted from Gonzales and Woods

Page 31: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Fall 2012 ©2012, Selim Aksoy 31

Template matching

Correlation can also be used for matching. If we want to determine whether an image f

contains a particular object, we let h be that object (also called a template) and compute the correlation between f and h.

If there is a match, the correlation will be maximum at the location where h finds a correspondence in f.

Preprocessing such as scaling and alignment is necessary in most practical applications.

Page 32: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Fall 2012 ©2012, Selim Aksoy 32

Template matching

Adapted from Gonzales and Woods

Page 33: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Fall 2012 ©2012, Selim Aksoy 33

Template matching

Face detection using template matching: face templates.

Page 34: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Fall 2012 ©2012, Selim Aksoy 34

Template matching

Face detection using template matching: detected faces.

Page 35: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Fall 2012 ©2012, Selim Aksoy 35

Resizing images

How can we generate a half-sized version of a large image?

Adapted from Steve Seitz, U of Washington

Page 36: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Fall 2012 ©2012, Selim Aksoy 36

Resizing images

Throw away every other row and column to create a 1/2 size image (also called sub-sampling).

1/4

1/8

Adapted from Steve Seitz, U of Washington

Page 37: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Fall 2012 ©2012, Selim Aksoy 37

Resizing images

Does this look nice?1/4 (2x zoom)

1/8 (4x zoom)

1/2

Adapted from Steve Seitz, U of Washington

Page 38: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Fall 2012 ©2012, Selim Aksoy 38

Resizing images We cannot shrink an image by simply taking every k’th pixel. Solution: smooth the image, then sub-sample.

Gaussian 1/4

Gaussian 1/8

Gaussian 1/2

Adapted from Steve Seitz, U of Washington

Page 39: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Fall 2012 ©2012, Selim Aksoy 39

Resizing images

Gaussian 1/4 (2x zoom)

Gaussian 1/8 (4x zoom)

Gaussian 1/2

Adapted from Steve Seitz, U of Washington

Page 40: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Fall 2012 ©2012, Selim Aksoy 40

Sampling and aliasing

Adapted from Steve Seitz, U of Washington

Page 41: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Fall 2012 ©2012, Selim Aksoy 41

Sampling and aliasing

Errors appear if we do not sample properly. Common phenomenon:

High spatial frequency components of the image appear as low spatial frequency components.

Examples: Wagon wheels rolling the wrong way in movies. Checkerboards misrepresented in ray tracing. Striped shirts look funny on color television.

Page 42: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Fall 2012 ©2012, Selim Aksoy 42

Gaussian pyramids

Adapted from Gonzales and Woods

Page 43: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Fall 2012 ©2012, Selim Aksoy 43

Gaussian pyramids

Adapted from Michael Black, Brown University

Page 44: Linear Filtering – Part II Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Fall 2012 ©2012, Selim Aksoy 44

Gaussian pyramids

Adapted from Michael Black, Brown University