the frequency domainguerzhoy/320/lec/freqdomain.pdff(x) fourier f( ) transform f( ) inverse fourier...

59
The Frequency Domain CSC320: Introduction to Visual Computing Michael Guerzhoy Many slides borrowed from Steve Seitz, Alexei Efros, Derek Hoiem, Allan Jepson, David Fleet, John M. Brayer Randall Munroe, http://xkcd.com/26/

Upload: others

Post on 16-Oct-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

The Frequency Domain

CSC320: Introduction to Visual Computing

Michael GuerzhoyMany slides borrowed from Steve Seitz, Alexei Efros, Derek Hoiem, Allan Jepson, David Fleet, John M. Brayer

Randall Munroe, http://xkcd.com/26/

Page 2: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

Salvador Dali

“Gala Contemplating the Mediterranean Sea,

which at 30 meters becomes the portrait

of Abraham Lincoln”, 1976

Page 3: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of
Page 4: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of
Page 5: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

A set of basis vectors

This change of basis has a special name…

Teases away fast vs. slow changes in the image.

Page 6: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

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 other 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

LagrangeLegendre

Page 7: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

A sum of sines

Our building block:

Add enough of them to get

any signal f(x) you want!

What does each control?

Which one encodes the

coarse vs. fine structure of

the signal?

xAsin(

Page 8: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

Fourier Transform

We want to understand the frequency of our signal. So,

let’s reparametrize the signal by instead of x:

xAsin(

f(x) F()Fourier

Transform

F() f(x)Inverse Fourier

Transform

For every from 0 to inf, F() holds the amplitude A

and phase of the corresponding sine • How can F hold both? Complex number trick!

)()()( iIRF 22 )()( IRA

)(

)(tan 1

R

I

We can always go back:

Page 9: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

Time and Frequency

example : g(t) = sin(2pf t) + (1/3)sin(2p(3f) t)

Page 10: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

Time and Frequency

example : g(t) = sin(2pf t) + (1/3)sin(2p(3f) t)

= +

Page 11: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

Frequency Spectra

example : g(t) = sin(2pf t) + (1/3)sin(2p(3f) t)

= +

Page 12: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

Frequency Spectra

Usually, frequency is more interesting than the phase

Page 13: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

= +

=

Frequency Spectra

Page 14: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

= +

=

Frequency Spectra

Page 15: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

= +

=

Frequency Spectra

Page 16: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

= +

=

Frequency Spectra

Page 17: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

= +

=

Frequency Spectra

Page 18: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

= 1

1sin(2 )

k

A ktk

Frequency Spectra

Page 19: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

Frequency Spectra

Page 20: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

FT: Just a change of basis

.

.

.

* =

M * f(x) = F()

Page 21: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

IFT: Just a change of basis

.

.

.

* =

M-1 * F() = f(x)

Page 22: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

Finally: Scary Math

Page 23: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

Finally: Scary Math

…not really scary:

is hiding our old friend:

So it’s just our signal f(x) times sine at frequency

)sin()cos( xixe xi

Q

PQPΑ

xAxQxP

122 tan

sin()sin()cos(

xAsin(

phase can be encoded

by sin/cos pair

Page 24: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

Extension to 2D

Page 25: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

2D Discrete Fourier Transform

Page 26: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

2D Discrete Fourier Transform (DFT)

• If ℎ 𝑘, 𝑙 is the 2D DFT of h, then

• |ℎ 𝑘, 𝑙 |2 = 𝑅𝑒 ℎ 𝑘, 𝑙2+ 𝐼𝑚 ℎ 𝑘, 𝑙

2is the power

spectrum of h

Page 27: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

2D Fourier Basis Functions

http://www.algebra.com/algebra/homework/word/geometry/Altitud

e-drawn-to-the-hypotenuse-in-a-right-triangle.lesson

Note:

(0, 0) is in the top-left

corner in the images

here.

In other images in this

lecture, the origin is on

the bottom-left

Page 28: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

Zero crossings

• Zero crossing of sin 𝜔𝑘𝑛 + 𝜔𝑙𝑚 :• 𝜔𝑘𝑛 + 𝜔𝑙𝑚 = 𝑞𝜋 for some q

• Corresponds to an “edge” in the grating (switch

from positive numbers to negatives, or vice versa)

• What is the orientation of the edge?

• 𝜔𝑘𝑛 + 𝜔𝑙𝑚 = 𝑞𝜋

• 𝑚 =𝑞𝜋

𝜔𝑙+ (−𝜔𝑘/𝜔𝑙)𝑛

• The slope (−𝜔𝑘/𝜔𝑙) determines the direction

• (−𝜔𝑘/𝜔𝑙) positive the edge goes top-left to

bottom-right

• (−𝜔𝑘/𝜔𝑙) negative the edge goes bottom-

left to top-right

• (−𝜔𝑘/𝜔𝑙) zero the edge is horizontal

• (−𝜔𝑘/𝜔𝑙) is infinity (i.e., 𝜔𝑙 = 0) edge is

vertical

Page 29: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

Fourier analysis in images

Intensity Image

Fourier Image

https://web.archive.org/web/20130513181427/http://sharp.bu.edu/~slehar/fourier/fourier.html

• The dot at the centre is the “zero frequency” term (the

sum of the image): 𝑛,𝑚 𝑒−𝑖 0×𝑛+0×𝑚 ℎ(𝑛,𝑚)

• Why two dots off side?

Page 30: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

Why Two Dots?

https://web.archive.org/web/20130513181427/http://sharp.bu.edu/~slehar/fourier/fourier.html

• One for 𝑘, 𝑙 = 1,1• One for 𝑘, 𝑙 = −1,−1• Note: the gratings for those look the same for the real

part

• Say F is a 2D Fourier transform of a real image f. Then:

• |F(u,v)| = |F(-u, -v)|• (Since cos(x) = cos(-x), sin(-x) = -sin(x). Details: exercise)

Page 31: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

Signals can be composed

+ =

More: http://www.cs.unm.edu/~brayer/vision/fourier.html

https://web.archive.org/web/20130513181427/http://sharp.bu.edu/~slehar/fourier/fourier.html

Page 32: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

Man-made Scene

Page 33: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

The FT of man-made scenes

• Edges have to be represented as sums of

gratings, with the gratings in the same

general direction as the edges• Partly* explains the high magnitude of the FT along the n

and m axis in most outdoor images

• Other edges also need to be represented• In the Colosseum photo on the previous slide, we have two

edge directions that are not vertical or horizontal

• They correspond to the lines you see on the FT magnitude

image (note: while in the photo (0,0) is on the top right and

x and y increase going to the bottom-right, in the FT

magnitude image,

Page 34: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

*Small print on the “+” pattern(aside, not covered in

detail): Edge Effects

Two FTs of similar patterns

Page 35: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

Aside, continued (not covered in detail)

• We treat the image as if it were tiling the

entire plane, so if the left/right, top/bottom

ends are different, we get “edge effects”

Page 36: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

Can change spectrum, then reconstruct

Page 37: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

Low Pass filtering

• Only keep the low frequencies, set the

coefficients of the high frequencies to 0

• Similar to blurring with a Gaussian kernel

Page 38: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

High Pass filtering

• Only keep the high frequencies, set the

coefficients of the low frequencies to 0

• We’ll talk later how to implement this using

filters

Page 39: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

Log Magnitude

Strong Vertical Frequency

(Sharp Horizontal Edge)

Strong Horz. Frequency

(Sharp Vert. Edge)

Diagonal Frequencies

Low Frequencies

Page 40: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

The Convolution Theorem

The greatest thing since sliced (banana) bread!

• 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[ hghg

][F][F][F 111 hggh

Page 41: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

2D convolution theorem example

*

f(x,y)

h(x,y)

g(x,y)

|F(sx,sy)|

|H(sx,sy)|

|G(sx,sy)|

Page 42: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

The Ringing Artifact, Again

Gaussian Box filter

Page 43: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

Gaussian Filtering

• The FT of a Gaussian(𝜎) is Gaussian(1/𝜎)• You can prove it with integrals, or experimentally, or just

trust me

• The Convolution Theorem gives us:

Page 44: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

Box Filtering isn’t as nice

• The FT of a box filter is similar to what we

saw for the step function: high frequencies

remain

Page 45: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

Fourier Transform Pairs

Page 46: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

Low-pass, Band-pass, High-pass filters

low-pass:

Band-pass:

Page 47: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

Edges in images

Page 48: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

What does blurring take away?

original

Page 49: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

What does blurring take away?

smoothed (5x5 Gaussian)

Page 50: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

High-Pass filter

smoothed – original

Page 51: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

Band-pass filtering

Laplacian Pyramid (subband images)Created from Gaussian pyramid by subtraction

Gaussian Pyramid (low-pass images)

Page 52: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

Da Vinci and Peripheral Vision

Page 53: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

Leonardo playing with peripheral vision

Page 54: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

Unsharp Masking

200 400 600 800

100

200

300

400

500

- =

=+ a

Page 55: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

Unsharp Masking

• The blurred image has all the low frequency components intact

• If we subtract the blurred image from the original, we only keep the high frequencies

Page 56: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

Unsharp masking

• If in the original, a pixel is brighter than its neigbours, the difference image will be positive

• If in the original, a pixel is darker than its neigbours, the difference image will be negative

• Otherwise, the difference image is around 0

• So adding the difference image had little effect away from the edges, and will tend to exaggerate the edges

• That is called “sharpening:” the edges will become less blurry

Page 57: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

Lossy Image Compression (JPEG)

Block-based Discrete Cosine Transform (DCT) (similar to DFT)

Page 58: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

Using DCT in JPEG

• The first coefficient B(0,0) is the DC

component, the average intensity

• The top-left coeffs represent low frequencies,

the bottom right represent high frequencies

• Store as much of the top left as you can

Page 59: The Frequency Domainguerzhoy/320/lec/FreqDomain.pdff(x) Fourier F( ) Transform F( ) Inverse Fourier f(x) Transform For every from 0 to inf, F( ) holds the amplitude A and phase of

Hybrid Images

?

http://cvcl.mit.edu/hybrid_gallery/gallery.html