Beruflich Dokumente
Kultur Dokumente
Overview Common Fourier Transforms Ideal Lowpass Butterworth Lowpass Gaussian Lowpass Ideal Highpass Butterworth Highpass Gaussian Highpass Conclusions
Overview
For linear frequency domain filters, we point multiply 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) }
Overview
By varying the filter H(u,v) we can implement a wide variety of image processing operations Lowpass filters smooth an image by keeping only the low frequencies (the big features) Highpass filters sharpen an image by keeping only the high frequencies (the small features)
Ideal Lowpass
An ideal lowpass filter keeps low frequencies in an image and discards the high frequencies This is accomplished by multiplying F(u,v) by a filter H(u,v) that equals 1 in desired range and 0 outside this range
Ideal Lowpass
H(u,v) is a disk of radius D0 centered at origin
Ideal Lowpass
Ideal Lowpass
To understand the ringing artifacts above, we need to consider what convolution mask corresponds to the ideal lowpass filter
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); } // Perform inverse FFT FastIFT(); } // Apply filter if (dist > freq * freq) { Re.Data2D[v][u] = 0; Im.Data2D[v][u] = 0; }
Butterworth Lowpass
A Butterworth lowpass keeps frequencies inside radius D0 and discards values outside It introduces a gradual transition from 1 to 0 to reduce ringing artifacts
Butterworth Lowpass
A family of filters can be created by varying n to increase or decrease the slope at D0
Butterworth Lowpass
Butterworth Lowpass
Ringing artifact increases as n increases
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); // Perform inverse FFT FastIFT(); } // Apply filter float filter = 1 / (1 + pow(dist / (freq*freq), power)); Re.Data2D[v][u] *= filter; Im.Data2D[v][u] *= filter;
Gaussian Lowpass
A Gaussian lowpass filter has the most natural and well behaved filter shape (blurring with a Gaussian filter corresponds to heat diffusion)
Gaussian Lowpass
A family of filters can be created by varying the standard deviation D0 to increase or decrease filter width
Gaussian Lowpass
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); // Perform inverse FFT FastIFT(); } // Apply filter float filter = exp(dist / (-2*freq*freq)); Re.Data2D[v][u] *= filter; Im.Data2D[v][u] *= filter;
Ideal Highpass
An ideal highpass filter keeps the high frequencies and discards the low frequencies This is accomplished by multiplying F(u,v) by a filter H(u,v) that equals 1 in desired range and 0 outside this range
Ideal Highpass
H(u,v) is a disk of radius D0 centered at origin
Ideal Highpass
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); } // Perform inverse FFT FastIFT(); } // Apply filter if (dist < freq * freq) { Re.Data2D[v][u] = 0; Im.Data2D[v][u] = 0; }
Butterworth Highpass
A Butterworth highpass keeps frequencies outside radius D0 and discards values inside It has a gradual transition from 0 to 1 to reduce ringing artifacts
Butterworth Highpass
A family of filters can be created by varying n to increase or decrease the slope at D0
Butterworth Highpass
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); // Perform inverse FFT FastIFT(); } // Apply filter float filter = 1 / (1 + pow(dist / (freq*freq), power)); Re.Data2D[v][u] *= (1-filter); Im.Data2D[v][u] *= (1-filter);
Gaussian Highpass
The Gaussian highpass filter discards low frequencies and keeps high frequencies
Since Gaussian HP = (1 Gaussian LP) it does not introduce any ringing artifacts
Gaussian Highpass
A family of filters can be created by varying the standard deviation D0 to increase or decrease filter width
Gaussian Highpass
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); // Perform inverse FFT FastIFT(); } // Apply filter float filter = exp(dist / (-2*freq*freq)); Re.Data2D[v][u] *= (1-filter); Im.Data2D[v][u] *= (1-filter);
Conclusion
In this section we have seen three types of lowpass filters and three types of highpass filters In the next section we will see that frequency filtering can do much more to an image