Fourier Transform and Image Filtering - SCI Home

82
Fourier Transform and Image Filtering CS/BIOEN 6640 Lecture Marcel Prastawa Fall 2010

Transcript of Fourier Transform and Image Filtering - SCI Home

Page 1: Fourier Transform and Image Filtering - SCI Home

Fourier Transform and

Image Filtering

CS/BIOEN 6640Lecture Marcel Prastawa

Fall 2010

Page 2: Fourier Transform and Image Filtering - SCI Home

The Fourier Transform

Page 3: Fourier Transform and Image Filtering - SCI Home

Fourier Transform

• Forward, mapping to frequency domain:

• Backward, inverse mapping to time domain:

Page 4: Fourier Transform and Image Filtering - SCI Home

Fourier Series

• Projection or change of basis• Coordinates in Fourier basis:

• Rewrite f as:

Page 5: Fourier Transform and Image Filtering - SCI Home

Example: Step FunctionStep function as sum of infinite sine waves

Page 6: Fourier Transform and Image Filtering - SCI Home

Discrete Fourier Transform

Page 7: Fourier Transform and Image Filtering - SCI Home

Fourier Basis

• Why Fourier basis?

• Orthonormal in [-pi, pi]• Periodic• Continuous, differentiable basis

Page 8: Fourier Transform and Image Filtering - SCI Home

FT Properties

Page 9: Fourier Transform and Image Filtering - SCI Home

Common Transform PairsDirac delta - constant

Page 10: Fourier Transform and Image Filtering - SCI Home

Common Transform PairsRectangle – sinc

sinc(x) = sin(x) / x

Page 11: Fourier Transform and Image Filtering - SCI Home

Common Transform PairsTwo symmetric Diracs - cosine

Page 12: Fourier Transform and Image Filtering - SCI Home

Common Transform Pairs

Comb – comb (inverse width)

Page 13: Fourier Transform and Image Filtering - SCI Home

Common Transform PairsGaussian – Gaussian (inverse variance)

Page 14: Fourier Transform and Image Filtering - SCI Home

Common Transform Pairs Summary

Page 15: Fourier Transform and Image Filtering - SCI Home

Quiz

What is the FT of a triangle function?

Hint: how do you get triangle function from the functions shown so far?

Page 16: Fourier Transform and Image Filtering - SCI Home

Triangle Function FTTriangle = box convolved with box

So its FT is sinc * sinc

Page 17: Fourier Transform and Image Filtering - SCI Home

Fourier Transform of Images

Page 18: Fourier Transform and Image Filtering - SCI Home

• Forward transform:

• Backward transform:

• Forward transform to freq. yields complex values (magnitude and phase):

2D Fourier Transform

Page 19: Fourier Transform and Image Filtering - SCI Home

2D Fourier Transform

Page 20: Fourier Transform and Image Filtering - SCI Home

Fourier Spectrum

Fourier spectrumOrigin in corners

Retiled with originIn center

Log of spectrum

Image

Page 21: Fourier Transform and Image Filtering - SCI Home

Fourier Spectrum–Rotation

Page 22: Fourier Transform and Image Filtering - SCI Home

Phase vs Spectrum

Image Reconstruction fromphase map

Reconstruction fromspectrum

Page 23: Fourier Transform and Image Filtering - SCI Home

Fourier Spectrum Demo

http://bigwww.epfl.ch/demo/basisfft/demo.html

Page 24: Fourier Transform and Image Filtering - SCI Home

Low-Pass Filter• Reduce/eliminate high frequencies• Applications

– Noise reduction• uncorrelated noise is broad band• Images have sprectrum that focus on low

frequencies

86%

88%

90%

92%

94%

96%

98%

100%

0% 10% 20% 30% 40% 50% 60% 70% 80%

Page 25: Fourier Transform and Image Filtering - SCI Home

Ideal LP Filter – Box, Rect

Cutoff freq Ringing – Gibbs phenomenon

Page 26: Fourier Transform and Image Filtering - SCI Home

Extending Filters to 2D (or higher)

• Two options– Separable

• H(s) -> H(u)H(v)• Easy, analysis

– Rotate• H(s) -> H((u2 + v2)1/2)• Rotationally invariant

Page 27: Fourier Transform and Image Filtering - SCI Home

Ideal LP Filter – Box, Rect

Page 28: Fourier Transform and Image Filtering - SCI Home

Ideal Low-Pass Rectangle With Cutoff of 2/3

Image Filtered Filtered + HE

Page 29: Fourier Transform and Image Filtering - SCI Home

Ideal LP – 1/3

Page 30: Fourier Transform and Image Filtering - SCI Home

Ideal LP – 2/3

Page 31: Fourier Transform and Image Filtering - SCI Home

Butterworth Filter

Control of cutoff and slopeCan control ringing

Page 32: Fourier Transform and Image Filtering - SCI Home

Butterworth - 1/3

Page 33: Fourier Transform and Image Filtering - SCI Home

Butterworth vs Ideal LP

Page 34: Fourier Transform and Image Filtering - SCI Home

Butterworth – 2/3

Page 35: Fourier Transform and Image Filtering - SCI Home

Gaussian LP FilteringILPF BLPF GLPF

F1

F2

Page 36: Fourier Transform and Image Filtering - SCI Home

High Pass Filtering

• HP = 1 - LP– All the same filters as HP apply

• Applications– Visualization of high-freq data (accentuate)

• High boost filtering– HB = (1- a) + a(1 - LP) = 1 - a*LP

Page 37: Fourier Transform and Image Filtering - SCI Home

High-Pass Filters

Page 38: Fourier Transform and Image Filtering - SCI Home

High-Pass Filters in Spatial Domain

Page 39: Fourier Transform and Image Filtering - SCI Home

High-Pass Filtering with IHPF

Page 40: Fourier Transform and Image Filtering - SCI Home

BHPF

Page 41: Fourier Transform and Image Filtering - SCI Home

GHPF

Page 42: Fourier Transform and Image Filtering - SCI Home

HP, HB, HE

Page 43: Fourier Transform and Image Filtering - SCI Home

High Boost with GLPF

Page 44: Fourier Transform and Image Filtering - SCI Home

High-Boost Filtering

Page 45: Fourier Transform and Image Filtering - SCI Home

Band-Pass Filters

• Shift LP filter in Fourier domain by convolution with delta

LP

BPTypically 2-3 parameters-Width-Slope-Band value

Page 46: Fourier Transform and Image Filtering - SCI Home

Band Pass - Two Dimensions

• Two strategies– Rotate

• Radially symmetric– Translate in 2D

• Oriented filters

• Note:– Convolution with delta-pair in FD is

multiplication with cosine in spatial domain

Page 47: Fourier Transform and Image Filtering - SCI Home

Band Bass Filtering

Page 48: Fourier Transform and Image Filtering - SCI Home

SEM Image and Spectrum

Page 49: Fourier Transform and Image Filtering - SCI Home

Band-Pass Filter

Page 50: Fourier Transform and Image Filtering - SCI Home

Radial Band Pass/Reject

Page 51: Fourier Transform and Image Filtering - SCI Home

Band Reject Filtering

Page 52: Fourier Transform and Image Filtering - SCI Home

Band Reject Filtering

Page 53: Fourier Transform and Image Filtering - SCI Home

Band Reject Filtering

Page 54: Fourier Transform and Image Filtering - SCI Home

Aliasing

Page 55: Fourier Transform and Image Filtering - SCI Home

Discrete Sampling and Aliasing

• Digital signals and images are discrete representations of the real world – Which is continuous

• What happens to signals/images when we sample them?– Can we quantify the effects? – Can we understand the artifacts and can we limit

them?– Can we reconstruct the original image from the

discrete data?

Page 56: Fourier Transform and Image Filtering - SCI Home

A Mathematical Model of Discrete Samples

Delta functional

Shah functional

Page 57: Fourier Transform and Image Filtering - SCI Home

A Mathematical Model of Discrete Samples

Discrete signal

Samples from continuous function

Representation as a function of t• Multiplication of f(t) with Shah

• Goal– To be able to do a continuous Fourier

transform on a signal before and after sampling

Page 58: Fourier Transform and Image Filtering - SCI Home

Fourier Series of A Shah Functional

u

Page 59: Fourier Transform and Image Filtering - SCI Home

Fourier Transform of A Discrete Sampling

u

Page 60: Fourier Transform and Image Filtering - SCI Home

Fourier Transform of A Discrete Sampling

u

Energy from higher freqs gets folded back down into lower freqs –Aliasing

Frequencies get mixed. The original signal is not recoverable.

Page 61: Fourier Transform and Image Filtering - SCI Home

What if F(u) is Narrower in the Fourier Domain?

u

• No aliasing!• How could we recover the original

signal?

Page 62: Fourier Transform and Image Filtering - SCI Home

What Comes Out of This Model

• Sampling criterion for complete recovery

• An understanding of the effects of sampling– Aliasing and how to avoid it

• Reconstruction of signals from discrete samples

Page 63: Fourier Transform and Image Filtering - SCI Home

Shannon Sampling Theorem

• Assuming a signal that is band limited:

• Given set of samples from that signal

• Samples can be used to generate the original signal– Samples and continuous signal are

equivalent

Page 64: Fourier Transform and Image Filtering - SCI Home

Sampling Theorem• Quantifies the amount of information in

a signal– Discrete signal contains limited frequencies– Band-limited signals contain no more

information then their discrete equivalents• Reconstruction by cutting away the

repeated signals in the Fourier domain– Convolution with sinc function in

space/time

Page 65: Fourier Transform and Image Filtering - SCI Home

Reconstruction

• Convolution with sinc function

Page 66: Fourier Transform and Image Filtering - SCI Home

Sinc Interpolation Issues

• Must functions are not band limited• Forcing functions to be band-limited can

cause artifacts (ringing)

f(t) |F(s)|

Page 67: Fourier Transform and Image Filtering - SCI Home

Sinc Interpolation Issues

Ringing - Gibbs phenomenonOther issues:

Sinc is infinite - must be truncated

Page 68: Fourier Transform and Image Filtering - SCI Home

Aliasing• High frequencies appear as low

frequencies when undersampled

Page 69: Fourier Transform and Image Filtering - SCI Home

Aliasing

16 pixels8 pixels

0.9174pixels

0.4798pixels

Page 70: Fourier Transform and Image Filtering - SCI Home

Overcoming Aliasing

• Filter data prior to sampling– Ideally - band limit the data (conv with sinc

function)– In practice - limit effects with fuzzy/soft low

pass

Page 71: Fourier Transform and Image Filtering - SCI Home

Antialiasing in Graphics

• Screen resolution produces aliasing on underlying geometry

Multiple high-res samples get averaged to create one screen sample

Page 72: Fourier Transform and Image Filtering - SCI Home

Antialiasing

Page 73: Fourier Transform and Image Filtering - SCI Home

Interpolation as Convolution

• Any discrete set of samples can be considered as a functional

• Any linear interpolant can be considered as a convolution– Nearest neighbor - rect(t)– Linear - tri(t)

Page 74: Fourier Transform and Image Filtering - SCI Home

Convolution-Based Interpolation

• Can be studied in terms of Fourier Domain• Issues

– Pass energy (=1) in band– Low energy out of band– Reduce hard cut off (Gibbs, ringing)

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

1.2

-6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6

Page 75: Fourier Transform and Image Filtering - SCI Home

Fast Fourier Transform

With slides from Richard Stern, CMU

Page 76: Fourier Transform and Image Filtering - SCI Home

DFT

• Ordinary DFT is O(N2)• DFT is slow for large images

• Exploit periodicity and symmetricity• Fast FT is O(N log N)• FFT can be faster than convolution

Page 77: Fourier Transform and Image Filtering - SCI Home

Fast Fourier Transform

• Divide and conquer algorithm• Gauss ~1805• Cooley & Tukey 1965

• For N = 2K

Page 78: Fourier Transform and Image Filtering - SCI Home

The Cooley-Tukey Algorithm• Consider the DFT algorithm for an integer power of 2,

• Create separate sums for even and odd values of n:

• Letting for n even and for n odd, we obtain

N = 2ν

X[k] =n=0

N−1∑ x[n]WN

nk =n=0

N−1∑ x[n]e− j2πnk / N ; WN = e− j2π / N

X[k] = x[n]WNnk +

n even∑ x[n]WN

nk

n odd∑

n = 2r n = 2r +1

X[k] = x[2r]WN2rk +

r=0

N / 2( )−1∑ x[2r +1]WN

2r+1( )k

r=0

N /2( )−1∑

Page 79: Fourier Transform and Image Filtering - SCI Home

The Cooley-Tukey Algorithm• Splitting indices in time, we have obtained

• But andSo …

N/2-point DFT of x[2r] N/2-point DFT of x[2r+1]

X[k] = x[2r]WN2rk +

r=0

N / 2( )−1∑ x[2r +1]WN

2r+1( )k

r=0

N /2( )−1∑

WN2 = e− j2π2 / N = e− j2π /(N / 2) = WN / 2 WN

2rkWNk = WN

kWN / 2rk

X[k] =n=0

(N/ 2)−1∑ x[2r]WN /2

rk + WNk

n=0

(N/ 2)−1∑ x[2r +1]WN / 2

rk

Page 80: Fourier Transform and Image Filtering - SCI Home

Example: N=8

• Divide and reuse

Page 81: Fourier Transform and Image Filtering - SCI Home

Example: N=8, Upper Part

• Continue to divide and reuse

Page 82: Fourier Transform and Image Filtering - SCI Home

Two-Point FFT• The expression for the 2-point DFT is:

• Evaluating for we obtain

which in signal flowgraph notation looks like ...

X[k] =n=0

1∑ x[n]W2

nk =n=0

1∑ x[n]e− j2πnk / 2

k = 0,1X[0] = x[0]+ x[1]

X[1] = x[0] + e− j2π1/ 2x[1] = x[0]− x[1]

This topology is referred to as thebasic butterfly