Download as pdf or txt
Download as pdf or txt
You are on page 1of 96

EECE\CS 253 Image Processing

Lecture Notes: The 1&2-Dimensional Lecture Notes Fourier Transforms

Richard Alan Peters II


Department of Electrical Engineering and Computer Science
Fall Semester 2012

This work is licensed under the Creative Commons Attribution-Noncommercial 2.5 License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc/2.5/ or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.

Signal:
A measurable phenomenon that changes over time or throughout space.
sound image

code

01101000101101110110010110001
2013-03-08 1999-2013 by Richard Alan Peters II 2

Signals: Space-Time vs. FrequencyDomain Representation


Space/time representation: a graph of the measurements with respect to a point in time and/or positions in space. Fact: signals undulate (otherwise theyd contain no information). Frequency-domain representation: an exact description of a signal in terms of its undulations.

2013-03-08

1999-2013 by Richard Alan Peters II

Origin of Sounds

The mechanical vibrations of an object in an atmosphere. Vibrations: internal elastic motions of the material. The surface of the object undulates causing compressions and rarefactions in the air which propagate through the air away from the surface. An object vibrates with different modes. A mode is a vibratory pattern with a distinctive shape part of the object surface moves out while another part moves in a standing wave.
1999-2013 by Richard Alan Peters II 4

2013-03-08

Vibratory Modes / Standing Waves: Examples

displacement from rest position

internal pressure

string modes
Note that the modes are all sinusoids.

pipe modes
Note that the negatives of these also will occur

2013-03-08

1999-2013 by Richard Alan Peters II

Sound Waves:

Emerge from the superposition of the modes.

string sound

pipe sound

2013-03-08

1999-2013 by Richard Alan Peters II

Sound Waves:

Emerge from the superposition of the modes.

Even-order harmonics

The vibratory modes add up to one complex motion that pushes the air around the vibrating object

string sound

pipe sound

Odd-order harmonics

2013-03-08

1999-2013 by Richard Alan Peters II

Fact: Any Real Signal has a Frequency-Domain Representation


The modes shown (blue) sum to the rippling square wave (black). As the number of modes in the sum becomes large, it approaches a square wave (red).
2013-03-08

Odd-order harmonics
sq (t ) = 2p 1 sin 2 n 1 t + ( ) + 2 n 1 l n=-

1999-2013 by Richard Alan Peters II

Frequency-Domain Representation
Any periodic signal can be described by a sum of sinusoids.
sq (t ) = 2p 1 n t sin 2 1 + ( ) l n=- 2n + 1

The sinusoids are called basis functions. The multipliers are called Fourier coefficients.
2013-03-08 1999-2013 by Richard Alan Peters II 9

Frequency-Domain Representation
Any periodic signal can be described by a sum of sinusoids.
sq (t ) = 2p 1 n t sin 2 1 + ( ) l n=- 2n + 1

The sinusoids are called basis functions. The multipliers are called Fourier coefficients.
2013-03-08

Basis functions
10

1999-2013 by Richard Alan Peters II

Frequency-Domain Representation
Any periodic signal can be described by a sum of sinusoids.
sq (t ) = 2p 1 n t sin 2 1 + ( ) l n=- 2n + 1

The sinusoids are called basis functions. The multipliers are called Fourier coefficients.
2013-03-08

1999-2013 by Richard Alan Peters II

The Fourier coefficients (of a square wave).

11

Example: Partial Sums of a Square Wave


The limit of the given sequence of partial sums1 is exactly a square wave

1 sine

2 sines

4 sines

8 sines
2013-03-08

16 sines
1999-2013 by Richard Alan Peters II

32 sines

the limit as n approaches infinity of the sum of n sines.


1

12

Anatomy of a Sinusoid
f (t)

2p t - f f (t ) = A sin l

2013-03-08

1999-2013 by Richard Alan Peters II

13

The Inner Product: a Measure of Similarity


The similarity between functions f and g on the interval (- / 2, / 2) can be defined by
l /2

f,g =

-l /2

f (t ) g * (t ) dt

where g * (t ) is the complex conjugate of g (t ).

This number, called the inner product of f and g , can also be thought of as the amount of g in f or as the projection of f onto g .
If f and g have the same energy, then their inner product is maximal if f = g . On the other hand if f , g = 0, then f and g have nothing in common.
2013-03-08 1999-2013 by Richard Alan Peters II 14

Inner Products

a function, f

pointwise product f(t)g(t)

1024

g is a component of f
0

f (t ) g (t )dt 0.12

2013-03-08

1999-2013 by Richard Alan Peters II

15

Inner Products

a function, f

pointwise product f(t)h(t)

1024

h is a not a comp. of f
0

f (t )h(t )dt 0

2013-03-08

1999-2013 by Richard Alan Peters II

16

Inner Product of a Periodic Function and a Sinusoid

3 different representations

2013-03-08

1999-2013 by Richard Alan Peters II

17

Inner Product of a Periodic Function and a Sinusoid

real number results yield the amplitude of that sinusoid in the function.

2013-03-08

1999-2013 by Richard Alan Peters II

18

Inner Product of a Periodic Function and a Sinusoid

Complex number result yields the amplitude and phase of that sinusoid in the function.

2013-03-08

1999-2013 by Richard Alan Peters II

19

The Fourier Series


f (t ) = A0 +

is the decomposition of a -periodic signal into a sum of sinusoids.


The representation of a function by its Fourier Series is the sum of sinusoidal basis functions multiplied by coefficients. Fourier coefficients are generated by taking the inner product of the function with the basis. The basis functions correspond to modes of vibration.
20

n=1

2p n 2p n + Bn sin An cos t t l l

periodic : $l such that f (t nl ) = f (t )


l /2

2 An = l 2 Bn = l
2013-03-08


-l /2 l /2

2p n f (t ) cos t j dt for n 0 n l 2p n f (t ) sin t j dt for n 0 n l


1999-2013 by Richard Alan Peters II


-l /2

The Fourier Series


f (t ) = =
n=-

can also be written in terms of complex exponentials


2 p n +fn + l

Ce
n

pn i 2l t

n=-

Cn e

i = -1

2pn 2pn + + + cos f sin f C t C t n n n n l l n=-


+ ifn l /2 2 pn -i t 1 l dt = f (t ) e l -l /2

Cn = Cn e+ifn eix = cos x + i sin x


f (t + nl ) = f (t ) for all integers n

Cn = Cn e

2p n 2p n 1 = f (t ) cos + + t + fn C t sin f dt n n l l l -l /2

l /2

2013-03-08

1999-2013 by Richard Alan Peters II

21

The Fourier Series


f (t ) = [ An cos wnt + Bn sin wnt ], where wn =
n=0

Contd. on next page.

Relationship between the real and the complex Fourier Series


2pn l

l /2 l /2 2 = f (h ) cos wn h d h cos wnt + f (h ) sin wn h d h sin wn t l n=0 -l /2 -l /2

2 = f (h )[cos wn h cos wnt + f (h ) sin wn h sin wnt ] d h l n=0 -l /2 l /2 The sine-plus-cosine 1 = f (h ) cos (wn h - wnt ) d h form results from the l n=0 -l /2 projection of f onto a cosine that is in phase with the current time.
2013-03-08 1999-2013 by Richard Alan Peters II 22

l /2

Relationship between the real and the complex Fourier Series (contd.)
Claim:
0=
l /2

Contd. on next page.

n=-

sin (w h - w t ).
n n

Therefore: Thus:

-l /2

f (h ) sin (wn h - wnt ) d h = 0. n=-

l /2 1 -i f (h ) sin (wn h - wn t ) d h = 0. l n=- -l /2

Then add zero to the equation at the end of the previous page:

l /2 l /2 1 1 f (t ) = f (h ) cos (wn h - wnt ) d h - i f (h ) sin (wn h - wnt ) d h . l n=- -l /2 l n=- -l /2

2013-03-08

1999-2013 by Richard Alan Peters II

23

Relationship between the real and the complex Fourier Series (contd.)
l /2 l /2 1 1 f (t ) = f (h ) cos (wn h - wnt ) d h - i f (h ) sin (wn h - wnt ) d h l n=- -l /2 l n=- -l /2

1 = f (h )[cos wn (h - t ) - i sin wn (h - t )] d h l n=- -l /2 1 = f (h ) e-iwn (h-t )d h l n=- -l /2


2 pn 2 pn h -i +i t 1 l l h h f e d e = ( ) n=- l -l /2 l /2 l /2

l /2

Then some algebraic manipulations lead to the result.


2 pn + + n l

n=-

Ce
n

pn i 2l t

n=-

Cn e e

ifn

pn i 2l t

n=-

Cn e

t f

2013-03-08

1999-2013 by Richard Alan Peters II

24

Relationship between the real and the complex Fourier Series (contd.)
l /2 l /2 1 1 f (t ) = f (h ) cos (wn h - wnt ) d h - i f (h ) sin (wn h - wnt ) d h l n=- -l /2 l n=- -l /2

1 = f (h )[cos wn (h - t ) - i sin wn (h - t )] d h l n=- -l /2 1 = f (h ) e-iwn (h-t )d h l n=- -l /2


2 pn 2 pn h -i +i t 1 l l h h f e d e = ( ) n=- l -l /2 l /2 l /2

l /2

Then some algebraic manipulations lead to the result.


2 pn + + n l

n=-

Ce
n

pn i 2l t

n=-

Cn e e

ifn

pn i 2l t

n=-

Cn e

t f

2013-03-08

1999-2013 by Richard Alan Peters II

25

Why are Fourier Coefficients Complex Numbers?


f (t ) =
n=-

Cn e

+i

2 pn t l

where Cn = Cn e +ifn .

Cn represents the amplitude, A=|Cn|, and relative phase, , of that part of the original signal, f (t), that is a sinusoid of frequency n = 2n / .

intensity

0
0

frequency, = 1/

2013-03-08

1999-2013 by Richard Alan Peters II

26

What about real + imaginary?

F (w ) = ( N2A co s )[d (w + N l ) + d (w - N l )] + i ( N2A sin )[- d (w + N l ) + d (w - N l )]

The FS of a cosine is a pair of impulses with complex amplitudes


2013-03-08 1999-2013 by Richard Alan Peters II 27

The real and imaginary parts at the positive frequency, N/ ...

Real + Imaginary to Magnitude & Phase

form a magnitude, NA/2, and a phase, 0.


2013-03-08 1999-2013 by Richard Alan Peters II 28

The real and imaginary parts at the negative frequency, -N/ ...

Real + Imaginary to Magnitude & Phase

form a magnitude, NA/2, and a phase, -0.


2013-03-08 1999-2013 by Richard Alan Peters II 29

Fourier Series of a Square Wave


Time-domain signal

Fourier magnitude

Fourier phase

2013-03-08

1999-2013 by Richard Alan Peters II

30

The Fourier Transform


is the decomposition of a nonperiodic signal into a continuous sum* of sinusoids.

F ( w ) = F (w ) e

iF(w )

= f (t ) e i 2 p w t dt
-

= f (t )[cos ( 2pw t ) + i sin ( 2pw t )] dt


- -i 2 p w t

f (t ) = F (w ) e
-

d w = F (w ) e-i(2 p w t +F(w)) d w
-

= F (w ) [cos ( 2pw t ) - i sin (2pw t )] d w


-

= F (w ) [cos ( 2pw t +F (w )) - i sin (2pw t +F (w ))] d w


-

2013-03-08

1999-2013 by Richard Alan Peters II

i.e., an integral.

31

Mammals Use the FT in Hearing

2013-03-08

1999-2013 by Richard Alan Peters II

32

The Discrete Fourier Transform


A discrete signal, {hk k = 0,1, 2, , N 1 }, of finite length N can be repre sented as a weighted sum of N sinusoids, e i 2 k n /N n = 0,1, 2, , N 1 through

hk = H n e i 2 k n /N
n= 0

N 1

where the set, { H n n = 0,1, 2, , N 1}, are the Fourier coefficients defined as the projection of the original signal onto sinusoid, n, given by :

1 N 1 Hn = hk e +i 2 k n /N N k=0
2013-03-08 1999-2013 by Richard Alan Peters II 33

The Two-Dimensional Fourier Transform


Primary Uses of the FT in Image Processing:

Explains why down-sampling can add distortion to an image and shows how to avoid it. Useful for certain types of noise reduction, deblurring, and other types of image restoration. For feature detection and enhancement, especially edge detection.

2013-03-08

1999-2013 by Richard Alan Peters II

34

The Fourier Transform: Discussion


The expressions

F (w ) = f (t ) e-i 2 p w t dt = f (t ) , e+ i 2 p w t
-

continuous signals defined over all real numbers

and 1 Hn = N

he
k n= 0

N -1

-i 2 p k n / N

= hk , e

+i 2 p k n /N

discrete signals with N terms or samples.

for the Fourier coefficients are inner products which can be thought of as measures of the similarity between the functions f (t ) and e + i 2 t for t ( , ) or between the sequences N -1 + i 2 p k n / N N -1 { hk } k =0 and { e } k =0 .
2013-03-08 1999-2013 by Richard Alan Peters II 35

The Fourier Transform: Discussion (contd.)


In the context of inner products, the complex exponentials

{ e-i2pw t

w and w (- , )

} and { e-i 2pk n/N

, -2, -1, 0,1, 2,

}
, if w 1= w 2 if w 1 w 2 c , if j = k if j k

are called orthogonal sets since they have the property:

e-i 2 p w 1 t , e-i 2p w 2 t = e-i 2 p w 1 t e+ i 2 p w 2 t dt = { 0,


-

-i 2 p j n / N

, e

-i 2 p k n / N

= e-i 2 p j n /N e+i 2 p k n /N = { 0,
N -1 n= 0

The function sets are called orthogonal basis sets

They are called basis sets since for any function1, f (t), of a real variable there exists a complex-valued function F(w), and for any sequence1, hk , there exist complex numbers, Hn , such that

f (t ) = F (w ) e
-
2013-03-08

-i 2 p w t

d w and hk = H n e-i 2p k n /N .
n= 0

N -1

1 with

finite energy.
36

1999-2013 by Richard Alan Peters II

The Fourier Transform: Discussion (contd.)


Consider the 2-dimensional functions

{e

-i 2 p ( ux + vy )

u , v, x, y }

and

{e

jm -i 2 p ( M + kn ) N

j , m 0, ..., M - 1, k , n 0,..., N- 1

These are, likewise, orthogonal:


e-i 2 p(u1x+v1 y) , e-i 2 p (u2 x+v2 y)

= =

- -

e-i 2 p (u1x+v1 y) e+ i 2 p (u2 x+v2 y) dxdy ,


2 2

, if u1 =u2 and v1 =v2 0, otherwise

j1m + k1n -i 2 p M N

, e

j2 m + k2 n -i 2 p M N

= e
m= 0 n= 0

M -1 N -1

-i 2 p

( jMm + kNn) e+i 2p( jMm + kNn)


1 1

=
2013-03-08

c , if j1 = j2 and k1 = k2 0, otherwise

.
37

1999-2013 by Richard Alan Peters II

The Fourier Transform: Discussion (contd.)


Therefore

{e

- i 2 p ( ux + vy )

u , v, x, y } and

{e

-i2p(

jm M

kn N

j, k , m , n, M

are orthogonal basis sets. This suggests that function f (x,y) defined on the real plane, and sequence {{ hmn }} for integers m and n have analogous Fourier representations,

f ( x, y ) =

- -

F (u , v) e+i 2 p ( ux+vy ) dudv and hmn = H jk e


j= 0 k = 0

M - 1N - 1

jm kn +i 2 p + M N

where the Fourier coefficients are given by


F (u , v) =

- -

f ( x, y) e-i 2 p ( ux+vy ) dxdy and H jk = hmn e


m=0 n=0

M -1 N -1

jm kn -i 2 p + M N

(True for finite energy functions f (x,y) and {{ hmn }}.)


2013-03-08 1999-2013 by Richard Alan Peters II 38

Continuous Fourier Transform

The continuous Fourier transform assumes a continuous image exists in a finite region of an infinite plane.
The BoingBoing Bloggers

2013-03-08

1999-2013 by Richard Alan Peters II

39

Discrete Fourier Transform


The discrete Fourier transform assumes a digital image exists on a closed surface, a torus.

The BoingBoing Bloggers

2013-03-08

1999-2013 by Richard Alan Peters II

40

Discrete Fourier Transform


The discrete Fourier transform assumes a digital image exists on a closed surface, a torus.

The BoingBoing Bloggers

2013-03-08

1999-2013 by Richard Alan Peters II

41

The 2D Fourier Transform of a Digital Image


Let I(r,c) be a single-band (intensity) digital image with R rows and C columns. Then, I(r,c) has Fourier representation
I ( r , c ) = I ( v ,u ) e
u =0 v=0 R-1 C -1 vr uc +i 2 p + R C

where
1 I (v,u ) = RC I ( r ,c ) e r =0 c=0 R-1 C -1 vr uc -i 2 p R+ C

these complex exponentials are 2D sinusoids.

are the R x C Fourier coefficients.


2013-03-08 1999-2013 by Richard Alan Peters II 42

What are 2D sinusoids?


To simplify the situation assume R = C = N. Then

e
where

i 2

vr R

+ uc C

=e

2 (vr + uc) N

=e

2 ( r sin + c cos ) N

,
v = tan -1 ( u ).

v = w sin , u = w cos , w = v 2 + u 2 , and


Write
N = , w

Then by Eulers relation,

Note: since images are indexed by row & col with r down and c to the right, is positive in the clockwise direction.

1 ( r sin + c cos ) i 2p l

= cos [ 2lp (r sin + c cos )] i sin [ 2lp (r sin + c cos )].


Contd. on next page.
1999-2013 by Richard Alan Peters II 43

2013-03-08

What are 2D sinusoids? (contd.)


Both the real part of this,

Re e

1 ( r sin + c cos ) i 2 p l

} = + cos[

2p l

(r sin + c cos )]

and the imaginary part,

Im e

1 ( r sin + c cos ) i 2 p l

} = sin [

2p l

(r sin + c cos )]

are sinusoidal gratings of unit amplitude, period and direction . Then


w 2pw is the radian frequency, and the frequency, of the wavefront N N N is the wavelength in pixels in the wavefront direction. w
1999-2013 by Richard Alan Peters II 44

and =
2013-03-08

2D Sinusoids:
... are plane waves with grayscale amplitudes, periods in terms of lengths, ...

I ( r , c) =

2p A cos (r sin + c cos ) + j + 1 l 2

orientation

= phase shift
2013-03-08 1999-2013 by Richard Alan Peters II 45

2D Sinusoids:

... specific orientations, and phase shifts.

2013-03-08

1999-2013 by Richard Alan Peters II

46

The Fourier Transform of an Image


c v v

I
2013-03-08

Re[F{I}]
1999-2013 by Richard Alan Peters II

Im[F{I}]
47

Points on the Fourier Plane


If R=C=N the point at column freq. u and row freq. v represents a sinusoid with freq. and orientation . If R C then = 1/ where is the length of vector (C/u, R/v) and the wavefront orientation is = tan-1[(v/R)/(u/C)].

2013-03-08

1999-2013 by Richard Alan Peters II

48

Points on the Fourier Plane (of a Digital Image)


In the Fourier transform of an RC digital image, positions u and v indicate the number of repetitions of the sinusoid in those directions. Therefore the wavelengths along the column and row axes are -v direction

More about this later (pp. 66-87).

u = C u wf

and v =

R v

pixels,
of a digital image
-1

and the wavelength in the wavefront direction is


2 2 2 = RC (uR) + (vC ) .

The frequency is the fraction of the sinusoid traversed over one pixel,
u u = C , v = v R

- direction

, and
(0,0)

u direction

wf =

1 2 2 (uR) + (vC ) cycles. RC


row freq. column freq.

The wavefront direction is given by


v wf = tan -1 ( . ) = tan-1 ( vu C R)
u

Note that the wave front direction = only if R=C.


49

2013-03-08

1999-2013 by Richard Alan Peters II

Points on the Fourier Plane


y

Note that is the wavefront direction only if R=C.

x This point represents this particular sinusoidal grating


2013-03-08 1999-2013 by Richard Alan Peters II 50

The Value of a Fourier Coefficient


is a complex number with a real part and an imaginary part. If you represent that number as a magnitude, A, and a phase, , ..these represent the amplitude and offset of the sinusoid with frequency and direction .*
2013-03-08 1999-2013 by Richard Alan Peters II
*See

p. 49.

51

The Value of a Fourier Coefficient


The magnitude and phase representation makes more sense physically since the Fourier magnitude, A (,), at point (,) represents the amplitude of the sinusoid and the phase, (,), represents the offset of the sinusoid relative to origin.
2013-03-08 1999-2013 by Richard Alan Peters II 52

The Fourier Coefficient at (u,v)


So, the point (u,v) on the Fourier plane represents a sinusoidal grating of frequency and orientation .* The complex value, F(u,v), of the FT at point (u,v) represents the amplitude, A, and the phase offset, , of the sinusoid.

2013-03-08

1999-2013 by Richard Alan Peters II

*See

p. 49.

53

The Sinusoid from the Fourier Coeff. at (u,v)

Note that the wave front direction = only if R=C.


2013-03-08 1999-2013 by Richard Alan Peters II 54

FT of an Image (Magnitude + Phase)

I
2013-03-08

log{|F{I}|2+1}
1999-2013 by Richard Alan Peters II

[F{I}]
55

FT of an Image (Real + Imaginary)

I
2013-03-08

Re[F{I}]
1999-2013 by Richard Alan Peters II

Im[F{I}]
56

The Power Spectrum


The power spectrum of a signal is the square of the magnitude of its Fourier Transform.
I (u ,v) = I (u ,v) I*(u ,v)
2

For display, the log of the power spectrum is often used.

= [ Re I (u ,v) + i Im I (u ,v)][ Re I (u ,v) - i Im I (u ,v)] = [ Re I (u ,v)] + [ Im I (u ,v)] .


2 2

At each location (u,v) it indicates the squared intensity of the frequency component with period l = 1 / u 2 + v 2 and orientation
q = tan -1 (v / u ).
For display in Matlab: PS = fftshift(2*log(abs(fft2(I))+1));
2013-03-08 1999-2013 by Richard Alan Peters II 57

On the Computation of the Power Spectrum


The power spectrum (PS) is defined by PS( I ) = F {I(u, v )} . We take the base-e logarithm of the PS in order to view it. Otherwise its dynamic range could be too large to see everything at once. We add 1 to it first so that the minimum value of the result is 0 rather than infinity, which it would be if there were any zeros in the PS. Recall that log( f 2) = 2log( f ). Multiplying by 2 is not necessary if you are generating a PS for viewing, since you'll probably have to scale it into the range 0-255 anyway. It is much easier to see the structures in a Fourier plane if the origin is in the center. Therefore we usually perform an fftshift on the PS before it is displayed. >> PS = fftshift(log(abs(fft2(I))+1)); >> M = max(PS(:)); >> image(uint8(255*(PS/M)));
2

If the PS is being calculated for later computational use -- for example the autocorrelation of a function is the inverse FT of the PS of the function -- it should be calculated by >> PS = abs(fft2(I)).^2;

2013-03-08

1999-2013 by Richard Alan Peters II

58

The Uncertainty Relation


space frequency

FT

If x y is the extent of the object in space and if u v is its extent in frequency then, x y u v 1 16 2

space

frequency

FT

A small object in space has a large frequency extent and vice-versa.


1999-2013 by Richard Alan Peters II 59

2013-03-08

The Uncertainty Relation


frequency small extent space large extent

IFT

Recall: a symmetric pair of impulses in the frequency domain becomes a sinusoid in the spatial domain. A symmetric pair of lines in the frequency domain becomes a sinusoidal line in the spatial domain.

small extent frequency large extent

large extent space small extent

IFT

small extent 2013-03-08

large extent 1999-2013 by Richard Alan Peters II 60

The Fourier Transform of an Edge

edge

Power Spectrum

Phase Spectrum

2013-03-08

1999-2013 by Richard Alan Peters II

61

The Fourier Transform of a Bar

bar

Power Spectrum

Phase Spectrum

2013-03-08

1999-2013 by Richard Alan Peters II

62

Coordinate Origin of the FFT


Even Odd Even

Center = (floor(R/2)+1, floor(C/2)+1)


Odd

Image Origin

Image Origin

Weight Matrix Origin

Weight Matrix Origin

After FFT shift 2013-03-08

After FFT shift

After IFFT shift

After IFFT shift 63

1999-2013 by Richard Alan Peters II

Matlabs fftshift and ifftshift


I = ifftshift(J):
origin

J = fftshift(I):
origin

from FFT2 or ifftshift

after fftshift

J ( R/2 +1, C/2 +1) I (1,1)

I (1,1) J ( R/2 +1, C/2 +1)

where x = floor(x) = the largest integer smaller than x.


2013-03-08 1999-2013 by Richard Alan Peters II 64

Matlabs fftshift and ifftshift


J = fftshift(I): I (1,1) J ( R/2 +1, C/2 +1)
2 3 1 5 8 6 9 4 7 1 4 7 2 5 8 3 6 9

I = ifftshift(J): J ( R/2 +1, C/2 +1) I (1,1)

5 1 4 7 2 5 8 3 6 9 2 8

6 9

4 7

where x = floor(x) = the largest integer smaller than x.


2013-03-08 1999-2013 by Richard Alan Peters II 65

Points on the Fourier Plane (of a Digital Image)


In the Fourier transform of an RC digital image, positions u and v indicate the number of repetitions of the sinusoid in those directions. Therefore the wavelengths along the column and row axes are -v direction

u = C u wf

and v =

R v

pixels,
of a digital image
-1

and the wavelength in the wavefront direction is


2 2 2 = RC (uR) + (vC ) .

The frequency is the fraction of the sinusoid traversed over one pixel,
u u = C , v = v R

- direction

, and
(0,0)

u direction

wf =

1 2 2 (uR) + (vC ) cycles. RC


row freq. column freq.

The wavefront direction is given by


v wf = tan -1 ( . ) = tan-1 ( vu C R)
u

Note that the wave front direction = only if R=C.


66

2013-03-08

1999-2013 by Richard Alan Peters II

Geometrical Derivation of Wavelength


Since the wavelength of a horizontal* wave is R/v and that of a vertical is C/u, the line segment, h, that connects the two distances is parallel to the wavefront. The wavelength is the altitude of the triangle w.r.t. h (the perpendicular to h that intersects the origin). The area of the triangle, one half of base times height, is independent of the leg that is taken to be the base. Equate the expression with base C/u to that with base h, to find w.r.t R, C, v, u, & h. Then replace h with its expression as a function of R, C, v, & u to get the final expression.
*The equivalue lines are horizontal in a wave with a vertical wave front and vice versa.

2013-03-08

1999-2013 by Richard Alan Peters II

67

Coordinates and Directions in the Fourier Plane


decreasing rows (-r,-c) <0 <0 (+r,-c) increasing cols (+r,+c) increasing rows (-r,+c) (-r,-c) >0 decreasing cols (+r,-c) >0 (+r,+c) (-r,+c)

Since rows increase down and columns to the right, slopes and angles are opposite those of a right-handed coordinate system.
2013-03-08 1999-2013 by Richard Alan Peters II 68

Inverse FFTs of Impulses


horizontal is the wavefront direction.

fftshifted

highest-possible-frequency horizontal sinusoid (C is even)


2013-03-08 1999-2013 by Richard Alan Peters II 69

Inverse FFTs of Impulses


vertical is the wavefront direction.

fftshifted

highest-possible-frequency vertical sinusoid (R is even)


2013-03-08 1999-2013 by Richard Alan Peters II 70

Inverse FFTs of Impulses


a checker-board pattern.

fftshifted

highest-possible-freq horizontal+vertical sinusoid (R & C even)


2013-03-08 1999-2013 by Richard Alan Peters II 71

Inverse FFTs of Impulses


horizontal is the wavefront direction.

fftshifted

lowest-possible-frequency horizontal sinusoid


2013-03-08 1999-2013 by Richard Alan Peters II 72

Inverse FFTs of Impulses


vertical is the wavefront direction.

fftshifted

lowest-possible-frequency vertical sinusoid


2013-03-08 1999-2013 by Richard Alan Peters II 73

Inverse FFTs of Impulses


negative diagonal is the wavefront direction.

fftshifted

lowest-possible-frequency negative diagonal sinusoid


2013-03-08 1999-2013 by Richard Alan Peters II 74

Inverse FFTs of Impulses


positive diagonal is the wavefront direction.

fftshifted

lowest-possible-frequency positive diagonal sinusoid


2013-03-08 1999-2013 by Richard Alan Peters II 75

Frequencies and Wavelengths in the Fourier Plane


512 columns

+v direction

Note this

and this.

frequencies: (u,v) = (4,3); wavelengths: (u, v) = (128,128)


How can that be?
2013-03-08 1999-2013 by Richard Alan Peters II 76

384 rows

+u direction

Frequencies and Wavelengths in the Fourier Plane


512 columns

u = C / u

u = # of complete cycles in the horizontal direction

frequencies: (u,v) = (1,0); wavelength: u= 512


2013-03-08 1999-2013 by Richard Alan Peters II 77

384 rows

Frequencies and Wavelengths in the Fourier Plane


512 columns

frequencies: (u,v) = (0,1); wavelength: v= 384


2013-03-08 1999-2013 by Richard Alan Peters II 78

384 rows

v = # of complete cycles in the vertical direction

v = R / v

Frequencies and Wavelengths in the Fourier Plane


512 columns

u = C / u

u = # of complete cycles in the horizontal direction

frequencies: (u,v) = (2,0); wavelength: u= 256


2013-03-08 1999-2013 by Richard Alan Peters II 79

384 rows

Frequencies and Wavelengths in the Fourier Plane


512 columns

frequencies: (u,v) = (0,2); wavelength: v= 192


2013-03-08 1999-2013 by Richard Alan Peters II 80

384 rows

v = # of complete cycles in the vertical direction

v = R / v

Frequencies and Wavelengths in the Fourier Plane


512 columns

u = C / u

u = # of complete cycles in the horizontal direction

frequencies: (u,v) = (3,0); wavelength: u= 170


2013-03-08 1999-2013 by Richard Alan Peters II 81

384 rows

Frequencies and Wavelengths in the Fourier Plane


512 columns

frequencies: (u,v) = (0,3); wavelength: v= 128


2013-03-08 1999-2013 by Richard Alan Peters II 82

384 rows

v = # of complete cycles in the vertical direction

v = R / v

Frequencies and Wavelengths in the Fourier Plane


512 columns

In the Fourier plane of a square image, the orientation of the line through the point pair = the orientation of the wave front in the image. Not so for a non-square image.

In the F plane the angle is -45 in this image its about -53 (yellow line). Thats because the fraction of R covered by one pixel is 4/3 the fraction of C covered by one pixel.

Also as a result, the wavelength is 102.4.

frequencies: (u,v) = (3,3); wavelengths: (u, v) = (170 ,128)


2013-03-08 1999-2013 by Richard Alan Peters II 83

384 rows

Frequencies and vC Wavelengths in the Fourier Plane = tan ,


-1 wf

In general the slope of the wavefront direction in the image is given by (v/R) / (u/C). Therefore its angle is

uR

512 columns

wf 384 rows
-1

wf

wf

and the wavelength is:

frequencies: (u,v) = (3,3);


2013-03-08

2 2 2 (uR wavelengths: wf (= v) = (170 ,128) + vC . ) ( ) u, RC

1999-2013 by Richard Alan Peters II

84

Frequencies and Wavelengths in the Fourier Plane


512 columns

frequencies: (u,v) = (3,3); wavelengths: (u, v) = (170 ,128)


2013-03-08 1999-2013 by Richard Alan Peters II 85

384 rows

Frequencies and Wavelengths in the Fourier Plane


512 columns

frequencies: (u,v) = (4,3); wavelengths: (u, v) = (128,128)


2013-03-08 1999-2013 by Richard Alan Peters II 86

384 rows

The ratio R/C = in this image. Therefore at frequency (4,3) the wave front angle is
-1 3 512 -1 3 4 = tan -1 ( tan tan 1 45 ,Fourier = = = ) Frequencies and Wavelengths in the wf 4 3 4 384

Plane

512 columns wf 384 rows


87

wf wf

frequencies: (u,v) = (4,3); wavelengths: (u, v) = (128,128) wf


2 2 = 384 512 (3 384) + (4 512)
1 2

and the wavelength is

83.67,

2013-03-08

1999-2013 by Richard Alan Peters II

Power Spectrum of an Image

2013-03-08

1999-2013 by Richard Alan Peters II

88

Relationship between Image and FT


phase power spectrum

power spectrum

phase

2013-03-08

1999-2013 by Richard Alan Peters II

89

Features in the FT and in the Image


Lines in the Power Spectrum are perpendicular to lines in the image.

2013-03-08

1999-2013 by Richard Alan Peters II

90

Fourier Magnitude and Phase

2013-03-08

1999-2013 by Richard Alan Peters II

91

Fourier Magnitude

log

F {I}

2013-03-08

1999-2013 by Richard Alan Peters II

92

Fourier Phase

F { I}

2013-03-08

1999-2013 by Richard Alan Peters II

93

Q: Which contains more visually relevant information; magnitude or phase?

original image

Fourier log magnitude


1999-2013 by Richard Alan Peters II

Fourier phase

2013-03-08

94

Magnitude Only Reconstruction

2013-03-08

1999-2013 by Richard Alan Peters II

95

Phase Only Reconstruction

2013-03-08

1999-2013 by Richard Alan Peters II

96

You might also like