Fourier Transform, Frequency Domain, and Fourier ...

1 downloads 0 Views 28MB Size Report
Complex Plane. Frequency Domain. Fourier Filtering. Fourier Transform, Frequency Domain, and Fourier Filtering1. Lecture 02. See Sections 1.2 and 2.1.3 in.
Fourier Transform

Inverse Fourier Transform

Complex Plane

Frequency Domain

Fourier Filtering

Fourier Transform, Frequency Domain, and Fourier Filtering1 Lecture 02

See Sections 1.2 and 2.1.3 in Reinhard Klette: Concise Computer Vision Springer-Verlag, London, 2014 ccv.wordpress.fos.auckland.ac.nz

1

See last slide for copyright information. 1 / 32

Fourier Transform

Inverse Fourier Transform

Complex Plane

Frequency Domain

Fourier Filtering

Two Images and Their Fourier Spectra

Left: Original images Fibers and Straw in the spatial domain Right: Centered and log-transformed spectra in the frequency domain

2 / 32

Fourier Transform

Inverse Fourier Transform

Complex Plane

Frequency Domain

Fourier Filtering

Agenda

1

Discrete Fourier Transform

2

Inverse Fourier Transform

3

Complex Plane

4

Frequency Domain

5

Fourier Filtering

3 / 32

Fourier Transform

Inverse Fourier Transform

Complex Plane

Frequency Domain

Fourier Filtering

Discrete Fourier Transform and FFT Fourier transform Named after the French mathematician J. B. J. Fourier (1768–1830) Maps real-valued function into a complex-valued function Complex number z = a + ib, with i = real part a imaginary part b



−1, has

Discrete Fourier Transform (DFT) transforms uniformly spaced real signals from the spatial domain into complex numbers in the frequency domain DFTs are performed basically in any device which processes signals (e.g. cell phones, CDs, DVDs and so forth), using the Fast Fourier Transform (FFT) as a time-efficient algorithm 4 / 32

Fourier Transform

Inverse Fourier Transform

Complex Plane

Frequency Domain

Fourier Filtering

DFT A 1-dimensional (1D) DFT maps an infinite sine wave f (x) = into the shown real part; the imaginary part is zero everywhere

1 2

· sin( x2 )

Source: madebyevan.com/dft/ . What is the DFT of f (x) = 12 · cos( x2 ) ? What are input examples with a non-zero imaginary part in their DFT?

The 2-dimensional (2D) DFT maps an Ncols × Nrows scalar image I into a complex-valued Fourier transform I 5 / 32

Fourier Transform

Inverse Fourier Transform

Complex Plane

Frequency Domain

Fourier Filtering

Fourier Filtering – An Outlook The DFT I in the frequency domain provides insights into the image I Fourier filtering: Change data in the frequency domain (by Fourier filter operations) and map them back (by an inverse 2D DFT) into a modified image Examples: Contrast enhancement, noise removal, or smoothing of images 1D Fourier filtering: commonly used in signal theory (e.g., for audio processing in mobile phones) 2D Fourier filtering of images: follows the same principles, just in 2D instead of in 1D Note: In the context of the Fourier transform we use image coordinates from 0 to Ncols − 1 for x, and from 0 to Nrows − 1 for y 6 / 32

Fourier Transform

Inverse Fourier Transform

Complex Plane

Frequency Domain

Fourier Filtering

2D Discrete Fourier Transform (2D DFT)

I(u, v ) =

Ncols

   NX cols −1 Nrows X−1 1 xu yv I (x, y ) · exp −i2π + · Nrows Ncols Nrows x=0

y =0

for frequencies u = 0, 1, . . . , Ncols − 1 and v = 0, 1, . . . , Nrows − 1 √ i = −1 is the imaginary unit of complex numbers Eulerian formula, for real α and e = 2.71828 . . . = exp(1): exp(iα) = e iα = cos(α) + i · sin(α) If α outside of interval [0, 2π) then taken modulo 2π Thus: Fourier transform is a weighted sum of sine and cosine functions in the complex plane 7 / 32

Fourier Transform

Inverse Fourier Transform

Complex Plane

Frequency Domain

Fourier Filtering

Agenda

1

Discrete Fourier Transform

2

Inverse Fourier Transform

3

Complex Plane

4

Frequency Domain

5

Fourier Filtering

8 / 32

Fourier Transform

Inverse Fourier Transform

Complex Plane

Frequency Domain

Fourier Filtering

Inverse Discrete Fourier Transform Maps Fourier transform I back into the spatial domain: I (x, y ) =

NX cols −1 Nrows X−1 u=0

v =0

 I(u, v ) exp i2π



yv xu + Ncols Nrows



Powers exp(iα) here reversed compared to the forward transform Scaling factor 1/Ncols · Nrows in the 2D DFT and the scaling factor 1 in the inverse transform; we also could√have a split of 1/Ncols · Nrows into two scaling factors, say, for example, 1/ Ncols · Nrows in both transforms Representation of Image by Basis Functions Image I is represented above as a weighted sum of basis functions exp(iα) = cos(α) + i sin(α) being 2D combinations of cosine and sine functions in the complex plane; Fourier coefficients I(u, v ) are the weights 9 / 32

Fourier Transform

Inverse Fourier Transform

Complex Plane

Frequency Domain

Fourier Filtering

Illustration of Basis Functions Sine functions for imaginary part; for real part a we have cosine functions

2D waves defined by sin(u + nv ), for n = 1, . . . , 5 10 / 32

Fourier Transform

Inverse Fourier Transform

Complex Plane

Frequency Domain

Fourier Filtering

Agenda

1

Discrete Fourier Transform

2

Inverse Fourier Transform

3

Complex Plane

4

Frequency Domain

5

Fourier Filtering

11 / 32

Fourier Transform

Inverse Fourier Transform

Complex Plane

Frequency Domain

Fourier Filtering

Calculus of Complex Numbers z1 = a1 + i · b1 and z2 = a2 + i · b2 z1 + z2 = (a1 + a2 ) + i · (b1 + b2 ) z1 · z2 = (a1 a2 − b1 b2 ) + i · (a1 b2 + a2 b1 ) Norm of z = a + i · b:

||z||2 =



a2 + b 2

Example: ||W ||2 = 1 for root of unity W = exp( i2π N ), N ≥ 1 Why? – See the Eulerian formula z? = a − i · b

is the conjugate of

If z 6= 0 then

z =a+i ·b

? z −1 = ||z||−2 2 ·z 12 / 32

Fourier Transform

Inverse Fourier Transform

Complex Plane

Frequency Domain

Fourier Filtering

Unit Circle (r = 1) in the Complex Plane Imaginary part

W

8

6 W 7 +i W

W5 W4

W9

W3

W 10

W2

W 11

a+ib

b

W1

r α

W 12 -1

W0 +1

a

Real part

W 23

W 13 W 14

W 22

W 15

W 21 W

16

W W 17

-i W 18

20

W 19 13 / 32

Fourier Transform

Inverse Fourier Transform

Complex Plane

Frequency Domain

Fourier Filtering

Complex Plane

Powers of W = exp( i2π N ) are all located on the unit circle (N ≥ 1) Previous page illustrates N = 24 Figure shows complex number z = a + ib having (r , α) as polar coordinates: r is the norm (the amplitude) α is the phase Complex Plane Plane of complex numbers a + i · b with points (a, b) or vectors [a, b]>

14 / 32

Fourier Transform

Inverse Fourier Transform

Complex Plane

Frequency Domain

Fourier Filtering

Agenda

1

Discrete Fourier Transform

2

Inverse Fourier Transform

3

Complex Plane

4

Frequency Domain

5

Fourier Filtering

15 / 32

Fourier Transform

Inverse Fourier Transform

Complex Plane

Frequency Domain

Fourier Filtering

Image Data in Matrix I in the uv Frequency Domain

Values for low frequencies u or v (i.e. close to 0) represent long wavelengths of sine or cosine components Values for large frequencies u or v (i.e. away from zero) represent short wavelengths Low frequencies (long wavelengths) represent homogeneous additive contributions to the input image I High frequencies (short wavelengths) represent local discontinuities in I such as edges or intensity outliers

16 / 32

Fourier Transform

Inverse Fourier Transform

Complex Plane

Frequency Domain

Fourier Filtering

Where is ”Low” and where is ”High”? Origin in image I and Fourier transform I is in the upper left corner Imagine that values in matrix I are repeated periodically in the plane, with periods Ncols and Nrows , thus tessellating the plane

17 / 32

Fourier Transform

Inverse Fourier Transform

Complex Plane

Frequency Domain

Fourier Filtering

Origin at the Center

For having the origin (i.e. the low frequencies) at the center of the Fourier transform 1

we can perform a permutation of the four quadrants of the matrix or

2

we multiply all values I (x, y ) first by (−1)x+y before performing the 2D DFT

18 / 32

Fourier Transform

Inverse Fourier Transform

Complex Plane

Frequency Domain

Fourier Filtering

Two Properties of the DFT

1

2D DFT I combines two Ncols × Nrows arrays representing the real or the imaginary part; due to the symmetry property I(Ncols − u, Nrows − v ) = I(−u, −v ) = I(u, v )∗ half of the data in both arrays of I is redundant

2

Mean of I : I(0, 0) =

Ncols

NX cols −1 Nrows X−1 1 I (x, y ) · Nrows x=0

y =0

Imaginary part of I(0, 0) is always equal to zero

19 / 32

Fourier Transform

Inverse Fourier Transform

Complex Plane

Frequency Domain

Fourier Filtering

Spectrum and Phase Spectrum ||I|| ||I||(u, v ) = ||I(u, v )||2

for all Ncols · Nrows frequencies (u, v ) √ Recall: amplitude ||z||2 = r = a2 + b 2

Visualisation of the spectrum ||I|| in form of a gray-level image: It would be just black with a bright dot at the origin; for better visibility, use log-transform log10 (1 + ||I(u, v )||2 ) Phase α = atan2(b, a) for z = a + ib Visualization of phase components of I is not so common; actually not corresponding to the importance of phase for representing information present in an image

20 / 32

Fourier Transform

Inverse Fourier Transform

Complex Plane

Frequency Domain

Fourier Filtering

Invariance w.r.t. Histogram Equalization

Jpg-image Donkey, histogram equalization, and corresponding spectra 21 / 32

Fourier Transform

Inverse Fourier Transform

Complex Plane

Frequency Domain

Fourier Filtering

Invariance w.r.t. Value Inversion

Jpg-image Donkey, inverted gray-levels, corresponding spectra 22 / 32

Fourier Transform

Inverse Fourier Transform

Complex Plane

Frequency Domain

Fourier Filtering

Simple Geometric Shapes

Directional patterns in I , e.g. lines into direction β or β + π, create value distributions in I in the orthogonal direction (i.e., in direction β + π/2) 23 / 32

Fourier Transform

Inverse Fourier Transform

Complex Plane

Frequency Domain

Fourier Filtering

Wave Pattern and a Filter

TL: Ideal wave pattern generates non-negative values only at v = 0 BL: Diagonal wave pattern is influenced by the “finite-array effect” TR: Overlaid diagonal wave pattern BR: Simple mask for blocking values in the frequency domain; inverse DFT produces a filtered image 24 / 32

Fourier Transform

Inverse Fourier Transform

Complex Plane

Frequency Domain

Fourier Filtering

Agenda

1

Discrete Fourier Transform

2

Inverse Fourier Transform

3

Complex Plane

4

Frequency Domain

5

Fourier Filtering

25 / 32

Fourier Transform

Inverse Fourier Transform

Complex Plane

Frequency Domain

Fourier Filtering

Linear Transform of Image I 1

Modify image data in the spatial domain by a linear convolution J (x, y ) = (I ∗ G ) (x, y ) =

NX cols −1 Nrows X−1 i=0

I (i, j) · G (x − i, y − j)

j=0

G is the filter kernel and J is the filtered image Example: G (0, 0) = 1 and G (x, y ) = 0 otherwise, then ... ? 2

Modify 2D DFT I of I by multiplying values in I, position by position, with corresponding complex numbers in G [i.e., I(u, v ) · G(u, v )]; the resulting complex array is transformed by the inverse 2D DFT into the modified image J

Both options lead to identical results assuming that G is the 2D DFT of G (see convolution theorem of the Fourier transform in the CCV book) 26 / 32

Fourier Transform

Inverse Fourier Transform

Complex Plane

Frequency Domain

Fourier Filtering

Steps of Fourier Filtering In the convolution case we miss the opportunity to design frequency-dependent filter functions in the frequency domain; there is also the FFT for time-efficiency of the second way Given: Image I and complex-valued filter function G; for applying a standard FFT program, map image I at first into a larger 2n × 2n array 1

2

3

Transform image I into the frequency domain, into the complex-valued I by using the FFT program Multiply complex-valued I, element by element, with the complex-valued filter function G Transform the result back into the spatial domain by using the FFT program for the inverse DFT

Filter function G can be obtained as Fourier transform of a filter kernel G in the spatial domain, but ii is common practice to design G in the frequency domain 27 / 32

Fourier Transform

Inverse Fourier Transform

Complex Plane

Frequency Domain

Fourier Filtering

Examples of Filter Functions in the Frequency Domain a

a

1

1

u a

u a

1

1

u

u

1D profiles of rotation-symmetric filter functions Top: A linear high-pass filter and an ideal low-pass filter Bottom: An exponential high-emphasis filter and a linear band-pass filter Attributes “linear”, “exponential”, or “ideal” of a filter function specify the way how the transition is defined from large amplitudes of the filter to low amplitudes 28 / 32

Fourier Transform

Inverse Fourier Transform

Complex Plane

Frequency Domain

Fourier Filtering

Design of Filter Functions: Examples

High-pass filter: e.g. for edge detection, or for visualizing details and for suppressing low frequencies Low-pass filter: e.g. for a reduction of outliers and of contrast, i.e. a smoothing effect High-emphasis filter: e.g. for enhancing contrast Band-pass filter: for allowing only a certain range of frequencies “to pass” A filter which eliminates or enhances selected frequencies (under proper consideration of the symmetry constraint)

29 / 32

Fourier Transform

Inverse Fourier Transform

Complex Plane

Frequency Domain

Fourier Filtering

Example for Fourier Filtering

30 / 32

Fourier Transform

Inverse Fourier Transform

Complex Plane

Frequency Domain

Fourier Filtering

Example for Fourier Filtering: Continued

Upper row, left: Intensity channel of image Emma Upper row, right: Its spectrum, centered and with log-transform Lower row, left: An ideal low-pass filtered Emma, showing a typical smoothing effect Lower row, right: An exponential-band-pass filtered Emma, already showing more higher frequencies than lower frequencies

31 / 32

Fourier Transform

Inverse Fourier Transform

Complex Plane

Frequency Domain

Fourier Filtering

Copyright Information

This slide show was prepared by Reinhard Klette with kind permission from Springer Science+Business Media B.V. The slide show can be used freely for presentations. However, all the material is copyrighted. R. Klette. Concise Computer Vision. c

Springer-Verlag, London, 2014. In case of citation: just cite the book, that’s fine.

32 / 32