Date post: | 15-Jan-2016 |
Category: |
Documents |
Upload: | immanuel-inglett |
View: | 230 times |
Download: | 0 times |
Image Processing
Frequency Filtering
Instructor: Juyong [email protected]
http://staff.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
Convolution via Fourier Transform
Image & Mask Transforms
Pixel-wise Product
Inverse Transform
04/21/23 3
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
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
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
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
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
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
04/21/23 10
Ideal Lowpass Filter
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
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.
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
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
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
04/21/23 16
Ideal Highpass Filter
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
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
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
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
04/21/23 21
Ideal Bandpass Filter
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
- =
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*
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
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
04/21/23 26
The Optimal Filter
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
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
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
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
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
One-Dimensional Gaussian
22 2)(
21)(
xexg
04/21/23 32
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
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
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
04/21/23 36
Gaussian Lowpass Filter
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
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
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
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
04/21/23 41
Gaussian Highpass Filter
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
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
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
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
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
04/21/23 47
Gaussian Bandpass Filter
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
- =
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
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*
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
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
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
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
04/21/23 55
Ideal vs. Gaussian Filters
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
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
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
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
04/21/23 60
Effects on Power Spectrum
Power Spectrum and Phase of an Image
original imageoriginal image power spectrumpower spectrum phasephase
04/21/23 61
Power Spectrum and Phase of a Blurred Image
04/21/23 62
blurred imageblurred image power spectrumpower spectrum phasephase
Power Spectrum and Phase of an Image
original imageoriginal image power spectrumpower spectrum phasephase
04/21/23 63
Power Spectrum and Phase of a Sharpened Image
04/21/23 64
power spectrumpower spectrum phasephasesharpened imagesharpened image
April 21, 2023 65
Thanks!