Gabor filter feature extraction principle explanation and c++ implementation


Gabor filter

In 1946, Dennis Gabor proposed the famous "window" Fourier transform (also called short-time Fourier transform, STFT) in the article "Theory of communication", namely the Gabor transform.
In the image processing neighborhood, Gabor wavelet is a very effective texture representation method.
In the spatial domain, a 2-dimensional Gabor filter is a product of a sine plane wave and a Gaussian kernel function:
insert image description here
where s(x, y) is a complex sinusoidal signal, called the carrier, and Wr(x, y) is a two-dimensional signal Gaussian type function, called the envelope.

complex sinusoidal carrier

The definition of the complex sine function is as follows:
insert image description here
where (u0, v0), P defines the spatial frequency and phase of the sine signal, respectively. This sine function can be imagined as two independent real functions, which are respectively represented as the real part and the imaginary part of the complex function:
insert image description here
they can be expressed intuitively as: the
insert image description here
parameters u0 and v0 define the spatial frequency of the sinusoidal signal in the Cartesian coordinate system. This spatial frequency can also be expressed in polar coordinates as magnitude F0 and direction ω0:
insert image description here
Then:
insert image description here
In this notation, the complex sine function is:

insert image description here
make
insert image description here

In general, the complex sine function is expressed as:`
insert image description here

Gaussian filter

The two-dimensional Gaussian function can be expressed as:
insert image description here

Then multiply the complex sine function and the Gaussian filter, and the complex form of the gabor filter can be expressed as:
insert image description here
The following is a more intuitive look at the effect of multiplying the two:
insert image description here
(a) 2D sine surface, (b) Gaussian kernel, © corresponding Gabor filter.

Parameter explanation

The description of each parameter in the above formula:

Wavelength (λ): The unit is pixel, usually greater than or equal to 2. But not greater than one-fifth of the input image size.

direction (theta): the direction of the parallel stripes, it takes the value from 0 to 360 degrees

Phase offset (φ): The value range is -180 degrees to 180 degrees. Among them, 0he180 degrees correspond to centrosymmetric functions, respectively, while -90 degrees and 90 degrees correspond to anti-symmetric functions.

Aspect ratio (γ): The aspect ratio, which determines the shape of the Gabor function. When γ=1, the shape is round. When γ < 1, the shape elongates with the direction of the parallel stripes.

Bandwidth (b): The half-response spatial frequency bandwidth b of a Gabor filter is related to the ratio of σ/λ, where σ represents the standard deviation of the Gaussian factor of the Gabor function, as follows:
insert image description here

The comparison chart of the gabor kernel function under different parameters is given below: size 512*512

The wavelength λ resolution is: 8, 16, 32 insert image description here
directions (θ) are: 0, 45, 90 degrees, respectively The
insert image description here
phase offset (φ) is 0, 90, 180 degrees, respectively
insert image description here

The aspect ratio (γ) is: 0.5, 1, 2

insert image description here

Bandwidth (b) is 0.5, 1, 2 respectively
insert image description here

Gabor filter kernel implementation

cv::Mat getGaborKernel(int ks, double sig, double th, double lm, double ps)
{
    
    
    int hks = (ks-1)/2;
    double theta = th*CV_PI/180;
    double psi = ps*CV_PI/180;
    double del = 2.0/(ks-1);
    double lmbd = lm;
    double sigma = sig/ks;
    double x_theta;
    double y_theta;
    cv::Mat kernel(ks,ks, CV_32F);
    for (int y=-hks; y<=hks; y++)
    {
    
    
        for (int x=-hks; x<=hks; x++)
        {
    
    
            x_theta = x*del*cos(theta)+y*del*sin(theta);
            y_theta = -x*del*sin(theta)+y*del*cos(theta);
            kernel.at<float>(hks+y,hks+x) = (float)exp(-0.5*(pow(x_theta,2)+pow(y_theta,2))/pow(sigma,2))* cos(2*CV_PI*x_theta/lmbd + psi);
        }
    }
    return kernel;
}

Effect:

Please add image description

参考文献:
1、Gabor filter visualization
2、1-Petkov_Gabor_functions2011-Lecture notes
3、Texture features for browsing and retrieval of image data

Guess you like

Origin blog.csdn.net/weixin_44901043/article/details/123595172
Recommended