eece253_08_frequencyfiltering

46
EECE\CS 253 Image Processing Richard Alan Peters II Department of Electrical Engineering and Computer Science Fall Semester 2007 Lecture Notes Lecture Notes: Frequency Filtering 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.

Upload: dhishna-devadas

Post on 27-Oct-2014

10 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: EECE253_08_FrequencyFiltering

EECE\CS 253 Image Processing

Richard Alan Peters II

Department of Electrical Engineering and Computer Science

Fall Semester 2007

Lecture NotesLecture Notes: Frequency Filtering

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.

Page 2: EECE253_08_FrequencyFiltering

April 7, 2023 2April 7, 2023 2 1999-2007 by Richard Alan Peters II

Convolution Property of the Fourier Transform

.}{

Moreover,

.}{

Then,

).,( and ),( TransformsFourier

have ),( and ),( functionsLet

GFgf

GFgf

vuGvuF

crgcrf

F

F 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

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

* = convolution · = multiplication

Page 3: EECE253_08_FrequencyFiltering

April 7, 2023 3April 7, 2023 3 1999-2007 by Richard Alan Peters II

Convolution via Fourier Transform

Image & Mask Transforms

Pixel-wise Product

Inverse Transform

Page 4: EECE253_08_FrequencyFiltering

April 7, 2023 4April 7, 2023 4 1999-2007 by Richard Alan Peters II

1. Read the image from a file into a variable, say I.

2. Read in or create the convolution mask, h.

3. Compute the sum of the mask: s = sum(sum(h));

4. If s == 0, set s = 1;

5. Create: H = zeros(size(I));

6. Copy h into the middle of H.

7. Shift H into position: H = ifftshift(H);

8. Take the 2D FT of I and H: FI=fft2(I); FH=fft2(H);

9. Pointwise multiply the FTs: FJ=FI.*FH;

10. Compute the inverse FT: J = real(ifft2(FJ));

11. Normalize the result: J = J/s;

How to Convolve via FT in Matlab

For color images you may need to do each step for each band separately.

For color images you may need to do each step for each band separately.

The mask is usually 1-band

The mask is usually 1-band

Page 5: EECE253_08_FrequencyFiltering

April 7, 2023 5April 7, 2023 5 1999-2007 by Richard Alan Peters II

Coordinate Origin of the FFT

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

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

Even EvenOdd Odd

Image Origin Weight Matrix OriginImage Origin Weight Matrix Origin

After FFT shift After IFFT shiftAfter FFT shift After IFFT shift

Page 6: EECE253_08_FrequencyFiltering

April 7, 2023 6April 7, 2023 6 1999-2007 by Richard Alan Peters II

5 6 4

8 9 7

2 3 1

1 2 3

4 5 6

7 8 9

Matlab’s fftshift and ifftshift

J = fftshift(I):

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

I = ifftshift(J):

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

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

1 2 3

4 5 6

7 8 9

5 6 4

8 9 7

2 3 1

Page 7: EECE253_08_FrequencyFiltering

April 7, 2023 7April 7, 2023 7 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.

Lowpass filtering in the frequency domain:– 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.

Page 8: EECE253_08_FrequencyFiltering

April 7, 2023 8April 7, 2023 8 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. Highpass filtered in the frequency domain:

– 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.

Page 9: EECE253_08_FrequencyFiltering

April 7, 2023 9April 7, 2023 9 1999-2007 by Richard Alan Peters II

Convolution Property of the Fourier Transform

.

by compute can weThus

.}{

Moreover,

.}{

Then,

).,( and ),( TransformsFourier

have ),( and ),( functionsLet

1 GFgf

gf

GFgf

GFgf

vuGvuF

crgcrf

-

F

F

FThe 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

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

* = convolution · = multiplication

Recall:Recall:

Page 10: EECE253_08_FrequencyFiltering

April 7, 2023 10April 7, 2023 10 1999-2007 by Richard Alan Peters II

Ideal Lowpass Filter

Fourier Domain Rep.Fourier Domain Rep. Spatial RepresentationSpatial Representation Central ProfileCentral Profile

Image size: 512x512FD filter radius: 16

Image size: 512x512FD filter radius: 16

Multiply by this, or …

… convolve by this

Page 11: EECE253_08_FrequencyFiltering

April 7, 2023 11April 7, 2023 11 1999-2007 by Richard Alan Peters II

Fourier Domain Rep.Fourier Domain Rep. Spatial RepresentationSpatial Representation Central ProfileCentral Profile

Ideal Lowpass Filter Image size: 512x512FD filter radius: 8

Image size: 512x512FD filter radius: 8

Multiply by this, or …

… convolve by this

Page 12: EECE253_08_FrequencyFiltering

April 7, 2023 12April 7, 2023 12 1999-2007 by Richard Alan Peters II

Power Spectrum and Phase of an Image

Consider the image below:

Consider the image below:

Original ImageOriginal Image Power SpectrumPower Spectrum PhasePhase

Page 13: EECE253_08_FrequencyFiltering

April 7, 2023 13April 7, 2023 13 1999-2007 by Richard Alan Peters II

Ideal LPF in FDIdeal LPF in FDOriginal ImageOriginal Image Power SpectrumPower Spectrum

Ideal Lowpass Filter Image size: 512x512FD filter radius: 16

Image size: 512x512FD filter radius: 16

Page 14: EECE253_08_FrequencyFiltering

April 7, 2023 14April 7, 2023 14 1999-2007 by Richard Alan Peters II

Original ImageOriginal ImageFiltered ImageFiltered Image Filtered Power SpectrumFiltered Power Spectrum

Ideal Lowpass Filter Image size: 512x512FD filter radius: 16

Image size: 512x512FD filter radius: 16

Page 15: EECE253_08_FrequencyFiltering

April 7, 2023 15April 7, 2023 15 1999-2007 by Richard Alan Peters II

Ideal Highpass Filter

Fourier Domain Rep.Fourier Domain Rep. Spatial RepresentationSpatial Representation Central ProfileCentral Profile

Image size: 512x512FD notch radius: 16

Image size: 512x512FD notch radius: 16

Multiply by this, or …

Multiply by this, or …

… convolve by this

… convolve by this

Page 16: EECE253_08_FrequencyFiltering

April 7, 2023 16April 7, 2023 16 1999-2007 by Richard Alan Peters II

Ideal HPF in FDIdeal HPF in FDOriginal ImageOriginal Image Power SpectrumPower Spectrum

Ideal Highpass Filter Image size: 512x512FD notch radius: 16

Image size: 512x512FD notch radius: 16

Page 17: EECE253_08_FrequencyFiltering

April 7, 2023 17April 7, 2023 17 1999-2007 by Richard Alan Peters II

Original ImageOriginal ImageFiltered Image*Filtered Image*Filtered Power SpectrumFiltered Power Spectrum

Ideal Highpass Filter Image size: 512x512FD notch radius: 16

Image size: 512x512FD notch radius: 16

*signed image; 0 mapped to 128

*signed image; 0 mapped to 128

Page 18: EECE253_08_FrequencyFiltering

April 7, 2023 18April 7, 2023 18 1999-2007 by Richard Alan Peters II

Filtered Image*Filtered Image*Positive PixelsPositive Pixels Negative PixelsNegative Pixels

Ideal Highpass Filter Image size: 512x512FD notch radius: 16

Image size: 512x512FD notch radius: 16

*signed image; 0 mapped to 128

*signed image; 0 mapped to 128

Page 19: EECE253_08_FrequencyFiltering

April 7, 2023 19April 7, 2023 19 1999-2007 by Richard Alan Peters II

The Uncertainty Relation

FTFT

space frequency

FTFT

space frequency

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

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

Page 20: EECE253_08_FrequencyFiltering

April 7, 2023 20April 7, 2023 20 1999-2007 by Richard Alan Peters II

The Uncertainty Relation

Recall: a symmetric pair of impulses in the frequency domain becomes a sinusoid in the spatial domain.

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.

A symmetric pair of lines in the frequency domain becomes a sinusoidal line in the spatial domain.

IFTIFT

spacefrequency

la

rge

ext

en

t

small extent

sm

all e

xten

t

large extent

IFTIFT

spacefrequency

small extent

s

ma

ll e

xte

nt

la

rge

exte

nt

large extent

Page 21: EECE253_08_FrequencyFiltering

April 7, 2023 21April 7, 2023 21 1999-2007 by Richard Alan Peters II

Ideal Filters Do Not Produce Ideal Results

A sharp cutoff in the frequency domain…

A sharp cutoff in the frequency domain…

…causes ringing in the spatial domain.

…causes ringing in the spatial domain.

IFTIFT

Page 22: EECE253_08_FrequencyFiltering

April 7, 2023 22April 7, 2023 22 1999-2007 by Richard Alan Peters II

Ideal Filters Do Not Produce Ideal Results

Ideal LPFIdeal LPF

Blurring the image above w/ an ideal lowpass filter…

Blurring the image above w/ an ideal lowpass filter…

…distorts the results with ringing or ghosting.

…distorts the results with ringing or ghosting.

Page 23: EECE253_08_FrequencyFiltering

April 7, 2023 23April 7, 2023 23 1999-2007 by Richard Alan Peters II

Optimal Filter: The Gaussian

The Gaussian filter optimizes the uncertainty relation. It provides the sharpest cutoff with the least ringing.

The Gaussian filter optimizes the uncertainty relation. It provides the sharpest cutoff with the least ringing.

IFTIFT

Page 24: EECE253_08_FrequencyFiltering

April 7, 2023 24April 7, 2023 24 1999-2007 by Richard Alan Peters II

One-Dimensional Gaussian

22 2)(

21)(

xexg

Page 25: EECE253_08_FrequencyFiltering

April 7, 2023 25April 7, 2023 25 1999-2007 by Richard Alan Peters II

Two-Dimensional GaussianIf and are different for r & c…

If and are different for r & c…

…or if and are the same for r & c.

…or if and are the same for r & c.

r

cR = 512, C = 512

= 257, = 64

Page 26: EECE253_08_FrequencyFiltering

April 7, 2023 26April 7, 2023 26 1999-2007 by Richard Alan Peters II

Gaussian LPFGaussian LPF

With a gaussian lowpass filter, the image above …

With a gaussian lowpass filter, the image above …

… is blurred without ringing or ghosting.

… is blurred without ringing or ghosting.

Optimal Filter: The Gaussian

Page 27: EECE253_08_FrequencyFiltering

April 7, 2023 27April 7, 2023 27 1999-2007 by Richard Alan Peters II

Fourier Domain Rep.Fourier Domain Rep. Spatial RepresentationSpatial Representation Central ProfileCentral Profile

Image size: 512x512SD filter sigma = 8

Image size: 512x512SD filter sigma = 8Gaussian Lowpass Filter

Multiply by this, or …

Multiply by this, or …

… convolve by this

… convolve by this

Page 28: EECE253_08_FrequencyFiltering

April 7, 2023 28April 7, 2023 28 1999-2007 by Richard Alan Peters II

Fourier Domain Rep.Fourier Domain Rep. Spatial RepresentationSpatial Representation Central ProfileCentral Profile

Gaussian Lowpass Filter Image size: 512x512SD filter sigma = 2

Image size: 512x512SD filter sigma = 2

Multiply by this, or …

Multiply by this, or …

… convolve by this

… convolve by this

Page 29: EECE253_08_FrequencyFiltering

April 7, 2023 29April 7, 2023 29 1999-2007 by Richard Alan Peters II

Gaussian LPF in FDGaussian LPF in FDOriginal ImageOriginal Image Power SpectrumPower Spectrum

Image size: 512x512SD filter sigma = 8

Image size: 512x512SD filter sigma = 8Gaussian Lowpass Filter

Page 30: EECE253_08_FrequencyFiltering

April 7, 2023 30April 7, 2023 30 1999-2007 by Richard Alan Peters II

Original ImageOriginal ImageFiltered ImageFiltered Image Filtered Power SpectrumFiltered Power Spectrum

Gaussian Lowpass Filter Image size: 512x512SD filter sigma = 8

Image size: 512x512SD filter sigma = 8

Page 31: EECE253_08_FrequencyFiltering

April 7, 2023 31April 7, 2023 31 1999-2007 by Richard Alan Peters II

Gaussian Highpass Filter

Fourier Domain Rep.Fourier Domain Rep. Spatial RepresentationSpatial Representation Central ProfileCentral Profile

Image size: 512x512FD notch sigma = 8

Image size: 512x512FD notch sigma = 8

Multiply by this, or …

Multiply by this, or …

… convolve by this

… convolve by this

Page 32: EECE253_08_FrequencyFiltering

April 7, 2023 32April 7, 2023 32 1999-2007 by Richard Alan Peters II

Gaussian HPF in FDGaussian HPF in FDOriginal ImageOriginal Image Power SpectrumPower Spectrum

Gaussian Highpass Filter Image size: 512x512FD notch sigma = 8

Image size: 512x512FD notch sigma = 8

Page 33: EECE253_08_FrequencyFiltering

April 7, 2023 33April 7, 2023 33 1999-2007 by Richard Alan Peters II

Original ImageOriginal ImageFiltered Power SpectrumFiltered Power Spectrum

Gaussian Highpass Filter Image size: 512x512FD notch sigma = 8

Image size: 512x512FD notch sigma = 8

*signed image; 0 mapped to 128

*signed image; 0 mapped to 128

Filtered Image*Filtered Image*

Page 34: EECE253_08_FrequencyFiltering

April 7, 2023 34April 7, 2023 34 1999-2007 by Richard Alan Peters II

Negative PixelsNegative PixelsFiltered ImageFiltered ImagePositive PixelsPositive Pixels

Gaussian Highpass Filter Image size: 512x512FD notch sigma = 8

Image size: 512x512FD notch sigma = 8

*signed image; 0 mapped to 128

*signed image; 0 mapped to 128

Filtered Image*Filtered Image*

Page 35: EECE253_08_FrequencyFiltering

April 7, 2023 35April 7, 2023 35 1999-2007 by Richard Alan Peters II

Original ImageOriginal Image Ideal HPF*Ideal HPF*Ideal LPFIdeal LPF

Comparison of Ideal and Gaussian Filters

*signed image; 0 mapped to 128

*signed image; 0 mapped to 128

Page 36: EECE253_08_FrequencyFiltering

April 7, 2023 36April 7, 2023 36 1999-2007 by Richard Alan Peters II

Original ImageOriginal Image Gaussian HPF*Gaussian HPF*Gaussian LPFGaussian LPF

Comparison of Ideal and Gaussian Filters

*signed image; 0 mapped to 128

*signed image; 0 mapped to 128

Page 37: EECE253_08_FrequencyFiltering

April 7, 2023 37April 7, 2023 37 1999-2007 by Richard Alan Peters II

Another Highpass Filter

original imageoriginal image filter power spectrumfilter power spectrum filtered image*filtered image*

*signed image; 0 mapped to 128

*signed image; 0 mapped to 128

Page 38: EECE253_08_FrequencyFiltering

April 7, 2023 38April 7, 2023 38 1999-2007 by Richard Alan Peters II

Ideal Bandpass Filter

original imageoriginal image filter power spectrumfilter power spectrum filtered image*filtered image*

*signed image; 0 mapped to 128

*signed image; 0 mapped to 128

Page 39: EECE253_08_FrequencyFiltering

April 7, 2023 39April 7, 2023 39 1999-2007 by Richard Alan Peters II

Gaussian Bandpass Filter

Fourier Domain Rep.Fourier Domain Rep. Spatial RepresentationSpatial Representation Central ProfileCentral Profile

Image size: 512x512sigma = 2 - sigma = 8

Image size: 512x512sigma = 2 - sigma = 8

Page 40: EECE253_08_FrequencyFiltering

April 7, 2023 40April 7, 2023 40 1999-2007 by Richard Alan Peters II

Gaussian BPF in FDGaussian BPF in FDOriginal ImageOriginal Image Power SpectrumPower Spectrum

Gaussian Bandpass Filter Image size: 512x512sigma = 2 - sigma = 8

Image size: 512x512sigma = 2 - sigma = 8

Page 41: EECE253_08_FrequencyFiltering

April 7, 2023 41April 7, 2023 41 1999-2007 by Richard Alan Peters II

Original ImageOriginal ImageFiltered Image*Filtered Image*Filtered Power SpectrumFiltered Power Spectrum

Gaussian Bandpass Filter Image size: 512x512sigma = 2 - sigma = 8

Image size: 512x512sigma = 2 - sigma = 8

*signed image; 0 mapped to 128

*signed image; 0 mapped to 128

Page 42: EECE253_08_FrequencyFiltering

April 7, 2023 42April 7, 2023 42 1999-2007 by Richard Alan Peters II

Filtered Image*Filtered Image*Negative PixelsNegative PixelsFiltered ImageFiltered ImagePositive PixelsPositive Pixels

Gaussian Bandpass Filter Image size: 512x512sigma = 2 - sigma = 8

Image size: 512x512sigma = 2 - sigma = 8

*signed image; 0 mapped to 128

*signed image; 0 mapped to 128

Page 43: EECE253_08_FrequencyFiltering

April 7, 2023 43April 7, 2023 43 1999-2007 by Richard Alan Peters II

Original ImageOriginal Image Gaussian BPF*Gaussian BPF*Ideal BPF*Ideal BPF*

Comparison of Ideal and Gaussian Filters

*signed image; 0 mapped to 128

*signed image; 0 mapped to 128

Page 44: EECE253_08_FrequencyFiltering

April 7, 2023 44April 7, 2023 44 1999-2007 by Richard Alan Peters II

Power Spectrum and Phase of a Blurred Image

blurred imageblurred image power spectrumpower spectrum phasephase

Page 45: EECE253_08_FrequencyFiltering

April 7, 2023 45April 7, 2023 45 1999-2007 by Richard Alan Peters II

Power Spectrum and Phase of an Image

original imageoriginal image power spectrumpower spectrum phasephase

Page 46: EECE253_08_FrequencyFiltering

April 7, 2023 46April 7, 2023 46 1999-2007 by Richard Alan Peters II

Power Spectrum and Phase of a Sharpened Image

sharpened imagesharpened image power spectrumpower spectrum phasephase