Image Processing Frequency Filtering Instructor: Juyong Zhang
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 * = convolution · = multiplication 5/5/20152
Convolution via Fourier Transform Image & Mask Transforms Pixel-wise Product Inverse Transform 5/5/20153
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. The mask is usually 1-band 5/5/20154
Coordinate Origin of the FFT Center = (floor(R/2)+1, floor(C/2)+1) Center = (floor(R/2)+1, floor(C/2)+1) Even Odd Image OriginWeight Matrix OriginImage OriginWeight Matrix Origin After FFT shiftAfter IFFT shiftAfter FFT shiftAfter IFFT shift 5/5/20155
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 /5/20156
Blurring: Averaging / Lowpass Filtering Blurring results from: l 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. l 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/ (u 2 +v 2 ). The values of the output image are all non-negative. 5/5/20157
Sharpening: Differencing / Highpass Filtering Sharpening results from adding to the image, a copy of itself that has been: l 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. l Highpass filtered in the frequency domain: – High frequencies are enhanced or amplified. – Individual frequency components are multiplied by an increasing function of such as = (u 2 +v 2 ), where is a constant. The values of the output image positive & negative. 5/5/20158
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 * = convolution · = multiplication Recall: 5/5/20159
10 Ideal Lowpass Filter
Fourier Domain Rep. Spatial Representation Central Profile Image size: 512x512 FD filter radius: 16 Image size: 512x512 FD filter radius: 16 Multiply by this, or … … convolve by this 5/5/201511
Spatial Representation Central Profile Ideal Lowpass Filter Image size: 512x512 FD filter radius: 8 Image size: 512x512 FD filter radius: 8 Multiply by this, or … … convolve by this 5/5/ Fourier Domain Rep.
Power Spectrum and Phase of an Image Consider the image below: Original Image Power Spectrum Phase 5/5/201513
Ideal LPF in FD Original Image Power Spectrum Ideal Lowpass Filter Image size: 512x512 FD filter radius: 16 Image size: 512x512 FD filter radius: 16 5/5/201514
Filtered Power Spectrum Ideal Lowpass Filter Image size: 512x512 FD filter radius: 16 Image size: 512x512 FD filter radius: 16 5/5/ Filtered Image Original Image
5/5/ Ideal Highpass Filter
Fourier Domain Rep. Spatial Representation Central Profile Image size: 512x512 FD notch radius: 16 Image size: 512x512 FD notch radius: 16 Multiply by this, or … … convolve by this 5/5/201517
Ideal HPF in FD Original Image Power Spectrum Ideal Highpass Filter Image size: 512x512 FD notch radius: 16 Image size: 512x512 FD notch radius: 16 5/5/201518
Original Image Filtered Image* Filtered Power Spectrum Ideal Highpass Filter Image size: 512x512 FD notch radius: 16 Image size: 512x512 FD notch radius: 16 5/5/ *signed image: 0 mapped to 128
Filtered Image* Positive Pixels Negative Pixels Ideal Highpass Filter Image size: 512x512 FD notch radius: 16 Image size: 512x512 FD notch radius: 16 *signed image: 0 mapped to 128 5/5/201520
5/5/ Ideal Bandpass Filter
5/5/ 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 1 FD LP mask with radius 2 FD BP mask 1 - 2 - =
Ideal Bandpass Filter 5/5/ *signed image: 0 mapped to 128 image LPF radius 1 image LPF radius 2 image BPF radii 1, 2 *
Ideal Bandpass Filter original image* filter power spectrum filtered image 5/5/ *signed image: 0 mapped to 128
A Different Ideal Bandpass Filter original image filter power spectrum filtered image* 5/5/ *signed image: 0 mapped to 128
5/5/ The Optimal Filter
The Uncertainty Relation FT spacefrequency A small object in space has a large frequency extent and vice-versa. 5/5/ spacefrequency FT
The Uncertainty Relation 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. 5/5/ space frequency small extent large extent IFT space frequency large extent small extent large extent IFT
Ideal Filters Do Not Produce Ideal Results A sharp cutoff in the frequency domain… …causes ringing in the spatial domain. IFT 5/5/201529
Ideal Filters Do Not Produce Ideal Results Ideal LPF Blurring the image above with an ideal lowpass filter… …distorts the results with ringing or ghosting. 5/5/201530
Optimal Filter: The Gaussian The Gaussian filter optimizes the uncertainty relation. It provides the sharpest cutoff with the least ringing. IFT 5/5/201531
One-Dimensional Gaussian 5/5/201532
Two-Dimensional Gaussian If and are different for r & c … …or if and are the same for r & c. r c R = 512, C = 512 = 257, = 64 5/5/201533
Gaussian LPF With a gaussian lowpass filter, the image above … … is blurred without ringing or ghosting. Optimal Filter: The Gaussian 5/5/201534
Compare with an “Ideal” LPF Ideal LPF Blurring the image above with an ideal lowpass filter… …distorts the results with ringing or ghosting. 5/5/201535
5/5/ Gaussian Lowpass Filter
Fourier Domain Rep. Spatial Representation Central Profile Image size: 512x512 SD filter sigma = 8 Image size: 512x512 SD filter sigma = 8 Gaussian Lowpass Filter Multiply by this, or … … convolve by this 5/5/201537
Fourier Domain Rep. Spatial Representation Central Profile Image size: 512x512 SD filter sigma = 2 Image size: 512x512 SD filter sigma = 2 Multiply by this, or … … convolve by this 5/5/ Gaussian Lowpass Filter
Gaussian LPF in FD Original Image Power Spectrum Image size: 512x512 SD filter sigma = 8 Image size: 512x512 SD filter sigma = 8 5/5/ Gaussian Lowpass Filter
Filtered Image Original Image Filtered Power Spectrum Image size: 512x512 SD filter sigma = 8 Image size: 512x512 SD filter sigma = 8 5/5/ Gaussian Lowpass Filter
5/5/ Gaussian Highpass Filter
Fourier Domain Rep. Spatial Representation Central Profile Image size: 512x512 FD notch sigma = 8 Image size: 512x512 FD notch sigma = 8 Multiply by this, or … … convolve by this 5/5/201542
Gaussian HPF in FD Original Image Power Spectrum Gaussian Highpass Filter Image size: 512x512 FD notch sigma = 8 Image size: 512x512 FD notch sigma = 8 5/5/201543
Filtered Image* Filtered Power Spectrum Gaussian Highpass Filter Image size: 512x512 FD notch sigma = 8 Image size: 512x512 FD notch sigma = 8 *signed image: 0 mapped to 128 Original Image 5/5/201544
Negative Pixels Positive Pixels Gaussian Highpass Filter Image size: 512x512 FD notch sigma = 8 Image size: 512x512 FD notch sigma = 8 Filtered Image* 5/5/ *signed image: 0 mapped to 128
Another Gaussian Highpass Filter original image filter power spectrum filtered image * 5/5/ *signed image: 0 mapped to 128
5/5/ Gaussian Bandpass Filter
5/5/ 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 1 FD LP mask with radius 2 FD BP mask 1 - 2 - =
Ideal Bandpass Filter original image filter power spectrum filtered image* 5/5/ *signed image: 0 mapped to 128
Gaussian Bandpass Filter 5/5/ *signed image: 0 mapped to 128 image LPF radius 1 image LPF radius 2 image BPF radii 1, 2 *
Gaussian Bandpass Filter Fourier Domain Rep. Spatial Representation Central Profile Image size: 512x512 sigma = 2 - sigma = 8 Image size: 512x512 sigma = 2 - sigma = 8 5/5/201551
Gaussian BPF in FD Original Image Power Spectrum Gaussian Bandpass Filter Image size: 512x512 sigma = 2 - sigma = 8 Image size: 512x512 sigma = 2 - sigma = 8 5/5/201552
Original Image Filtered Image * Filtered Power Spectrum Gaussian Bandpass Filter Image size: 512x512 sigma = 2 - sigma = 8 Image size: 512x512 sigma = 2 - sigma = 8 5/5/ *signed image: 0 mapped to 128
Filtered Image* Negative Pixels Filtered Image Positive Pixels Gaussian Bandpass Filter Image size: 512x512 sigma = 2 - sigma = 8 Image size: 512x512 sigma = 2 - sigma = 8 5/5/ *signed image: 0 mapped to 128
5/5/ Ideal vs. Gaussian Filters
Original Image Ideal HPF * Ideal LPF Ideal Lowpass and Highpass Filters 5/5/ *signed image: 0 mapped to 128
Original Image Gaussian HPF* Gaussian LPF 5/5/ *signed image: 0 mapped to 128 Gaussian Lowpass and Highpass Filters
Original Image Gaussian BPF * Ideal BPF * 5/5/ *signed image: 0 mapped to 128 Ideal and Gaussian Bandpass Filters
Original Image Ideal BPF* Gaussian BPF* 5/5/ *signed image: 0 mapped to 128 Gaussian and Ideal Bandpass Filters
5/5/ Effects on Power Spectrum
Power Spectrum and Phase of an Image original image power spectrum phase 5/5/201561
Power Spectrum and Phase of a Blurred Image 5/5/ blurred image power spectrum phase
Power Spectrum and Phase of an Image original image power spectrum phase 5/5/201563
Power Spectrum and Phase of a Sharpened Image 5/5/ power spectrum phase sharpened image
5 May Thanks!