You are on page 1of 46

EECE\CS 253 Image Processing

Lecture Notes: Frequency Filtering Lecture Notes

Richard Alan Peters II


Department of Electrical Engineering and Computer Science
Fall Semester 2007

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.

Convolution Property of the Fourier Transform


Let functions f ( r, c ) and g ( r, c ) have Fourier Transforms F (u, v ) and G (u, v ). Then,
* = convolution = multiplication

F { f g } = F G.
Moreover,

F { f g } = F G.

The Fourier Transform of a The Fourier Transform of a convolution equals the convolution equals the product of the Fourier product of the Fourier Transforms. Similarly, the Transforms. Similarly, the Fourier Transform of a Fourier Transform of a convolution is the product of convolution is the product of the Fourier Transforms the Fourier Transforms

27 April 2008

1999-2007 by Richard Alan Peters II

Convolution via Fourier Transform

Image & Mask

Transforms

Pixel-wise Product

Inverse Transform

27 April 2008

1999-2007 by Richard Alan Peters II

How to Convolve via FT in Matlab


1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. Read the image from a file into a variable, say I. The mask is usually 1-band Read in or create the convolution mask, h. The mask is usually 1-band Compute the sum of the mask: s = sum(sum(h)); If s == 0, set s = 1; For color images you may For color images you may need to do each step for Create: H = zeros(size(I)); need to do each step for each band separately. each band separately. Copy h into the middle of H. Shift H into position: H = ifftshift(H); Take the 2D FT of I and H: FI=fft2(I); FH=fft2(H); Pointwise multiply the FTs: FJ=FI.*FH; Compute the inverse FT: J = real(ifft2(FJ)); Normalize the result: J = J/s;
1999-2007 by Richard Alan Peters II

27 April 2008

Coordinate Origin of the FFT


Even Odd Even

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


Odd

Image Origin

Image Origin

Weight Matrix Origin

Weight Matrix Origin

After FFT shift

After FFT shift

After IFFT shift

After IFFT shift

27 April 2008

1999-2007 by Richard Alan Peters II

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.


27 April 2008
1999-2007 by Richard Alan Peters II

Blurring: Averaging / Lowpass Filtering


Blurring results from:
Pixel averaging in the spatial domain:

Each pixel in the output is a weighted average of its neighbors. Is a convolution whose weight matrix sums to 1. High frequencies are diminished or eliminated Individual frequency components are multiplied by a nonincreasing function of such as 1/ = 1/(u2+v2). The values of the output image are all non-negative. The values of the output image are all non-negative.

Lowpass filtering in the frequency domain:


27 April 2008

1999-2007 by Richard Alan Peters II

Sharpening: Differencing / Highpass Filtering


Sharpening results from adding to the image, a copy of itself that has been:
Pixel-differenced in the spatial domain:

Each pixel in the output is a difference between itself and a weighted average of its neighbors. Is a convolution whose weight matrix sums to 0. High frequencies are enhanced or amplified. Individual frequency components are multiplied by an increasing function of such as = (u2+v2), where is a constant. The values of the output image positive & negative. The values of the output image positive & negative.

Highpass filtered in the frequency domain:


27 April 2008

1999-2007 by Richard Alan Peters II

Recall: Recall:

Convolution Property of the Fourier Transform


Let functions f ( r, c ) and g ( r, c ) have Fourier Transforms F (u, v ) and G (u, v ). Then,
* = convolution = multiplication

F { f g } = F G.
Moreover,

F { f g } = F G.
Thus we can compute f g by f g = F -1{F G}.
27 April 2008

The Fourier Transform of a The Fourier Transform of a convolution equals the convolution equals the product of the Fourier product of the Fourier Transforms. Similarly, the Transforms. Similarly, the Fourier Transform of a Fourier Transform of a convolution is the product of convolution is the product of the Fourier Transforms the Fourier Transforms
9

1999-2007 by Richard Alan Peters II

Ideal Lowpass Filter


Multiply by this, or convolve by this

Image size: 512x512 Image size: 512x512 FD filter radius: 16 FD filter radius: 16

Fourier Domain Rep. Fourier Domain Rep.

Spatial Representation Spatial Representation

Central Profile Central Profile

27 April 2008

1999-2007 by Richard Alan Peters II

10

Ideal Lowpass Filter


Multiply by this, or convolve by this

Image size: 512x512 Image size: 512x512 FD filter radius: 8 FD filter radius: 8

Fourier Domain Rep. Fourier Domain Rep.

Spatial Representation Spatial Representation

Central Profile Central Profile

27 April 2008

1999-2007 by Richard Alan Peters II

11

Consider the Consider the image below: image below:

Power Spectrum and Phase of an Image

Original Image Original Image

Power Spectrum Power Spectrum

Phase Phase

27 April 2008

1999-2007 by Richard Alan Peters II

12

Ideal Lowpass Filter

Image size: 512x512 Image size: 512x512 FD filter radius: 16 FD filter radius: 16

Original Image Original Image

Power Spectrum Power Spectrum

Ideal LPF in FD Ideal LPF in FD

27 April 2008

1999-2007 by Richard Alan Peters II

13

Ideal Lowpass Filter

Image size: 512x512 Image size: 512x512 FD filter radius: 16 FD filter radius: 16

Filtered Image Filtered Image

Filtered Power Spectrum Filtered Power Spectrum

Original Image Original Image

27 April 2008

1999-2007 by Richard Alan Peters II

14

Ideal Highpass Filter


Multiply by Multiply by this, or this, or convolve convolve by this by this

Image size: 512x512 Image size: 512x512 FD notch radius: 16 FD notch radius: 16

Fourier Domain Rep. Fourier Domain Rep.

Spatial Representation Spatial Representation

Central Profile Central Profile

27 April 2008

1999-2007 by Richard Alan Peters II

15

Ideal Highpass Filter

Image size: 512x512 Image size: 512x512 FD notch radius: 16 FD notch radius: 16

Original Image Original Image

Power Spectrum Power Spectrum

Ideal HPF in FD Ideal HPF in FD

27 April 2008

1999-2007 by Richard Alan Peters II

16

**signedimage; 0 signed image; 0

mapped to 128 mapped to 128

Ideal Highpass Filter

Image size: 512x512 Image size: 512x512 FD notch radius: 16 FD notch radius: 16

Filtered Image* Filtered Image*

Filtered Power Spectrum Filtered Power Spectrum

Original Image Original Image

27 April 2008

1999-2007 by Richard Alan Peters II

17

**signedimage; 0 signed image; 0

mapped to 128 mapped to 128

Ideal Highpass Filter

Image size: 512x512 Image size: 512x512 FD notch radius: 16 FD notch radius: 16

Positive Pixels Positive Pixels

Filtered Image* Filtered Image*

Negative Pixels Negative Pixels

27 April 2008

1999-2007 by Richard Alan Peters II

18

The Uncertainty Relation


space frequency

FT FT

If x y is the extent of the object in space and if u v is its extent in frequency then, 1 x y u v 16 2
A small object in space A small object in space has a large frequency has a large frequency extent and vice-versa. extent and vice-versa.

space

frequency

FT FT

27 April 2008

1999-2007 by Richard Alan Peters II

19

The Uncertainty Relation


frequency small extent space large extent

IFT IFT

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

small extent frequency large extent

large extent space small extent

IFT IFT

small extent

large extent 1999-2007 by Richard Alan Peters II

27 April 2008

20

Ideal Filters Do Not Produce Ideal Results

IFT IFT

A sharp cutoff in the A sharp cutoff in the frequency domain frequency domain
27 April 2008

causes ringing in the causes ringing in the spatial domain. spatial domain.
21

1999-2007 by Richard Alan Peters II

Ideal Filters Do Not Produce Ideal Results

Ideal LPF Ideal LPF

Blurring the image above Blurring the image above w/ an ideal lowpass filter w/ an ideal lowpass filter
27 April 2008

distorts the results with distorts the results with ringing or ghosting. ringing or ghosting.
22

1999-2007 by Richard Alan Peters II

Optimal Filter: The Gaussian

IFT IFT

The Gaussian filter optimizes the uncertainty relation. The Gaussian filter optimizes the uncertainty relation. It provides the sharpest cutoff with the least ringing. It provides the sharpest cutoff with the least ringing.
27 April 2008
1999-2007 by Richard Alan Peters II

23

One-Dimensional Gaussian

g ( x) =
27 April 2008

1 2

( x ) 2 2 2

1999-2007 by Richard Alan Peters II

24

Two-Dimensional Gaussian
R = 512, C = 512

g ( r, c) = g ( r ) g (c) = 1 2 e
r c

If and are If and are different for rr& cc different for &
2

( r r )2 ( y c ) 2 2 2 r 2 c

= 1 2 e
r c

2 2 c ( x r )2 + r ( y c )2 2 2 2 r c

or if and are or if and are the same for rr& cc. the same for & .

= 257, = 64

g ( r, c ) = 212 e

( r )2 + ( c )2 2 2

27 April 2008

1999-2007 by Richard Alan Peters II

25

Optimal Filter: The Gaussian

Gaussian LPF Gaussian LPF

With a gaussian lowpass With a gaussian lowpass filter, the image above filter, the image above
27 April 2008

is blurred without ringing is blurred without ringing or ghosting. or ghosting.


26

1999-2007 by Richard Alan Peters II

Gaussian Lowpass Filter


Multiply by Multiply by this, or this, or convolve convolve by this by this

Image size: 512x512 Image size: 512x512 SD filter sigma 8 SD filter sigma ==8

Fourier Domain Rep. Fourier Domain Rep.

Spatial Representation Spatial Representation

Central Profile Central Profile

27 April 2008

1999-2007 by Richard Alan Peters II

27

Gaussian Lowpass Filter


Multiply by Multiply by this, or this, or convolve convolve by this by this

Image size: 512x512 Image size: 512x512 SD filter sigma 2 SD filter sigma ==2

Fourier Domain Rep. Fourier Domain Rep.

Spatial Representation Spatial Representation

Central Profile Central Profile

27 April 2008

1999-2007 by Richard Alan Peters II

28

Gaussian Lowpass Filter

Image size: 512x512 Image size: 512x512 SD filter sigma 8 SD filter sigma ==8

Original Image Original Image

Power Spectrum Power Spectrum

Gaussian LPF in FD Gaussian LPF in FD

27 April 2008

1999-2007 by Richard Alan Peters II

29

Gaussian Lowpass Filter

Image size: 512x512 Image size: 512x512 SD filter sigma 8 SD filter sigma ==8

Filtered Image Filtered Image

Filtered Power Spectrum Filtered Power Spectrum

Original Image Original Image

27 April 2008

1999-2007 by Richard Alan Peters II

30

Gaussian Highpass Filter


Multiply by Multiply by this, or this, or convolve convolve by this by this

Image size: 512x512 Image size: 512x512 FD notch sigma 8 FD notch sigma ==8

Fourier Domain Rep. Fourier Domain Rep.

Spatial Representation Spatial Representation

Central Profile Central Profile

27 April 2008

1999-2007 by Richard Alan Peters II

31

Gaussian Highpass Filter

Image size: 512x512 Image size: 512x512 FD notch sigma 8 FD notch sigma ==8

Original Image Original Image

Power Spectrum Power Spectrum

Gaussian HPF in FD Gaussian HPF in FD

27 April 2008

1999-2007 by Richard Alan Peters II

32

**signedimage; 0 signed image; 0

mapped to 128 mapped to 128

Gaussian Highpass Filter

Image size: 512x512 Image size: 512x512 FD notch sigma 8 FD notch sigma ==8

Filtered Image* Filtered Image*

Filtered Power Spectrum Filtered Power Spectrum

Original Image Original Image

27 April 2008

1999-2007 by Richard Alan Peters II

33

**signedimage; 0 signed image; 0

mapped to 128 mapped to 128

Gaussian Highpass Filter

Image size: 512x512 Image size: 512x512 FD notch sigma 8 FD notch sigma ==8

Positive Pixels Filtered Image Positive Pixels Filtered Image

Filtered Image* Filtered Image*

Negative Pixels Negative Pixels

27 April 2008

1999-2007 by Richard Alan Peters II

34

**signedimage; 0 signed image; 0

mapped to 128 mapped to 128

Comparison of Ideal and Gaussian Filters

Ideal LPF Ideal LPF

Original Image Original Image

Ideal HPF* Ideal HPF*

27 April 2008

1999-2007 by Richard Alan Peters II

35

**signedimage; 0 signed image; 0

mapped to 128 mapped to 128

Comparison of Ideal and Gaussian Filters

Gaussian LPF Gaussian LPF

Original Image Original Image

Gaussian HPF* Gaussian HPF*

27 April 2008

1999-2007 by Richard Alan Peters II

36

*signed image; 0 *signed image; 0

mapped to 128 mapped to 128

Another Highpass Filter

original image original image

filter power spectrum filter power spectrum

filtered image* filtered image*

27 April 2008

1999-2007 by Richard Alan Peters II

37

*signed image; 0 *signed image; 0

mapped to 128 mapped to 128

Ideal Bandpass Filter

original image original image

filter power spectrum filter power spectrum

filtered image* filtered image*

27 April 2008

1999-2007 by Richard Alan Peters II

38

Gaussian Bandpass Filter

Image size: 512x512 Image size: 512x512 sigma 2 sigma 8 sigma ==2 --sigma ==8

Fourier Domain Rep. Fourier Domain Rep.

Spatial Representation Spatial Representation

Central Profile Central Profile

27 April 2008

1999-2007 by Richard Alan Peters II

39

Gaussian Bandpass Filter

Image size: 512x512 Image size: 512x512 sigma 2 sigma 8 sigma ==2 --sigma ==8

Original Image Original Image

Power Spectrum Power Spectrum

Gaussian BPF in FD Gaussian BPF in FD

27 April 2008

1999-2007 by Richard Alan Peters II

40

**signedimage; 0 signed image; 0

mapped to 128 mapped to 128

Gaussian Bandpass Filter

Image size: 512x512 Image size: 512x512 sigma 2 sigma 8 sigma ==2 --sigma ==8

Filtered Image* Filtered Image*

Filtered Power Spectrum Filtered Power Spectrum

Original Image Original Image

27 April 2008

1999-2007 by Richard Alan Peters II

41

**signedimage; 0 signed image; 0

mapped to 128 mapped to 128

Gaussian Bandpass Filter

Image size: 512x512 Image size: 512x512 sigma 2 sigma 8 sigma ==2 --sigma ==8

Positive Pixels Filtered Image Positive Pixels Filtered Image

FilteredImage** Filtered Image

Negative Pixels Negative Pixels

27 April 2008

1999-2007 by Richard Alan Peters II

42

**signedimage; 0 signed image; 0

mapped to 128 mapped to 128

Comparison of Ideal and Gaussian Filters

Ideal BPF* Ideal BPF*

Original Image Original Image

Gaussian BPF* Gaussian BPF*

27 April 2008

1999-2007 by Richard Alan Peters II

43

Power Spectrum and Phase of a Blurred Image

blurred image blurred image


27 April 2008

power spectrum power spectrum

phase phase
44

1999-2007 by Richard Alan Peters II

Power Spectrum and Phase of an Image

original image original image


27 April 2008

power spectrum power spectrum

phase phase
45

1999-2007 by Richard Alan Peters II

Power Spectrum and Phase of a Sharpened Image

sharpened image sharpened image


27 April 2008

power spectrum power spectrum

phase phase
46

1999-2007 by Richard Alan Peters II

You might also like