Sie sind auf Seite 1von 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 convolution equals the product of the Fourier Transforms. Similarly, the Fourier Transform of a convolution is the product of the Fourier Transforms

August 11, 2012

1999-2007 by Richard Alan Peters II

Convolution via Fourier Transform

Image & Mask

Transforms

Pixel-wise Product

Inverse Transform

August 11, 2012

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. 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 need to do each step for Create: H = zeros(size(I)); 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

August 11, 2012

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

After FFT shift

After IFFT shift

After IFFT shift

August 11, 2012

1999-2007 by Richard Alan Peters II

Matlabs fftshift and ifftshift


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

7 5 2 3 1 2 3 1 8 9 6

9 4

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


August 11, 2012

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


2 3 1

1999-2007 by Richard Alan Peters II

Blurring: Averaging / Lowpass Filtering


Blurring results from:
q

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.

Lowpass filtering in the frequency domain:


August 11, 2012

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:
q

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.

Highpass filtered in the frequency domain:


August 11, 2012

1999-2007 by Richard Alan Peters II

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} .
August 11, 2012

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

1999-2007 by Richard Alan Peters II

Ideal Lowpass Filter


Multiply by this, or convolve by this

Image size: 512x512 FD filter radius: 16

Fourier Domain Rep.

Spatial Representation

Central Profile

August 11, 2012

1999-2007 by Richard Alan Peters II

10

Ideal Lowpass Filter


Multiply by this, or convolve by this

Image size: 512x512 FD filter radius: 8

Fourier Domain Rep.

Spatial Representation

Central Profile

August 11, 2012

1999-2007 by Richard Alan Peters II

11

Consider the image below:

Power Spectrum and Phase of an Image

Original Image

Power Spectrum

Phase

August 11, 2012

1999-2007 by Richard Alan Peters II

12

Ideal Lowpass Filter

Image size: 512x512 FD filter radius: 16

Original Image

Power Spectrum

Ideal LPF in FD

August 11, 2012

1999-2007 by Richard Alan Peters II

13

Ideal Lowpass Filter

Image size: 512x512 FD filter radius: 16

Filtered Image

Filtered Power Spectrum

Original Image

August 11, 2012

1999-2007 by Richard Alan Peters II

14

Ideal Highpass Filter


Multiply by this, or convolve by this

Image size: 512x512 FD notch radius: 16

Fourier Domain Rep.

Spatial Representation

Central Profile

August 11, 2012

1999-2007 by Richard Alan Peters II

15

Ideal Highpass Filter

Image size: 512x512 FD notch radius: 16

Original Image

Power Spectrum

Ideal HPF in FD

August 11, 2012

1999-2007 by Richard Alan Peters II

16

signed image; 0 mapped to 128

Ideal Highpass Filter

Image size: 512x512 FD notch radius: 16

Filtered Image*

Filtered Power Spectrum

Original Image

August 11, 2012

1999-2007 by Richard Alan Peters II

17

signed image; 0 mapped to 128

Ideal Highpass Filter

Image size: 512x512 FD notch radius: 16

Positive Pixels

Filtered Image*

Negative Pixels

August 11, 2012

1999-2007 by Richard Alan Peters II

18

The Uncertainty Relation


space frequency

FT

space

frequency

FT

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


19

August 11, 2012

1999-2007 by Richard Alan Peters II

The Uncertainty Relation


frequency small extent space

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.

large extent

small extent frequency large extent

large extent space

small extent

IFT

small extent

large extent 1999-2007 by Richard Alan Peters II

August 11, 2012

20

Ideal Filters Do Not Produce Ideal Results

IFT

A sharp cutoff in the frequency domain

causes ringing in the spatial domain.

August 11, 2012

1999-2007 by Richard Alan Peters II

21

Ideal Filters Do Not Produce Ideal Results

Ideal LPF

Blurring the image above w/ an ideal lowpass filter


August 11, 2012

distorts the results with ringing or ghosting.


22

1999-2007 by Richard Alan Peters II

Optimal Filter: The Gaussian

IFT

The Gaussian filter optimizes the uncertainty relation. It provides the sharpest cutoff with the least ringing.
August 11, 2012
1999-2007 by Richard Alan Peters II

23

One-Dimensional Gaussian

g ( x) =
August 11, 2012

1 1

( x )1 1 1

1999-2007 by Richard Alan Peters II

24

Two-Dimensional Gaussian
R = 512, C = 512

If and are different for r & c

or if and are the same for r & c.

= 257, = 64

August 11, 2012

1999-2007 by Richard Alan Peters II

25

Optimal Filter: The Gaussian

Gaussian LPF

With a gaussian lowpass filter, the image above


August 11, 2012

is blurred without ringing or ghosting.


26

1999-2007 by Richard Alan Peters II

Gaussian Lowpass Filter


Multiply by this, or convolve by this

Image size: 512x512 SD filter sigma = 8

Fourier Domain Rep.

Spatial Representation

Central Profile

August 11, 2012

1999-2007 by Richard Alan Peters II

27

Gaussian Lowpass Filter


Multiply by this, or convolve by this

Image size: 512x512 SD filter sigma = 2

Fourier Domain Rep.

Spatial Representation

Central Profile

August 11, 2012

1999-2007 by Richard Alan Peters II

28

Gaussian Lowpass Filter

Image size: 512x512 SD filter sigma = 8

Original Image

Power Spectrum

Gaussian LPF in FD

August 11, 2012

1999-2007 by Richard Alan Peters II

29

Gaussian Lowpass Filter

Image size: 512x512 SD filter sigma = 8

Filtered Image

Filtered Power Spectrum

Original Image

August 11, 2012

1999-2007 by Richard Alan Peters II

30

Gaussian Highpass Filter


Multiply by this, or convolve by this

Image size: 512x512 FD notch sigma = 8

Fourier Domain Rep.

Spatial Representation

Central Profile

August 11, 2012

1999-2007 by Richard Alan Peters II

31

Gaussian Highpass Filter

Image size: 512x512 FD notch sigma = 8

Original Image

Power Spectrum

Gaussian HPF in FD

August 11, 2012

1999-2007 by Richard Alan Peters II

32

signed image; 0 mapped to 128

Gaussian Highpass Filter

Image size: 512x512 FD notch sigma = 8

Filtered Image*

Filtered Power Spectrum

Original Image

August 11, 2012

1999-2007 by Richard Alan Peters II

33

signed image; 0 mapped to 128

Gaussian Highpass Filter

Image size: 512x512 FD notch sigma = 8

Positive Pixels Filtered Image

Filtered Image*

Negative Pixels

August 11, 2012

1999-2007 by Richard Alan Peters II

34

signed image; 0 mapped to 128

Comparison of Ideal and Gaussian Filters

Ideal LPF

Original Image

Ideal HPF*

August 11, 2012

1999-2007 by Richard Alan Peters II

35

signed image; 0 mapped to 128

Comparison of Ideal and Gaussian Filters

Gaussian LPF

Original Image

Gaussian HPF*

August 11, 2012

1999-2007 by Richard Alan Peters II

36

signed image; 0 mapped to 128

Another Highpass Filter

original image original image

filter power spectrum filter power spectrum

filtered image* filtered image*

August 11, 2012

1999-2007 by Richard Alan Peters II

37

signed image; 0 mapped to 128

Ideal Bandpass Filter

original image original image

filter power spectrum filter power spectrum

filtered image* filtered image*

August 11, 2012

1999-2007 by Richard Alan Peters II

38

Gaussian Bandpass Filter

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

Fourier Domain Rep.

Spatial Representation

Central Profile

August 11, 2012

1999-2007 by Richard Alan Peters II

39

Gaussian Bandpass Filter

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

Original Image

Power Spectrum

Gaussian BPF in FD

August 11, 2012

1999-2007 by Richard Alan Peters II

40

signed image; 0 mapped to 128

Gaussian Bandpass Filter

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

Filtered Image*

Filtered Power Spectrum

Original Image

August 11, 2012

1999-2007 by Richard Alan Peters II

41

signed image; 0 mapped to 128

Gaussian Bandpass Filter

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

Positive Pixels Filtered Image

Filtered Image*

Negative Pixels

August 11, 2012

1999-2007 by Richard Alan Peters II

42

signed image; 0 mapped to 128

Comparison of Ideal and Gaussian Filters

Ideal BPF*

Original Image

Gaussian BPF*

August 11, 2012

1999-2007 by Richard Alan Peters II

43

Power Spectrum and Phase of a Blurred Image

blurred image blurred image


August 11, 2012

power spectrum power spectrum


1999-2007 by Richard Alan Peters II

phase phase
44

Power Spectrum and Phase of an Image

original image original image


August 11, 2012

power spectrum power spectrum


1999-2007 by Richard Alan Peters II

phase phase
45

Power Spectrum and Phase of a Sharpened Image

sharpened image sharpened image


August 11, 2012

power spectrum power spectrum


1999-2007 by Richard Alan Peters II

phase phase
46

Das könnte Ihnen auch gefallen