Top Banner
Image Processing Frequency Filtering Instructor: Juyong Zhang [email protected] http://staff.ustc.edu.cn/~juyong
65

Image Processing Frequency Filtering Instructor: Juyong Zhang [email protected] juyong.

Jan 15, 2016

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

Image Processing

Frequency Filtering

Instructor: Juyong [email protected]

http://staff.ustc.edu.cn/~juyong

Page 2: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

Convolution Property of the Fourier Transform

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

04/21/23 2

Page 3: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

Convolution via Fourier Transform

Image & Mask Transforms

Pixel-wise Product

Inverse Transform

04/21/23 3

Page 4: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

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(h(:));

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

5. Replace h with h = h/s;

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

7. Copy h into the middle of H.

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

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

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

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

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

04/21/23 4

Page 5: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

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

04/21/23 5

Page 6: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

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

04/21/23 6

Page 7: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

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.

04/21/23 7

Page 8: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

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.

04/21/23 8

Page 9: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

Convolution Property of the Fourier Transform

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

Recall:Recall:

04/21/23 9

Page 10: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

04/21/23 10

Ideal Lowpass Filter

Page 11: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

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

04/21/23 11

Page 12: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

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

04/21/23 12

Fourier Domain Rep.Fourier Domain Rep.

Page 13: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

Power Spectrum and Phase of an Image

Consider the image below:

Consider the image below:

Original ImageOriginal Image Power SpectrumPower Spectrum PhasePhase

04/21/23 13

Page 14: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

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

04/21/23 14

Page 15: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

Filtered Power SpectrumFiltered Power Spectrum

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

Image size: 512x512FD filter radius: 16

04/21/23 15

Filtered ImageFiltered ImageOriginal ImageOriginal Image

Page 16: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

04/21/23 16

Ideal Highpass Filter

Page 17: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

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

04/21/23 17

Page 18: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

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

04/21/23 18

Page 19: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

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

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

Image size: 512x512FD notch radius: 16

04/21/23 19

*signed image: 0 mapped to 128

*signed image: 0 mapped to 128

Page 20: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

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

04/21/23 20

Page 21: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

04/21/23 21

Ideal Bandpass Filter

Page 22: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

Ideal Bandpass Filter

04/21/23 22

A bandpass filter is created by (1)subtracting a FD radius 2 lowpass filtered image from a FD radius 1 lowpass filtered image, where 2 < 1, or (2)convolving the image with a mask that is the difference of the two lowpass masks.

FD LP mask with radius 1FD LP mask with radius 1 FD LP mask with radius 2

FD LP mask with radius 2 FD BP mask 1 - 2FD BP mask 1 - 2

- =

Page 23: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

Ideal Bandpass Filter

04/21/23 23

*signed image: 0 mapped to 128

*signed image: 0 mapped to 128

image LPF radius 1image LPF radius 1 image LPF radius 2

image LPF radius 2 image BPF radii 1, 2*image BPF radii 1, 2*

Page 24: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

Ideal Bandpass Filter

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

04/21/23 24

*signed image: 0 mapped to 128

*signed image: 0 mapped to 128

Page 25: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

A Different Ideal Bandpass Filter

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

04/21/23 25

*signed image: 0 mapped to 128

*signed image: 0 mapped to 128

Page 26: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

04/21/23 26

The Optimal Filter

Page 27: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

The Uncertainty Relation

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.

04/21/23 27

space frequency

FTFT

Page 28: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

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.

04/21/23 28

spacespacefrequency

small extent

s

ma

ll e

xte

nt

la

rge

exte

nt

large extent

IFTIFT

spacespacefrequency

la

rge

ext

en

t

small extent

sm

all e

xten

t

large extent

IFTIFT

Page 29: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

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

04/21/23 29

Page 30: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

Ideal Filters Do Not Produce Ideal Results

Ideal LPFIdeal LPF

Blurring the image above with an ideal lowpass filter…

Blurring the image above with an ideal lowpass filter…

…distorts the results with ringing or ghosting.

…distorts the results with ringing or ghosting.

04/21/23 30

Page 31: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

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

04/21/23 31

Page 32: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

One-Dimensional Gaussian

22 2)(

21)(

xexg

04/21/23 32

Page 33: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

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

04/21/23 33

Page 34: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

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

04/21/23 34

Page 35: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

Compare with an “Ideal” LPF

Ideal LPFIdeal LPF

Blurring the image above with an ideal lowpass filter…

Blurring the image above with an ideal lowpass filter…

…distorts the results with ringing or ghosting.

…distorts the results with ringing or ghosting.

04/21/23 35

Page 36: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

04/21/23 36

Gaussian Lowpass Filter

Page 37: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

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

04/21/23 37

Page 38: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

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

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

04/21/23 38

Gaussian Lowpass Filter

Page 39: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

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

Image size: 512x512SD filter sigma = 8

Image size: 512x512SD filter sigma = 8

04/21/23 39

Gaussian Lowpass Filter

Page 40: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

Filtered ImageFiltered ImageOriginal ImageOriginal Image Filtered Power SpectrumFiltered Power Spectrum

Image size: 512x512SD filter sigma = 8

Image size: 512x512SD filter sigma = 8

04/21/23 40

Gaussian Lowpass Filter

Page 41: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

04/21/23 41

Gaussian Highpass Filter

Page 42: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

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

04/21/23 42

Page 43: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

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

04/21/23 43

Page 44: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

Filtered Image*Filtered Image*Filtered 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

Original ImageOriginal Image

04/21/23 44

Page 45: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

Negative PixelsNegative PixelsPositive PixelsPositive Pixels

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

Image size: 512x512FD notch sigma = 8

Filtered Image*Filtered Image*

04/21/23 45

*signed image: 0 mapped to 128

*signed image: 0 mapped to 128

Page 46: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

Another Gaussian Highpass Filter

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

04/21/23 46

*signed image: 0 mapped to 128

*signed image: 0 mapped to 128

Page 47: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

04/21/23 47

Gaussian Bandpass Filter

Page 48: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

Gaussian Bandpass Filter

04/21/23 48

A bandpass filter is created by (1)subtracting a FD radius 2 lowpass filtered image from a FD radius 1 lowpass filtered image, where 2 < 1, or (2)convolving the image with a mask that is the difference of the two lowpass masks.

FD LP mask with radius 1FD LP mask with radius 1 FD LP mask with radius 2

FD LP mask with radius 2 FD BP mask 1 - 2FD BP mask 1 - 2

- =

Page 49: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

Ideal Bandpass Filter

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

04/21/23 49

*signed image: 0 mapped to 128

*signed image: 0 mapped to 128

Page 50: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

Gaussian Bandpass Filter

04/21/23 50

*signed image: 0 mapped to 128

*signed image: 0 mapped to 128

image LPF radius 1image LPF radius 1 image LPF radius 2

image LPF radius 2 image BPF radii 1, 2*image BPF radii 1, 2*

Page 51: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

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

04/21/23 51

Page 52: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

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

04/21/23 52

Page 53: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

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

04/21/23 53

*signed image: 0 mapped to 128

*signed image: 0 mapped to 128

Page 54: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

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

04/21/23 54

*signed image: 0 mapped to 128

*signed image: 0 mapped to 128

Page 55: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

04/21/23 55

Ideal vs. Gaussian Filters

Page 56: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

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

Ideal Lowpass and Highpass Filters

04/21/23 56

*signed image: 0 mapped to 128

*signed image: 0 mapped to 128

Page 57: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

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

04/21/23 57

*signed image: 0 mapped to 128

*signed image: 0 mapped to 128

Gaussian Lowpass and Highpass Filters

Page 58: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

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

04/21/23 58

*signed image: 0 mapped to 128

*signed image: 0 mapped to 128

Ideal and Gaussian Bandpass Filters

Page 59: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

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

04/21/23 59

*signed image: 0 mapped to 128

*signed image: 0 mapped to 128

Gaussian and Ideal Bandpass Filters

Page 60: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

04/21/23 60

Effects on Power Spectrum

Page 61: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

Power Spectrum and Phase of an Image

original imageoriginal image power spectrumpower spectrum phasephase

04/21/23 61

Page 62: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

Power Spectrum and Phase of a Blurred Image

04/21/23 62

blurred imageblurred image power spectrumpower spectrum phasephase

Page 63: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

Power Spectrum and Phase of an Image

original imageoriginal image power spectrumpower spectrum phasephase

04/21/23 63

Page 64: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

Power Spectrum and Phase of a Sharpened Image

04/21/23 64

power spectrumpower spectrum phasephasesharpened imagesharpened image

Page 65: Image Processing Frequency Filtering Instructor: Juyong Zhang juyong@ustc.edu.cn juyong.

April 21, 2023 65

Thanks!