Article directory
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:
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:
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:
they can be expressed intuitively as: the
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:
Then:
In this notation, the complex sine function is:
make
In general, the complex sine function is expressed as:`
Gaussian filter
The two-dimensional Gaussian function can be expressed as:
Then multiply the complex sine function and the Gaussian filter, and the complex form of the gabor filter can be expressed as:
The following is a more intuitive look at the effect of multiplying the two:
(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:
The comparison chart of the gabor kernel function under different parameters is given below: size 512*512
The wavelength λ resolution is: 8, 16, 32
directions (θ) are: 0, 45, 90 degrees, respectively The
phase offset (φ) is 0, 90, 180 degrees, respectively
The aspect ratio (γ) is: 0.5, 1, 2
Bandwidth (b) is 0.5, 1, 2 respectively
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:
参考文献:
1、Gabor filter visualization
2、1-Petkov_Gabor_functions2011-Lecture notes
3、Texture features for browsing and retrieval of image data