Thinking in Frequency Computer Vision Jia-Bin Huang, Virginia Tech - - PowerPoint PPT Presentation

thinking in frequency
SMART_READER_LITE
LIVE PREVIEW

Thinking in Frequency Computer Vision Jia-Bin Huang, Virginia Tech - - PowerPoint PPT Presentation

Thinking in Frequency Computer Vision Jia-Bin Huang, Virginia Tech Dali: Gala Contemplating the Mediterranean Sea (1976) Administrative stuffs HW 0 will be posted on Sunday (Sept 2). Due date: Sept 10 HW 1 will be posted on


slide-1
SLIDE 1

Thinking in Frequency

Computer Vision Jia-Bin Huang, Virginia Tech

Dali: “Gala Contemplating the Mediterranean Sea” (1976)

slide-2
SLIDE 2

Administrative stuffs

  • HW 0 will be posted on Sunday (Sept 2).
  • Due date: Sept 10
  • HW 1 will be posted on Sunday (Sept 2)
  • Due date: Sept 17
slide-3
SLIDE 3

Previous class: Image Filtering

  • Linear filtering is sum of dot

product at each position

  • Can smooth, sharpen, translate

(among many other uses)

  • Gaussian filters
  • Low pass filters, separability, variance
  • Attend to details:
  • filter size, extrapolation, cropping
  • Applications:
  • Texture representation
  • Noise models and nonlinear image

filters

1 1 1 1 1 1 1 1 1

slide-4
SLIDE 4

Today’s class

  • Review of image filtering in spatial domain
  • Fourier transform and frequency domain
  • Frequency view of filtering
  • Image downsizing and interpolation
  • Goals:
  • Understand 2D Fourier transform
  • Understand how to implement filtering in Fourier domain
  • Understand aliasing and how to prevent aliasing
slide-5
SLIDE 5

Demo

  • http://setosa.io/ev/image-kernels/
slide-6
SLIDE 6

Review: questions

Fill in the blanks:

a) _ = D * B b) A = _ * _ c) F = D * _ d) _ = D * D

A B C D E F G H I Filtering Operator

Slide: Hoiem

slide-7
SLIDE 7

Representing texture by mean abs response

Mean abs responses Filters

slide-8
SLIDE 8

Denoising and Nonlinear Image Filtering

  • Salt and pepper noise: contains

random occurrences of black and white pixels

  • Impulse noise: contains random
  • ccurrences of white pixels
  • Gaussian noise: variations in intensity

drawn from a Gaussian normal distribution

Source: S. Seitz

slide-9
SLIDE 9

Gaussian noise

  • Mathematical model: sum of many independent

factors

  • Good for small standard deviations
  • Assumption: independent, zero-mean noise

Source: M. Hebert

slide-10
SLIDE 10

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

Reducing Gaussian noise

slide-11
SLIDE 11

Reducing salt-and-pepper noise

  • What’s wrong with the results?

3x3 5x5 7x7

slide-12
SLIDE 12

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

slide-13
SLIDE 13

Median filter

  • Is median filtering linear?
  • Let’s try filtering
slide-14
SLIDE 14

Median filter

  • What advantage does median filtering have
  • ver Gaussian filtering?
  • Robustness to outliers

Source: K. Grauman

slide-15
SLIDE 15

Median filter

Salt-and-pepper noise Median filtered

Source: M. Hebert

  • MATLAB: medfilt2(image, [h w])
slide-16
SLIDE 16

Gaussian vs. median filtering

3x3 5x5 7x7 Gaussian Median

slide-17
SLIDE 17

Other non-linear filters

  • Weighted median (pixels further from center count less)
  • Clipped mean (average, ignoring few brightest and darkest pixels)
  • Bilateral filtering (weight by spatial distance and intensity difference)

http://vision.ai.uiuc.edu/?p=1455 Image:

Bilateral filtering

slide-18
SLIDE 18

Bilateral Filters

  • Edge preserving: weights similar pixels more

Carlo Tomasi, Roberto Manduchi, Bilateral Filtering for Gray and Color Images, ICCV, 1998.

Original Gaussian Bilateral spatial similarity (e.g., intensity)

slide-19
SLIDE 19

Previous class: Image Filtering

  • Linear filtering is sum of dot

product at each position

  • Can smooth, sharpen, translate

(among many other uses)

  • Gaussian filters
  • Low pass filters, separability, variance
  • Attend to details:
  • filter size, extrapolation, cropping
  • Applications:
  • Texture representation
  • Noise models and nonlinear image

filters

1 1 1 1 1 1 1 1 1

slide-20
SLIDE 20

Hybrid Images

  • A. Oliva, A. Torralba, P.G. Schyns,

“Hybrid Images,” SIGGRAPH 2006

Slide credit: Derek Hoiem

slide-21
SLIDE 21

Why do we get different, distance-dependent interpretations of hybrid images?

?

Slide credit: Derek Hoiem

slide-22
SLIDE 22

Why does a lower resolution image still make sense to us? What do we lose?

Image: http://www.flickr.com/photos/igorms/136916757/ Slide credit: Derek Hoiem

slide-23
SLIDE 23

Thinking in terms of frequency

slide-24
SLIDE 24

Jean Baptiste Joseph Fourier (1768-1830)

had crazy idea (1807):

Any univariate function can be rewritten as a weighted sum of sines and cosines of different frequencies.

  • Don’t believe it?
  • Neither did Lagrange,

Laplace, Poisson and

  • ther big wigs
  • Not translated into

English until 1878!

  • But it’s (mostly) true!
  • called Fourier Series
  • there are some subtle

restrictions

...the manner in which the author arrives at these equations is not exempt of difficulties and...his analysis to integrate them still leaves something to be desired on the score of generality and even rigour. Laplace Lagrange Legendre

Slides: Efros

slide-25
SLIDE 25

How would math have changed if the Slanket or Snuggie had been invented?

Slide credit: James Hays

slide-26
SLIDE 26

A sum of sines

Our building block: Add enough of them to get any signal f(x) you want!

) +φ ωx Asin(

slide-27
SLIDE 27

Frequency Spectra

  • example : g(t) = sin(2πf t) + (1/3)sin(2π(3f) t)

= +

Slides: Efros

slide-28
SLIDE 28

Frequency Spectra

slide-29
SLIDE 29

= + =

Frequency Spectra

slide-30
SLIDE 30

= + =

Frequency Spectra

slide-31
SLIDE 31

= + =

Frequency Spectra

slide-32
SLIDE 32

= + =

Frequency Spectra

slide-33
SLIDE 33

= + =

Frequency Spectra

slide-34
SLIDE 34

=

1

1 sin(2 )

k

A kt k π

∞ =

Frequency Spectra

slide-35
SLIDE 35

Example: Music

  • We think of music in terms of frequencies at

different magnitudes

slide-36
SLIDE 36

Other signals

  • We can also think of all kinds of other signals the

same way

xkcd.com

Cats(?)

slide-37
SLIDE 37

Fourier analysis in images

http://sharp.bu.edu/~slehar/fourier/fourier.html#filtering

Intensity Image Fourier Image

slide-38
SLIDE 38

Signals can be composed

+ =

http://sharp.bu.edu/~slehar/fourier/fourier.html#filtering More: http://www.cs.unm.edu/~brayer/vision/fourier.html

slide-39
SLIDE 39

Fourier Transform

Teases away fast vs. slow changes in the image.

Slide credit: A Efros

Image as a sum of basis images

slide-40
SLIDE 40

Extension to 2D

in Matlab, check out: imagesc(log(abs(fftshift(fft2(im)))));

slide-41
SLIDE 41

Fourier Transform

  • Fourier transform stores the magnitude and phase at

each frequency

  • Magnitude encodes how much signal there is at a particular frequency
  • Phase encodes spatial information (indirectly)
  • For mathematical convenience, this is often notated in terms of real

and complex numbers

2 2

) ( ) ( ω ω I R A + ± =

) ( ) ( tan 1 ω ω φ R I

=

Amplitude: Euler’s formula: Phase:

slide-42
SLIDE 42

Salvador Dali invented Hybrid Images? Salvador Dali “Gala Contemplating the Mediterranean Sea, which at 30 meters becomes the portrait

  • f Abraham Lincoln”, 1976
slide-43
SLIDE 43
slide-44
SLIDE 44
slide-45
SLIDE 45

Log Magnitude Strong Vertical Frequency (Sharp Horizontal Edge) Strong Horz. Frequency (Sharp Vert. Edge) Diagonal Frequencies

Low Frequencies

slide-46
SLIDE 46

Man-made Scene

slide-47
SLIDE 47

Can change spectrum, then reconstruct

slide-48
SLIDE 48

Low and High Pass filtering

slide-49
SLIDE 49

Computing the Fourier Transform

Continuous Discrete

k = -N/2..N/2

Fast Fourier Transform (FFT): NlogN

slide-50
SLIDE 50

Properties of Fourier Transforms

  • Linearity
  • Fourier transform of a real signal is symmetric about

the origin

  • The energy of the signal is the same as the energy of

its Fourier transform

See Szeliski Book (3.4)

slide-51
SLIDE 51

The Convolution Theorem

  • The Fourier transform of the convolution of two

functions is the product of their Fourier transforms

  • The inverse Fourier transform of the product of two

Fourier transforms is the convolution of the two inverse Fourier transforms

  • Convolution in spatial domain is equivalent to

multiplication in frequency domain!

] F[ ] F[ ] F[ h g h g = ∗

] [ F ] [ F ] [ F

1 1 1

h g gh

− − −

∗ =

slide-52
SLIDE 52

Filtering in spatial domain

  • 1

1

  • 2

2

  • 1

1

*

=

slide-53
SLIDE 53

*

=

Spatial domain Frequency domain

FFT FFT

=

Inverse FFT

slide-54
SLIDE 54

FFT in Matlab

  • Filtering with fft
  • Displaying with fft

im = … % im: gray-scale floating point image [imh, imw] = size(im); fftsize = 1024; % fftsize: should be order of 2 (for speed) and include padding hs = 50; % fil: Gaussian filter fil = fspecial('gaussian', hs*2+1, 10); % im_fft = fft2(im, fftsize, fftsize); % 1) fft im with padding fil_fft = fft2(fil, fftsize, fftsize); % 2) fft fil, pad to same size as image im_fil_fft = im_fft .* fil_fft; % 3) multiply fft images im_fil = ifft2(im_fil_fft); % 4) inverse fft2 im_fil = im_fil(1+hs:size(im,1)+hs, 1+hs:size(im, 2)+hs); % 5) remove padding figure(1), imagesc(log(abs(fftshift(im_fft)))), axis image, colormap jet

slide-55
SLIDE 55

Questions

Which has more information, the phase or the magnitude? What happens if you take the phase from one image and combine it with the magnitude from another image?

slide-56
SLIDE 56

Phase vs. Magnitude

Magnitude Phase Intensity image

FFT

Inverse FFT

Use random

magnitude

Inverse FFT

Use random phase

slide-57
SLIDE 57

Why does the Gaussian give a nice smooth image, but the square filter give edgy artifacts?

Gaussian Box filter

Filtering

slide-58
SLIDE 58

Gaussian

slide-59
SLIDE 59

Box Filter

slide-60
SLIDE 60

Question

Match the spatial domain image to the Fourier magnitude image

1 5 4 A 3 2 C B D E

slide-61
SLIDE 61

2-mins break

slide-62
SLIDE 62

Image half-sizing

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

slide-63
SLIDE 63

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

Slide by Steve Seitz

slide-64
SLIDE 64

Image sub-sampling

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

Slide by Steve Seitz

Why does this look so crufty? Aliasing! What do we do?

slide-65
SLIDE 65

Image sub-sampling

Source: F. Durand

slide-66
SLIDE 66

Even worse for synthetic images

Source: L. Zhang

slide-67
SLIDE 67

Aliasing problem

  • 1D example (sinewave):

Source: S. Marschner

slide-68
SLIDE 68

Source: S. Marschner

Aliasing problem

  • 1D example (sinewave):
slide-69
SLIDE 69

Aliasing problem

  • Sub-sampling may be dangerous….
  • Characteristic errors may appear:
  • “Wagon wheels rolling the wrong way in movies”
  • “Checkerboards disintegrate in ray tracing”
  • “Striped shirts look funny on color television”

Source: D. Forsyth

slide-70
SLIDE 70

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

  • 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

slide-71
SLIDE 71

Wagon-wheel effect

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

Source: L. Zhang

slide-72
SLIDE 72

Wagon-wheel effect

https://www.youtube.com/watch?v=QOwzkND_ooU

slide-73
SLIDE 73

Sampling an image

Examples of GOOD sampling

slide-74
SLIDE 74

Undersampling

Examples of BAD sampling -> Aliasing

slide-75
SLIDE 75

Anti-aliasing

Forsyth and Ponce 2002

slide-76
SLIDE 76

Gaussian (low-pass) pre-filtering

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

  • Solution: filter the image, then subsample

Source: S. Seitz

slide-77
SLIDE 77

Subsampling with Gaussian pre-filtering

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

  • Solution: filter the image, then subsample

Source: S. Seitz

slide-78
SLIDE 78

Compare with...

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

Source: S. Seitz

slide-79
SLIDE 79

Why does a lower resolution image still make sense to us? What do we lose?

Image: http://www.flickr.com/photos/igorms/136916757/

slide-80
SLIDE 80

Why do we get different, distance-dependent interpretations of hybrid images?

?

slide-81
SLIDE 81

Hybrid Image in FFT

Hybrid Image Low-passed Image High-passed Image

slide-82
SLIDE 82

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

slide-83
SLIDE 83

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

slide-84
SLIDE 84

Image interpolation

1 2 3 4 5

d = 1 in this example

Adapted from: S. Seitz

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

slide-85
SLIDE 85

Image interpolation

1 2 3 4 5 2.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

slide-86
SLIDE 86

Image interpolation

“Ideal” reconstruction Nearest-neighbor interpolation Linear interpolation Gaussian reconstruction

Source: B. Curless

slide-87
SLIDE 87

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

slide-88
SLIDE 88

Image interpolation

Nearest-neighbor interpolation Bilinear interpolation Bicubic interpolation

Original image: x 10

slide-89
SLIDE 89

Image interpolation

Also used for resampling

slide-90
SLIDE 90

Things to Remember

  • Sometimes it makes sense to think of

images and filtering in the frequency domain

  • Fourier analysis
  • Can be faster to filter using FFT for large

images (N logN vs. N2 for auto-correlation)

  • Images are mostly smooth
  • Basis for compression
  • Remember to low-pass before sampling
slide-91
SLIDE 91

Thank you

  • Next class:
  • Pyramid, template matching