11
3/20/2012 1 Filtering in the Frequency Domain (Application) Digital Image Processing University of Ioannina - Department of Computer Science Christophoros Nikou [email protected] 2 Periodicity of the DFT C. Nikou – Digital Image Processing (E12) • The range of frequencies of the signal is between [-M/2, M/2]. • The DFT covers two back-to-back half periods of the signal as it covers [0, M-1]. • For display and computation purposes it is convenient to shift the DFT and have a complete period in [0, M-1]. 3 Periodicity of the DFT (cont...) From DFT properties: 0 2 ( / ) 0 [] ( ) j NnM f ne Fk N π Letting N 0 =M/2: And F(0) is now located at M/2. [ ]( 1) ( / 2) n fn Fk M C. Nikou – Digital Image Processing (E12) 4 Periodicity of the DFT (cont...) In two dimensions: and F(0,0) is now located at (M/2, N/2). [ , ]( 1) ( / 2, / 2) m n fmn Fk M l N + C. Nikou – Digital Image Processing (E12) 5 DFT & Images The DFT of a two dimensional image can be visualised by showing the spectrum of the image component frequencies Image Processing (2002) C. Nikou – Digital Image Processing (E12) Images taken from Gonzalez & Woods, Digital DFT 6 DFT & Images Image Processing (2002) C. Nikou – Digital Image Processing (E12) Images taken from Gonzalez & Woods, Digital

3/20/2012 2 Periodicity of the DFTcnikou/Courses/Digital_Image_Processing/... · 2012. 3. 20. · 3/20/2012 4 19 The DFT and Image Processing To filter an image in the frequency domain:

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 3/20/2012 2 Periodicity of the DFTcnikou/Courses/Digital_Image_Processing/... · 2012. 3. 20. · 3/20/2012 4 19 The DFT and Image Processing To filter an image in the frequency domain:

3/20/2012

1

Filtering in the Frequency Domain(Application)

Digital Image Processing

University of Ioannina - Department of Computer Science

( pp )

Christophoros [email protected]

2 Periodicity of the DFT

C. Nikou – Digital Image Processing (E12)

• The range of frequencies of the signal is between [-M/2, M/2].• The DFT covers two back-to-back half periods of the signal

as it covers [0, M-1].• For display and computation purposes it is convenient to shift

the DFT and have a complete period in [0, M-1].

3 Periodicity of the DFT (cont...)

• From DFT properties: 02 ( / )0[ ] ( )j N n Mf n e F k Nπ ⇔ −

Letting N0=M/2:And F(0) is now located at M/2.

[ ]( 1) ( / 2)nf n F k M− ⇔ −

C. Nikou – Digital Image Processing (E12)

4 Periodicity of the DFT (cont...)

• In two dimensions:

and F(0,0) is now located at (M/2, N/2).

[ , ]( 1) ( / 2, / 2)m nf m n F k M l N+− ⇔ − −

C. Nikou – Digital Image Processing (E12)

5 DFT & Images

The DFT of a two dimensional image can be visualised by showing the spectrum of the image component frequencies

Imag

e P

roce

ssin

g (2

002)

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

DFT

6 DFT & Images

Imag

e P

roce

ssin

g (2

002)

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

Page 2: 3/20/2012 2 Periodicity of the DFTcnikou/Courses/Digital_Image_Processing/... · 2012. 3. 20. · 3/20/2012 4 19 The DFT and Image Processing To filter an image in the frequency domain:

3/20/2012

2

7 DFT & Images

Imag

e P

roce

ssin

g (2

002)

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

8 DFT & Images (cont…)

Imag

e P

roce

ssin

g (2

002)

DFT

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l DFT

Scanning electron microscope image of an integrated circuit

magnified ~2500 times

Fourier spectrum of the image

9 DFT & Images (cont…)

Imag

e P

roce

ssin

g (2

002)

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

10 DFT & Images (cont…)

Imag

e P

roce

ssin

g (2

002)

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

11 DFT & Images (cont…)

Imag

e P

roce

ssin

g (2

002)

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

12 DFT & Images (cont…)

Imag

e P

roce

ssin

g (2

002)

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

Page 3: 3/20/2012 2 Periodicity of the DFTcnikou/Courses/Digital_Image_Processing/... · 2012. 3. 20. · 3/20/2012 4 19 The DFT and Image Processing To filter an image in the frequency domain:

3/20/2012

3

13 DFT & Images (cont…)

Imag

e P

roce

ssin

g (2

002)

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

Although the images differ by a simple geometrictransformation no intuitive information may beextracted from their phases regarding their relation.

14 DFT & Images (cont…)

Imag

e P

roce

ssin

g (2

002)

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

15 DFT synopsis

Imag

e P

roce

ssin

g (2

002)

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

16 DFT synopsis (cont.)

Imag

e P

roce

ssin

g (2

002)

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

17 DFT synopsis (cont.)

Imag

e P

roce

ssin

g (2

002)

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

18 DFT synopsis (cont.)

Imag

e P

roce

ssin

g (2

002)

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

Page 4: 3/20/2012 2 Periodicity of the DFTcnikou/Courses/Digital_Image_Processing/... · 2012. 3. 20. · 3/20/2012 4 19 The DFT and Image Processing To filter an image in the frequency domain:

3/20/2012

4

19 The DFT and Image Processing

To filter an image in the frequency domain:1. Compute F(u,v) the DFT of the image2. Multiply F(u,v) by a filter function H(u,v)3. Compute the inverse DFT of the result

Imag

e P

roce

ssin

g (2

002)

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

20 Some Basic Frequency Domain Filters

Imag

e P

roce

ssin

g (2

002)

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

The DFT is centered after multiplication of the image by (-1)m+n

21Some Basic Frequency Domain Filters

(cont.)

Imag

e P

roce

ssin

g (2

002) Low Pass Filter

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

High Pass Filter

22 The importance of zero padding

Imag

e P

roce

ssin

g (2

002)

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

• The image and the DFT are considered to be periodic.• The vertical edges of the middle image are not blurred

if no padding is applied. Why?

23The importance of zero padding

(cont.)

Imag

e P

roce

ssin

g (2

002)

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

24 Spatial zero-padding and filters

Imag

e P

roce

ssin

g (2

002) •Padding is performed in the spatial domain.

•The filter is defined in the frequency domain.•A naïve approach:

Compute the inverse DFT of the filter

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l −Compute the inverse DFT of the filter.−Pad the filter in the spatial domain to have the same size as the image.−Compute its DFT to return to the frequency domain.

Page 5: 3/20/2012 2 Periodicity of the DFTcnikou/Courses/Digital_Image_Processing/... · 2012. 3. 20. · 3/20/2012 4 19 The DFT and Image Processing To filter an image in the frequency domain:

3/20/2012

5

25Spatial zero-padding and filters

(cont.)

Imag

e P

roce

ssin

g (2

002) • The filter and its inverse DFT of length 256 (continuous line)

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

26Spatial zero-padding and filters

(cont.)

Imag

e P

roce

ssin

g (2

002) • Zero-padded filter and its DFT

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

• Spatial truncation of the filter results in ringing effects.

27Spatial zero-padding and filters

(cont.)

Imag

e P

roce

ssin

g (2

002) • We cannot work with an infinite number of filter

components and simultaneously perform zero-padding to avoid aliasing.

• A decision on which limitation to accept is i d

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l required.• One solution to zero-pad the image and then use a filter of the same size with no zero-padding−Small errors due to aliasing but it is generally

preferable than ringing.• Another solution is to choose filters attenuating gradually instead of ideal filters.

28 Steps of filtering in the DFT domain

Imag

e P

roce

ssin

g (2

002)

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

29Steps of filtering in the DFT domain

(cont.)

Imag

e P

roce

ssin

g (2

002) • What if the filter is known in the spatial domain?

-1 0 1

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

-2 0 2

-1 0 1

• Apply a 3x3 Sobel filter to the 600x600 image in the frequency domain.

30Steps of filtering in the DFT domain

(cont.)

Imag

e P

roce

ssin

g (2

002) 1. Pad the image and the filter to 602x602.

2. Place the filter to the center of the 602x602 padded array.

3 Multiply the filter by (-1)m+n to place the

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l 3. Multiply the filter by (-1) to place the center of the filter to (0,0) of the array.

4. Compute the DFT of the filter.5. Multiply the DFT by (-1)m+n to place it to

the center of the array.6. Perform filtering in the frequency domain.

Page 6: 3/20/2012 2 Periodicity of the DFTcnikou/Courses/Digital_Image_Processing/... · 2012. 3. 20. · 3/20/2012 4 19 The DFT and Image Processing To filter an image in the frequency domain:

3/20/2012

6

31Steps of filtering in the DFT domain

(cont.)

Imag

e P

roce

ssin

g (2

002) • Alternatively, pad to 602x602, repeat the

filter periodically and compute the DFT.0 20 1

-2-1

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

0 1 -1

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

32The importance of zero padding

(cont...)

Imag

e P

roce

ssin

g (2

002)

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

33 Smoothing Frequency Domain Filters

• Smoothing is achieved in the frequency domain by dropping out the high frequency components

• The basic model for filtering is:

C. Nikou – Digital Image Processing (E12)

G(u,v) = H(u,v)F(u,v)• where F(u,v) is the Fourier transform of the

image being filtered and H(u,v) is the filter transform function

• Low pass filters – only pass the low frequencies, drop the high ones.

34 Ideal Low Pass Filter

Simply cut off all high frequency components that are a specified distance D0 from the origin of the transform.

Imag

e P

roce

ssin

g (2

002)

C. Nikou – Digital Image Processing (E12)

Changing the distance changes the behaviour of the filter.Im

ages

take

n fro

m G

onza

lez

& W

oods

, Dig

ital

35 Ideal Low Pass Filter (cont…)

The transfer function for the ideal low pass filter can be given as:

⎩⎨⎧ ≤

= 0

)(if0),( if 1

),(DDDvuD

vuH

C. Nikou – Digital Image Processing (E12)

where D(u,v) is given as:

⎩⎨ > 0),( if 0

),(DvuD

2/122 ])2/()2/[(),( NvMuvuD −+−=

36 Ideal Low Pass Filter (cont…)

Imag

e P

roce

ssin

g (2

002)

C. Nikou – Digital Image Processing (E12)

An image, its Fourier spectrum and a series of ideal low pass filters of radius 5, 15, 30, 80 and 230 superimposed on top of it.

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

Page 7: 3/20/2012 2 Periodicity of the DFTcnikou/Courses/Digital_Image_Processing/... · 2012. 3. 20. · 3/20/2012 4 19 The DFT and Image Processing To filter an image in the frequency domain:

3/20/2012

7

37 Ideal Lowpass Filters (cont...)

• ILPF in the spatial domain is a sincfunction that has to be truncated and produces ringing effects.

• The main lobe is responsible for blurring Imag

e P

roce

ssin

g (2

002)

C. Nikou – Digital Image Processing (E12)

and the side lobes are responsible for ringing.

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

38 Ideal Low Pass Filter (cont…)

Imag

e P

roce

ssin

g (2

002)

Originalimage

ILPF of radius 5

ILPF of radi s 30ILPF of radius 15

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l ILPF of radius 30

ILPF of radius 230ILPF of radius 80

ILPF of radius 15

39 Butterworth Lowpass Filters

• The transfer function of a Butterworth lowpass filter of order n with cutoff frequency at distance D0 from the origin is defined as:

Imag

e P

roce

ssin

g (2

002)

1

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

nDvuDvuH 2

0 ]/),([11),(

+=

40 Butterworth Lowpass Filters (cont...)

Imag

e P

roce

ssin

g (2

002)

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

41 Butterworth Lowpass Filter (cont…)

Imag

e P

roce

ssin

g (2

002)

Original image BLPF n=2, D0=5

BLPF n=2, D0=30BLPF n=2, D0=15

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l n , 0 30

BLPF n=2, D0=230BLPF n=2, D0=80

Less ringing than ILPFdue to smoothertransition

42 Gaussian Lowpass Filters

• The transfer function of a Gaussian lowpass filter is defined as:

Imag

e P

roce

ssin

g (2

002)

20

2 2/),(),( DvuDevuH −=

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

Page 8: 3/20/2012 2 Periodicity of the DFTcnikou/Courses/Digital_Image_Processing/... · 2012. 3. 20. · 3/20/2012 4 19 The DFT and Image Processing To filter an image in the frequency domain:

3/20/2012

8

43 Gaussian Lowpass Filters (cont…)

Imag

e P

roce

ssin

g (2

002) Original image Gaussian D0=5

Gaussian D0=30Gaussian D =15

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l 0

Gaussian D0=230Gaussian D0=85

Gaussian D0=15

Less ringing thanBLPF but also lesssmoothing

44 Lowpass Filters Compared

ILPF D0=15 BLPF n=2, D0=15

Imag

e P

roce

ssin

g (2

002)

C. Nikou – Digital Image Processing (E12)

Gaussian D0=15

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

45 Lowpass Filtering Examples

A low pass Gaussian filter is used to connect broken text

Imag

e P

roce

ssin

g (2

002)

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

46 Lowpass Filtering Examples

Imag

e P

roce

ssin

g (2

002)

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

47 Lowpass Filtering Examples (cont…)

• Different lowpass Gaussian filters used to remove blemishes in a photograph.

Imag

e P

roce

ssin

g (2

002)

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

48 Lowpass Filtering Examples (cont…)

Imag

e P

roce

ssin

g (2

002)

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

Page 9: 3/20/2012 2 Periodicity of the DFTcnikou/Courses/Digital_Image_Processing/... · 2012. 3. 20. · 3/20/2012 4 19 The DFT and Image Processing To filter an image in the frequency domain:

3/20/2012

9

49 Sharpening in the Frequency Domain

• Edges and fine detail in images are associated with high frequency components

• High pass filters – only pass the high

C. Nikou – Digital Image Processing (E12)

frequencies, drop the low ones• High pass frequencies are precisely the

reverse of low pass filters, so:Hhp(u, v) = 1 – Hlp(u, v)

50 Ideal High Pass Filters

• The ideal high pass filter is given by:

⎩⎨⎧

>≤

=0

0

),( if 1),( if 0

),(DvuDDvuD

vuH

Imag

e P

roce

ssin

g (2

002)

C. Nikou – Digital Image Processing (E12)

• D0 is the cut off distance as before.

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

51 Ideal High Pass Filters (cont…)

Imag

e P

roce

ssin

g (2

002)

C. Nikou – Digital Image Processing (E12)

IHPF D0 = 15 IHPF D0 = 30 IHPF D0 = 80

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

52 Butterworth High Pass Filters

• The Butterworth high pass filter is given as:

nvuDDvuH 2

0 )],(/[11),(

+=

Imag

e P

roce

ssin

g (2

002)

C. Nikou – Digital Image Processing (E12)

• n is the order and D0 is the cut off distance as before.

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

53 Butterworth High Pass Filters (cont…)

Imag

e P

roce

ssin

g (2

002)

C. Nikou – Digital Image Processing (E12)

BHPF n=2, D0 =15

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

BHPF n=2, D0 =30 BHPF n=2, D0 =80

54 Gaussian High Pass Filters

• The Gaussian high pass filter is given as:

D i th t ff di t b f

20

2 2/),(1),( DvuDevuH −−=

Imag

e P

roce

ssin

g (2

002)

C. Nikou – Digital Image Processing (E12)

• D0 is the cut off distance as before.

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

Page 10: 3/20/2012 2 Periodicity of the DFTcnikou/Courses/Digital_Image_Processing/... · 2012. 3. 20. · 3/20/2012 4 19 The DFT and Image Processing To filter an image in the frequency domain:

3/20/2012

10

55 Gaussian High Pass Filters (cont…)

Imag

e P

roce

ssin

g (2

002)

C. Nikou – Digital Image Processing (E12)

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

Gaussian HPF n=2, D0 =15

Gaussian HPF n=2, D0 =30

Gaussian HPF n=2, D0 =80

56 Highpass Filter Comparison

Imag

e P

roce

ssin

g (2

002)

C. Nikou – Digital Image Processing (E12)

IHPF D0 = 15

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

Gaussian HPF n=2, D0 =15

BHPF n=2, D0 =15

57 Highpass Filtering Example

Orig

inal

imag

e

Highpass filtering reIm

age

Pro

cess

ing

(200

2)

C. Nikou – Digital Image Processing (E12)

esult

Hig

h fre

quen

cy

emph

asis

resu

lt After histogram

equalisation

Imag

es ta

ken

from

Gon

zale

z &

Woo

ds, D

igita

l

58 Laplacian In The Frequency Domain

Lapl

acia

n in

the

requ

ency

dom

ain

(not

cen

tere

d)

2-D im

age of Laplacin the frequency

domain

(not centered)

Imag

e P

roce

ssin

g (2

002)

C. Nikou – Digital Image Processing (E12)

fr

cian

Inve

rse

DFT

of

Lapl

acia

n in

the

frequ

ency

dom

ain

Zoomed section of the image on

the left compared to spatial filterIm

ages

take

n fro

m G

onza

lez

& W

oods

, Dig

ital

59 Frequency Domain Laplacian Example

Original image

Laplacian filtered image

C. Nikou – Digital Image Processing (E12)

Laplacian image scaled

Enhanced image

60 Band-pass and Band-stop Filters

C. Nikou – Digital Image Processing (E12)

Page 11: 3/20/2012 2 Periodicity of the DFTcnikou/Courses/Digital_Image_Processing/... · 2012. 3. 20. · 3/20/2012 4 19 The DFT and Image Processing To filter an image in the frequency domain:

3/20/2012

11

61 Band-Pass Filters (cont...)

C. Nikou – Digital Image Processing (E12)

62 Band-Pass Filters (cont...)

C. Nikou – Digital Image Processing (E12)

63 Fast Fourier Transform

•The reason that Fourier based techniques have become so popular is the development of the Fast Fourier Transform (FFT) algorithm.

C. Nikou – Digital Image Processing (E12)

• It allows the Fourier transform to be carried out in a reasonable amount of time.

•Reduces the complexity from O(N4) to O(N2logN2).

64Frequency Domain Filtering & Spatial

Domain Filtering• Similar jobs can be done in the spatial and

frequency domains.• Filtering in the spatial domain can be

easier to understand.

C. Nikou – Digital Image Processing (E12)

• Filtering in the frequency domain can be much faster – especially for large images.