# Gabor filter

Jump to navigation Jump to search
Example of a two-dimensional Gabor filter

In image processing, a Gabor filter, named after Dennis Gabor, is a linear filter used for texture analysis, which means that it basically analyzes whether there are any specific frequency content in the image in specific directions in a localized region around the point or region of analysis. Frequency and orientation representations of Gabor filters are claimed by many contemporary vision scientists to be similar to those of the human visual system. They have been found to be particularly appropriate for texture representation and discrimination. In the spatial domain, a 2D Gabor filter is a Gaussian kernel function modulated by a sinusoidal plane wave (see Gabor transform).

Some authors claim that simple cells in the visual cortex of mammalian brains can be modeled by Gabor functions.[1][2] Thus, image analysis with Gabor filters is thought by some to be similar to perception in the human visual system.

## Definition

Its impulse response is defined by a sinusoidal wave (a plane wave for 2D Gabor filters) multiplied by a Gaussian function.[3] Because of the multiplication-convolution property (Convolution theorem), the Fourier transform of a Gabor filter's impulse response is the convolution of the Fourier transform of the harmonic function (sinusoidal function) and the Fourier transform of the Gaussian function. The filter has a real and an imaginary component representing orthogonal directions.[4] The two components may be formed into a complex number or used individually.

Complex

${\displaystyle g(x,y;\lambda ,\theta ,\psi ,\sigma ,\gamma )=\exp \left(-{\frac {x'^{2}+\gamma ^{2}y'^{2}}{2\sigma ^{2}}}\right)\exp \left(i\left(2\pi {\frac {x'}{\lambda }}+\psi \right)\right)}$

Real

${\displaystyle g(x,y;\lambda ,\theta ,\psi ,\sigma ,\gamma )=\exp \left(-{\frac {x'^{2}+\gamma ^{2}y'^{2}}{2\sigma ^{2}}}\right)\cos \left(2\pi {\frac {x'}{\lambda }}+\psi \right)}$

Imaginary

${\displaystyle g(x,y;\lambda ,\theta ,\psi ,\sigma ,\gamma )=\exp \left(-{\frac {x'^{2}+\gamma ^{2}y'^{2}}{2\sigma ^{2}}}\right)\sin \left(2\pi {\frac {x'}{\lambda }}+\psi \right)}$

where

${\displaystyle x'=x\cos \theta +y\sin \theta \,}$

and

${\displaystyle y'=-x\sin \theta +y\cos \theta \,}$

In this equation, ${\displaystyle \lambda }$ represents the wavelength of the sinusoidal factor, ${\displaystyle \theta }$ represents the orientation of the normal to the parallel stripes of a Gabor function, ${\displaystyle \psi }$ is the phase offset, ${\displaystyle \sigma }$ is the sigma/standard deviation of the Gaussian envelope and ${\displaystyle \gamma }$ is the spatial aspect ratio, and specifies the ellipticity of the support of the Gabor function.

## Wavelet space

Demonstration of a Gabor filter applied to Chinese OCR. Four orientations are shown on the right 0°, 45°, 90° and 135°. The original character picture and the superposition of all four orientations are shown on the left.

Gabor filters are directly related to Gabor wavelets, since they can be designed for a number of dilations and rotations. However, in general, expansion is not applied for Gabor wavelets, since this requires computation of bi-orthogonal wavelets, which may be very time-consuming. Therefore, usually, a filter bank consisting of Gabor filters with various scales and rotations is created. The filters are convolved with the signal, resulting in a so-called Gabor space. This process is closely related to processes in the primary visual cortex.[5] Jones and Palmer showed that the real part of the complex Gabor function is a good fit to the receptive field weight functions found in simple cells in a cat's striate cortex.[6]

## Extraction of features from images

A set of Gabor filters with different frequencies and orientations may be helpful for extracting useful features from an image.[7] In the discrete domain, two-dimensional Gabor filters are given by,

${\displaystyle G_{c}[i,j]=Be^{-{\frac {(i^{2}+j^{2})}{2\sigma ^{2}}}}\cos(2\pi f(i\cos \theta +j\sin \theta ))}$
${\displaystyle G_{s}[i,j]=Ce^{-{\frac {(i^{2}+j^{2})}{2\sigma ^{2}}}}\sin(2\pi f(i\cos \theta +j\sin \theta ))}$

where B and C are normalizing factors to be determined. 2-D Gabor filters have rich applications in image processing, especially in feature extraction for texture analysis and segmentation.[8] ${\displaystyle f}$ defines the frequency being looked for in the texture. By varying ${\displaystyle \theta }$, we can look for texture oriented in a particular direction. By varying ${\displaystyle \sigma }$, we change the support of the basis or the size of the image region being analyzed.

## Applications of 2-D Gabor filters in image processing

In document image processing, Gabor features are ideal for identifying the script of a word in a multilingual document.[9] Gabor filters with different frequencies and with orientations in different directions have been used to localize and extract text-only regions from complex document images (both gray and colour), since text is rich in high frequency components, whereas pictures are relatively smooth in nature.[10][11][12] It has also been applied for facial expression recognition [13] Gabor filters have also been widely used in pattern analysis applications. For example, it has been used to study the directionality distribution inside the porous spongy trabecular bone in the spine.[14] The Gabor space is very useful in image processing applications such as optical character recognition, iris recognition and fingerprint recognition. Relations between activations for a specific spatial location are very distinctive between objects in an image. Furthermore, important activations can be extracted from the Gabor space in order to create a sparse object representation.

## Example implementations

(Code for Gabor feature extraction from images in MATLAB can be found at http://www.mathworks.com/matlabcentral/fileexchange/44630.)

This is an example implementation in Python:

import numpy as np

def gabor(sigma, theta, Lambda, psi, gamma):
"""Gabor feature extraction."""
sigma_x = sigma
sigma_y = float(sigma) / gamma

# Bounding box
nstds = 3  # Number of standard deviation sigma
xmax = max(abs(nstds * sigma_x * np.cos(theta)), abs(nstds * sigma_y * np.sin(theta)))
xmax = np.ceil(max(1, xmax))
ymax = max(abs(nstds * sigma_x * np.sin(theta)), abs(nstds * sigma_y * np.cos(theta)))
ymax = np.ceil(max(1, ymax))
xmin = -xmax
ymin = -ymax
(y, x) = np.meshgrid(np.arange(ymin, ymax + 1), np.arange(xmin, xmax + 1))

# Rotation
x_theta = x * np.cos(theta) + y * np.sin(theta)
y_theta = -x * np.sin(theta) + y * np.cos(theta)

gb = np.exp(-.5 * (x_theta ** 2 / sigma_x ** 2 + y_theta ** 2 / sigma_y ** 2)) * np.cos(2 * np.pi / Lambda * x_theta + psi)
return gb


For an implementation on images, see [1].

This is an example implementation in MATLAB/Octave:

function gb=gabor_fn(sigma,theta,lambda,psi,gamma)

sigma_x = sigma;
sigma_y = sigma/gamma;

% Bounding box
nstds = 3;
xmax = max(abs(nstds*sigma_x*cos(theta)),abs(nstds*sigma_y*sin(theta)));
xmax = ceil(max(1,xmax));
ymax = max(abs(nstds*sigma_x*sin(theta)),abs(nstds*sigma_y*cos(theta)));
ymax = ceil(max(1,ymax));
xmin = -xmax; ymin = -ymax;
[x,y] = meshgrid(xmin:xmax,ymin:ymax);

% Rotation
x_theta=x*cos(theta)+y*sin(theta);
y_theta=-x*sin(theta)+y*cos(theta);

gb= exp(-.5*(x_theta.^2/sigma_x^2+y_theta.^2/sigma_y^2)).*cos(2*pi/lambda*x_theta+psi);


This is another example implementation in Haskell:

import Data.Complex (Complex((:+)))
gabor λ θ ψ σ γ x y = exp ( (-0.5) * ((x'^2 + γ^2*y'^2) / (σ^2)) :+ 0) * exp ( 0 :+ (2*pi*x'/λ+ψ) )
where x' =  x * cos θ + y * sin θ
y' = -x * sin θ + y * cos θ


(Note: a :+ b should be read as ${\displaystyle a+ib}$)

## References

1. ^ Marčelja, S. (1980). "Mathematical description of the responses of simple cortical cells". Journal of the Optical Society of America. 70 (11): 1297–1300. Bibcode:1980JOSA...70.1297M. doi:10.1364/JOSA.70.001297. PMID 7463179.
2. ^ Daugman, John G. (1985-07-01). "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–9. Bibcode:1985JOSAA...2.1160D. CiteSeerX 10.1.1.465.8506. doi:10.1364/JOSAA.2.001160. ISSN 1084-7529. PMID 4020513.
3. ^ Fogel, I.; Sagi, D. (June 1989). "Gabor filters as texture discriminator". Biological Cybernetics. 61 (2). CiteSeerX 10.1.1.367.2700. doi:10.1007/BF00204594. ISSN 0340-1200. OCLC 895625214.
4. ^ 3D surface tracking and approximation using Gabor filters, Jesper Juul Henriksen, South Denmark University, March 28, 2007
5. ^ Daugman, J.G. (1980), "Two-dimensional spectral analysis of cortical receptive field profiles", Vision Res., 20 (10): 847–56, doi:10.1016/0042-6989(80)90065-6, PMID 7467139
6. ^ Jones, J.P.; Palmer, L.A. (1987). "An evaluation of the two-dimensional gabor filter model of simple receptive fields in cat striate cortex" (PDF). J. Neurophysiol. 58 (6): 1233–1258. doi:10.1152/jn.1987.58.6.1233. PMID 3437332.
7. ^ Haghighat, M.; Zonouz, S.; Abdel-Mottaleb, M. (2013). "Identification Using Encrypted Biometrics". Computer Analysis of Images and Patterns. Lecture Notes in Computer Science. 8048. p. 440. doi:10.1007/978-3-642-40246-3_55. ISBN 978-3-642-40245-6.
8. ^ Ramakrishnan, A.G.; Kumar Raja, S.; Raghu Ram, H.V. (2002). "Neural network-based segmentation of textures using Gabor features" (PDF). Proceedings of the 12th IEEE Workshop on Neural Networks for Signal Processing. Martigny, Switzerland: IEEE: 365–374. doi:10.1109/NNSP.2002.1030048. ISBN 978-0-7803-7616-8. OCLC 812617471.
9. ^ Pati, Peeta Basa; Ramakrishnan, A.G. (July 2008). "Word level multi-script identification". Pattern Recognition Letters. 29 (9): 1218–1229. doi:10.1016/j.patrec.2008.01.027. ISSN 0167-8655.
10. ^ Raju S, S.; Pati, P.B.; Ramakrishnan, A.G. (2004). "Gabor filter based block energy analysis for text extraction from digital document images" (PDF). First International Workshop on Document Image Analysis for Libraries, 2004. Proceedings. Palo Alto, CA, USA: IEEE: 233–243. doi:10.1109/DIAL.2004.1263252. ISBN 978-0-7695-2088-9. LCCN 2003116308. OL 8067708M.
11. ^ Raju, S. Sabari; Pati, P. B.; Ramakrishnan, A. G. (2005). "Text Localization and Extraction from Complex Color Images". Lecture Notes in Computer Science. 3804: 486–493. doi:10.1007/11595755_59. ISBN 978-3-540-30750-1. ISSN 0302-9743. LCCN 2005936803. OL 9056158M.
12. ^ S Sabari Raju, P B Pati and A G Ramakrishnan, “Text Localization and Extraction from Complex Color Images,” Proc. First International Conference on Advances in Visual Computing (ISVC05), Nevada, USA, LNCS 3804, Springer Verlag, Dec. 5-7, 2005, pp. 486-493.
13. ^ Lyons, M.; Akamatsu, S.; Kamachi, M.; Gyoba, J. (1998). Coding facial expressions with Gabor wavelets. pp. 200–205. doi:10.1109/AFGR.1998.670949. ISBN 0-8186-8344-9. OL 11390549M.
14. ^ Gdyczynski, C.M.; Manbachi, A.; et al. (2014). "On estimating the directionality distribution in pedicle trabecular bone from micro-CT images". Journal of Physiological Measurements. 35 (12): 2415–2428. Bibcode:2014PhyM...35.2415G. doi:10.1088/0967-3334/35/12/2415. PMID 25391037.