| Developers' Corner

Gabor filter: What is it for?

Gabor filters which are well known in the realm of time series analyses can also be used in HALCON for 2D image analysis.

Gabor filters which are well known in the realm of time series analyses can also be used in HALCON for 2D image analysis. While in the literature the kernel representation of a Gabor filter dominates, the filter in HALCON is conveniently implemented in the frequency domain.

The standard workflow in HALCON is to convert the image to its frequency domain first and then apply the filter on it. The Gabor filter needs the complex part of the image to work. Then you can construct your Gabor filter or filter bank (e.g., in a double for-loop) with


gen_gabor (ImageFilter, GaborSize, 
Frequency+FrequencyIndex, Bandwidth,Orientation+OrientationIndex, 
'none', 'dc_center', Width, Height)


The filter shape and orientation in the frequency domain can be controlled with the parameters of the operator. The GaborSize determines the size in a frequency band, the Frequency determines the frequency, the Bandwidth tunes the frequency range, and the Orientation is the angle which controls the angular orientation of the filter in the frequency domain.

Images show filters constructed in the frequency domain. If the GaborSize is adjusted from the default value 1.4 (left) to, e.g. 50, a representation of a Gabor kernel in the frequency domain can be constructed (middle) which has the familiar look of the Gabor filters found in literature. Using e.g. two for-loops, a filter bank can be constructed (right). The manifold applications of customized filter banks can also be found in literature.

The filter can then be applied on the frequency image and afterwards the resulting filtered image can be converted back into the image domain:


convol_gabor (ImageFFT, ImageFilter, ImageResultGabor, 
fft_generic (ImageResultGabor, ImageFFTInvert, 'from_freq', 
1, 'sqrt', 'dc_center', 'byte')


Demonstration of an example application of a somewhat arbitrary constructed Gabor filter bank: Extract upper left and lower left edge of a cell of a rotating grid automatically.

From left to right: the original grid, a generically constructed example filter bank (rotated automatically), the convolution with the frequency image and the extracted borders. The extracted borders have been scaled for visibility reasons.
In the upper image sequence the displayed grid is orientated in 0° Orientation. Below the grid is slightly tilted and the filter automatically rotates the result if the rotation angle is given to the filter. That way the filtering can be automated according to the image content.

The angle for the filter rotation was extracted with lines_gauss and a smallest_rectangle2_xld applied on the black spaces in between. It is clearly visible that small parameter tuning can have large effects. Also the effect on the image borders for the filtering is not negligible, as borders are always to beconsidered for filtering operations.

Another example for using the Gabor filter is to differentiate stamp images from text. The inverted image is used in order to filter the transition black to white.

From left to right: original image, FFT, Gabor filter, filtered and scaled result of the filtering. The filter bank is constructed in order to extract the borders of
the stamps.

image extract stamps with gabor filter

Using some region selection and processing techniques and applying regiongrowing_mean afterwards, it is possible to construct a robust stamp extraction.

Conclusion: HALCON offers the powerful Gabor filter for a wide range of applications. We showed how the Gabor filter can be used to automatically follow the angle of a periodic shape of the image and extract features with a filter bank. Furthermore we differentiated images from text on a stamp catalogue.
The manifold applications of this filter include document image processing: Gabor features can be used for identifying the script of a word in a multilingual document or to differentiate text from images on documents. Gabor filter banks are also used for texture and pattern analysis and much more.