Upload
lamaa-lama
View
221
Download
0
Embed Size (px)
Citation preview
8/2/2019 ch04b
1/36
Ch4 Frequency Filtering 1
Overview Common Fourier Transforms Ideal Lowpass Butterworth Lowpass Gaussian Lowpass Ideal Highpass Butterworth Highpass Gaussian Highpass Conclusions
8/2/2019 ch04b
2/36
Overview
Forlinearfrequency domain filters, we pointmultiply the FT of our image by a filter H(u,v)and do an IFT to obtain the output image:
F(u,v) = FT{ f(x,y) }
G(u,v) = F(u,v).H(u,v)
g(x,y) = IFT{ G(,u,v) }
8/2/2019 ch04b
3/36
Overview
By varying the filter H(u,v) we can implementa wide variety of image processing operations
Lowpass filterssmooth an image by keepingonly the low frequencies (the big features)
Highpass filterssharpen an image by keepingonly the high frequencies (the small features)
8/2/2019 ch04b
4/36
Common Fourier Transforms
8/2/2019 ch04b
5/36
Common Fourier Transforms
8/2/2019 ch04b
6/36
Common Fourier Transforms
8/2/2019 ch04b
7/36
Common Fourier Transforms
8/2/2019 ch04b
8/36
Common Fourier Transforms
8/2/2019 ch04b
9/36
Common Fourier Transforms
8/2/2019 ch04b
10/36
Ideal Lowpass
An ideal lowpass filter keeps low frequenciesin an image and discards the high frequencies
This is accomplished by multiplying F(u,v) bya filter H(u,v) that equals 1 in desired rangeand 0 outside this range
8/2/2019 ch04b
11/36
Ideal Lowpass
H(u,v) is a disk of radius D0 centered at origin
8/2/2019 ch04b
12/36
Ideal Lowpass
Filter radii: 10, 30, 60, 160, 460
8/2/2019 ch04b
13/36
Ideal Lowpass
To understand the ringing artifacts above, weneed to consider what convolution maskcorresponds to the ideal lowpass filter
8/2/2019 ch04b
14/36
Ideal Lowpass
void im_complex::IdealLP
(float freq)
{
// Perform FFT
FastFT();
// Perform filtering
int ydim = Re.Ydim;
int xdim = Re.Xdim;
for (int v = 0; v < ydim; v++)
for (int u = 0; u < xdim; u++)
{ // Calculate distance to origin
int dv = (v < ydim / 2) ? v : v - ydim;
int du = (u < xdim / 2) ? u : u - xdim;
float dist = (float)(dv * dv + du * du);
// Apply filter
if (dist > freq * freq)
{
Re.Data2D[v][u] = 0;
Im.Data2D[v][u] = 0;
}}
// Perform inverse FFT
FastIFT();
}
8/2/2019 ch04b
15/36
Butterworth Lowpass
A Butterworth lowpass keeps frequenciesinside radius D0 and discards values outside
It introduces a gradual transition from 1 to 0 toreduce ringing artifacts
8/2/2019 ch04b
16/36
Butterworth Lowpass
A family of filters can be created by varying nto increase or decrease the slope at D0
8/2/2019 ch04b
17/36
Butterworth Lowpass
Cutoff frequencies: 10, 30, 60, 160, 460
8/2/2019 ch04b
18/36
Butterworth Lowpass
Ringing artifact increases as n increases
8/2/2019 ch04b
19/36
Butterworth Lowpass
void im_complex::ButterworthLP
(float freq, float power)
{
// Perform FFT
FastFT();
// Perform filtering
int ydim = Re.Ydim;
int xdim = Re.Xdim;
for (int v = 0; v < ydim; v++)
for (int u = 0; u < xdim; u++)
{
// Calculate distance to origin
int dv = (v < ydim / 2) ? v : v - ydim;
int du = (u < xdim / 2) ? u : u - xdim;
float dist = (float)(dv * dv + du * du);
// Apply filter
float filter = 1 / (1 +
pow(dist / (freq*freq), power));
Re.Data2D[v][u] *= filter;
Im.Data2D[v][u] *= filter;
}
// Perform inverse FFT
FastIFT();
}
8/2/2019 ch04b
20/36
Gaussian Lowpass
A Gaussian lowpass filter has the most naturaland well behaved filter shape (blurring with a
Gaussian filter corresponds to heat diffusion)
The FT of a Gaussian function is a Gaussianso no ringing artifacts are introduced
8/2/2019 ch04b
21/36
Gaussian Lowpass
A family of filters can be created by varyingthe standard deviation D0 to increase ordecrease filter width
8/2/2019 ch04b
22/36
Gaussian Lowpass
Cutoff frequencies: 10, 30, 60, 160, 460
8/2/2019 ch04b
23/36
Gaussian Lowpass
void im_complex::GaussLP
(float freq)
{
// Perform FFT
FastFT();
// Perform filtering
int ydim = Re.Ydim;
int xdim = Re.Xdim;
for (int v = 0; v < ydim; v++)
for (int u = 0; u < xdim; u++)
{
// Calculate distance to origin
int dv = (v < ydim / 2) ? v : v - ydim;
int du = (u < xdim / 2) ? u : u - xdim;
float dist = (float)(dv * dv + du * du);
// Apply filter
float filter =
exp(dist / (-2*freq*freq));
Re.Data2D[v][u] *= filter;
Im.Data2D[v][u] *= filter;
}
// Perform inverse FFT
FastIFT();
}
8/2/2019 ch04b
24/36
Ideal Highpass
An ideal highpass filter keeps the highfrequencies and discards the low frequencies
This is accomplished by multiplying F(u,v) bya filter H(u,v) that equals 1 in desired rangeand 0 outside this range
8/2/2019 ch04b
25/36
Ideal Highpass
H(u,v) is a disk of radius D0 centered at origin
8/2/2019 ch04b
26/36
Ideal Highpass
Cutoff frequencies: 30, 60, 160
8/2/2019 ch04b
27/36
Ideal Highpass
void im_complex::IdealHP
(float freq)
{
// Perform FFT
FastFT();
// Perform filtering
int ydim = Re.Ydim;
int xdim = Re.Xdim;
for (int v = 0; v < ydim; v++)
for (int u = 0; u < xdim; u++)
{
// Calculate distance to origin
int dv = (v < ydim / 2) ? v : v - ydim;
int du = (u < xdim / 2) ? u : u - xdim;
float dist = (float)(dv * dv + du * du);
// Apply filter
if (dist < freq * freq)
{
Re.Data2D[v][u] = 0;
Im.Data2D[v][u] = 0;
}}
// Perform inverse FFT
FastIFT();
}
8/2/2019 ch04b
28/36
Butterworth Highpass
A Butterworth highpass keeps frequenciesoutside radius D0 and discards values inside
It has a gradual transition from 0 to 1 toreduce ringing artifacts
8/2/2019 ch04b
29/36
Butterworth Highpass
A family of filters can be created by varying nto increase or decrease the slope at D0
8/2/2019 ch04b
30/36
8/2/2019 ch04b
31/36
Butterworth Highpass
void im_complex::ButterworthHP
(float freq, float power)
{
// Perform FFT
FastFT();
// Perform filtering
int ydim = Re.Ydim;
int xdim = Re.Xdim;
for (int v = 0; v < ydim; v++)
for (int u = 0; u < xdim; u++)
{
// Calculate distance to origin
int dv = (v < ydim / 2) ? v : v - ydim;
int du = (u < xdim / 2) ? u : u - xdim;
float dist = (float)(dv * dv + du * du);
// Apply filter
float filter = 1 / (1 +
pow(dist / (freq*freq), power));
Re.Data2D[v][u] *= (1-filter);
Im.Data2D[v][u] *= (1-filter);
}
// Perform inverse FFT
FastIFT();
}
8/2/2019 ch04b
32/36
Gaussian Highpass
The Gaussian highpass filter discards lowfrequencies and keeps high frequencies
Since Gaussian HP = (1 Gaussian LP) itdoes not introduce any ringing artifacts
8/2/2019 ch04b
33/36
Gaussian Highpass
A family of filters can be created by varyingthe standard deviation D0 to increase ordecrease filter width
8/2/2019 ch04b
34/36
Gaussian Highpass
Cutoff frequencies: 30, 60, 160
8/2/2019 ch04b
35/36
Gaussian Highpass
void im_complex::GaussHP
(float freq)
{
// Perform FFT
FastFT();
// Perform filtering
int ydim = Re.Ydim;
int xdim = Re.Xdim;
for (int v = 0; v < ydim; v++)
for (int u = 0; u < xdim; u++)
{
// Calculate distance to origin
int dv = (v < ydim / 2) ? v : v - ydim;
int du = (u < xdim / 2) ? u : u - xdim;
float dist = (float)(dv * dv + du * du);
// Apply filter
float filter =
exp(dist / (-2*freq*freq));
Re.Data2D[v][u] *= (1-filter);
Im.Data2D[v][u] *= (1-filter);
}
// Perform inverse FFT
FastIFT();
}
8/2/2019 ch04b
36/36
Conclusion
In this section we have seen three types oflowpass filters and three types of highpassfilters
In the next section we will see that frequencyfiltering can do much more to an image