Gabor filter bank¶
| Fact | Value |
|---|---|
| Also called | Gabor wavelet bank |
| Status | Implemented and tested |
| Family | Texture, corners, blobs and features |
| Engine | Browser |
| Type | Nonlinear, spatial, filter bank and maximum |
| Output | Image |
| Operator shown as | algorithm (exact) |
| Support radius | the largest Gabor kernel half width in the bank |
| Code | web/src/core/filters/features/gabor-bank.ts, gaborBankFilter |
| Operator code | web/src/core/filters/features/gabor-bank.ts, gaborBank |
| Channels | Brightness only, RGB |
Overview¶
A Gabor filter bank runs many Gabor filters at once, at several wavelengths and several orientations, and combines their responses into one value per pixel. The largest or the mean magnitude measures how much texture there is, at any of the scales and directions in the bank. The angle of the strongest filter shows the local direction of stripes and edges.
How it works¶
- List the wavelengths, from the smallest one up by the scale factor, and the angles, evenly spread over 180 degrees.
- Run a Gabor filter for every pair of a wavelength and an angle, and take its magnitude.
- Keep the largest magnitude, the mean, or the angle of the strongest filter.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(\lambda_0\): The smallest wavelength
- \(f\): The scale factor
- \(n\): The number of orientations
- \(b\): The bandwidth in octaves
- \(g_{s,k}\): The Gabor kernel of scale s and orientation k
Scale s has the wavelength lambda_0 f^s, and orientation k the angle 180 k / n. Sigma follows from the bandwidth b in octaves, as in scikit-image. Each g_{s,k} is a Gabor kernel, and M is the largest magnitude. The mean output averages the magnitudes instead. The angle output gives theta_k of the strongest filter. When several filters are within a relative 1e-9 of the largest magnitude, the first in the order of the bank wins. This makes exact ties, such as theta and 180 - theta next to a mirrored border, independent of rounding.
One Gabor filter sees one scale and one direction. Texture rarely has a single scale or direction, so banks sample both. Scales usually grow by a constant factor, often 2, which is one octave. Sigma is tied to the wavelength through the bandwidth b, in octaves. Sigma equals the wavelength times (1 / pi) sqrt(ln 2 / 2) (2^b + 1) / (2^b - 1). The same relation sets sigma in scikit-image. Kruizinga and Petkov, and Grigorescu and colleagues, compare texture features built on such banks.
Kernel or operator¶
The Inspector lists the wavelengths and angles of the bank and the rule that combines them. Each kernel is a Gabor kernel, shown on the Gabor filter page.
Algorithm¶
- List the wavelengths and angles of the bank, and sigma for each wavelength.
- Take the FFT of the image, extended by the largest kernel half width.
- Correlate with every complex Gabor kernel through that spectrum, and take the magnitude.
- Combine the magnitudes into the largest, the mean, or the angle of the strongest.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Smallest wavelength wavelength |
4 | 2 to 32 px | The wavelength of the finest scale. |
Scales scales |
3 | 1 to 5 | How many wavelengths the bank holds. |
Scale factor factor |
2 | 1.2 to 3 | Each scale has this many times the wavelength of the one before. |
Orientations orientations |
4 | 1 to 12 | How many angles the bank holds, spread evenly from 0 to 180 degrees. |
Bandwidth bandwidth |
1 | 0.5 to 3 octaves | The frequency bandwidth of each filter. It sets sigma from the wavelength. |
Aspect ratio aspect |
1 | 0.2 to 5 | Sigma along the wave divided by sigma along the stripes, as in the Gabor filter. |
Output output |
Largest magnitude | Largest magnitude, Mean magnitude, Angle of the strongest filter | How the responses of the bank become one value per pixel. |
Output mapping outputMapping |
Stretch to full range | Absolute value, Offset by 128, Stretch to full range, Clip to 0 to 255 | How signed results, such as gradients, become 8-bit pixel values. |
Border mode border |
Reflect 101 (default) | Reflect 101 (default), Reflect, Replicate, Constant (zero), Wrap | How pixels outside the image are filled when the window reaches past the edge. |
Channels channelScope |
Brightness only | RGB, Brightness only | Which part of the color image the filter changes. |
Implementation¶
gaborBank in web/src/core/filters/features/gabor-bank.ts lists the filters. The filter takes the FFT of the extended tile once with planeSpectrum and correlates every complex Gabor kernel through it. For the angle output, the first filter within a relative 1e-9 of the largest magnitude wins, so exact ties next to a mirrored border do not depend on rounding. The filter runs in the browser engine, in Web Workers, through the shared filter framework in web/src/core/filters/run.ts, which handles the border mode, the channel scope, alpha and the output mapping. By default it works on luma.
Worked example¶
| Scale | Wavelength | Sigma | Kernel size at angle 0 |
|---|---|---|---|
| 0 | 4 | 2.249 | 15 x 15 |
| 1 | 8 | 4.497 | 29 x 29 |
| 2 | 16 | 8.995 | 55 x 55 |
The default bank: smallest wavelength 4, 3 scales with factor 2, 4 orientations, bandwidth 1 octave and aspect ratio 1. For a bandwidth of 1 octave, sigma is (1 / pi) sqrt(ln 2 / 2) (2 + 1) / (2 - 1) = 0.5622 times the wavelength. The angles are 0, 45, 90, 135 degrees, so the bank holds 12 filters. The largest kernel sets the halo of 27 pixels.
Complexity¶
- Time: \(O(S K N log N)\)
- Memory: \(O(S K N)\)
S scales, K orientations and N pixels in a tile with its halo. The magnitudes of every filter are kept until they are combined.
Artifacts and limitations¶
Limitations
- The cost grows with the number of filters.
- The angle output is noisy in flat areas, where every filter responds weakly.
Artifacts
- Blocky angle maps where two orientations respond almost equally.
Tests¶
The reference runs scipy.ndimage.correlate with every kernel of the bank and combines the magnitudes with NumPy, using the same rule for ties. Before the cases are written, the script checks single filters with aspect ratio 1 against skimage.filters.gabor with the same bandwidth, which confirms the sigma relation. The cases cover two banks and the three outputs for all five border modes.
References¶
- Daugman, J. G. Uncertainty relation for resolution in space, spatial frequency, and orientation optimized by two-dimensional visual cortical filters. Journal of the Optical Society of America A 2(7), 1160 to 1169, 1985. DOI 10.1364/JOSAA.2.001160.
- Kruizinga, P. and Petkov, N. Nonlinear operator for oriented texture. IEEE Transactions on Image Processing 8(10), 1395 to 1407, 1999. DOI 10.1109/83.791965.
- Grigorescu, S. E., Petkov, N. and Kruizinga, P. Comparison of texture features based on Gabor filters. IEEE Transactions on Image Processing 11(10), 1160 to 1167, 2002. DOI 10.1109/TIP.2002.804262.
- scikit-image documentation, skimage.filters.gabor_kernel, which sets sigma from the bandwidth. https://scikit-image.org/docs/stable/api/skimage.filters.html#skimage.filters.gabor_kernel