Generating filter directly in the frequency domain

Before addition of said frequency domain filter is obtained from the spatial filter, the filter can also be generated directly from the frequency domain, the filter is a predetermined distance from the filter center point to different functions. Can create a grid array for implementing the frequency of the filter, the most important is the need to calculate the distance from any point in the rectangle function of the frequency of a designated point, an FFT (Fast Fourier) transformation algorithm is assumed that the origin is located at the frequency of the rectangular the top left corner, it is necessary translated to the origin of the center frequency of the square, with fftshift. Grid Array follows:

% (Frequency domain filter function) and the distance calculation provides the required array grid 
function [the U-, V] = dftuv (M, N) 
U = 0: (M-. 1); 
V = 0: (. 1-N ); 
IDX = Find (U> M / 2); 
U (IDX) = U (IDX) -M; 
IDY = Find (V> N / 2); 
V (IDY) = V (IDY) - N; 
[V , the U-] meshgrid now = (V, U); 
End

 

A low-pass (smoothing) filter in the frequency domain

Common low-pass filter in the frequency domain There are three ideal low-pass filter (ILPF), Butterworth low pass filter (BLPF), Gaussian low-pass filter (GLPF).

1) over the low-pass filter transfer function is as follows:

Where, D0 is a positive number, D (u, v) is a point (u, v) from the center of the filter to meet the D (u, v) = D0 locus of points for a circle. If an image is multiplied with the Fourier transform of the filter, we will see a cut over the filter (multiplied by 0) of all F (u, v) components other than the circle, the circle and the circle while retaining All components within the constant (multiplied by 1).

It can be used before the filter mesh is displayed:

             

2) n-order Butterworth low-pass filter, at a distance D0 at the center of the filter having a cutoff frequency, the transfer function is:

Ideal low pass filter is different, the transfer function of the Butterworth low pass filter is not a sharp discontinuity at the points D0, to a filter having a smooth transfer function, the cutoff frequency is typically defined trajectory in H (u , v) reducing a designated point for the ratio of the maximum value. The filter can also be displayed with mesh:

                  

3) a Gaussian low-pass filter transfer function is as follows:

Wherein, as the standard deviation. The mesh filter can be displayed

                   

Examples 4) low-pass filter

Filtering a 500 * 500 image with a Gaussian low-pass filter effect is as follows:

The example code below:

% Gaussian filtered low-pass filter 
f = imread ( 'G: \ Digital Image Processing (Gonzalez) \ DIP3E_CH04_Original_Images \ DIP3E_Original_Images_CH04 \ Fig0441 (A) (characters_test_pattern) .tif'); 
the subplot (221); imshow ( f); title ( 'original') 
F = im2double (F); 
% [F, revertclass] = toFloat (F); 
the PQ = paddedsize (size (F)); 
[the U-, V] = dftuv (the PQ (. 1 ), the PQ (2)); 
D = hypot (the U-, V); 
D0 = 0.05 * the PQ (2); 
F. = FFT2 (F, the PQ (. 1), the PQ (2)); 
H = exp (- (D . ^ 2) / (2 * (D0 ^ 2))); 
G = dftfilt (F, H); 
G = im2uint8 (G); 
% G = revertclass (G); 
the subplot (222); imshow (fftshift (H )); title ( 'Gaussian low pass filter image');% image display filter 
subplot (223); imshow (log (1 + abs (fftshift (F))), []); title ( ' filter spectrum '); 
the subplot (224); imshow (G); title (' post-filter image ')

 Different transfer functions of various filters, the filtering process is the same, and therefore, these several filters can be encapsulated into a function as follows:

% Frequency domain low-pass filtering function to generate the transfer function of several low-pass filter 
function [H, D] = the lpfilter (type, M, N, D0, n-) 
[the U-, V] = dftuv (M, N); 
= sqrt D (+ V. U. The ^ 2 ^ 2); 
Switch type 
    Case 'Ideal' 
        H = Double (D <= D0); 
    Case 'BTW' 
        IF the nargin ==. 4 
            n-=. 1; 
        End 
        H = 1. / (1+ (D./D0) ^ (n-2 *).); 
    Case 'Gaussian' 
        H = exp (- (D. ^ 2) ./ (2 * (D0 ^ 2))); 
    otherwise 
        error ( ' type filter Unkown '); 
        
End
        
        

  

Guess you like

Origin www.cnblogs.com/libai123456/p/11441075.html