Skip to content

Gabor Filters and Texture Analysis

Texture describes repeated or locally organized intensity patterns in an image. Gabor filters provide one way to measure patterns with particular directions and spatial frequencies.

1. What Is Texture?

Texture is related to how image intensities are arranged over space. Two image regions can have similar overall brightness but very different spatial patterns.

Different Spatial Patterns
Vertical Pattern
Intensity changes mainly from left to right.
Horizontal Pattern
Intensity changes mainly from top to bottom.
Diagonal Pattern
Intensity changes along a diagonal direction.
The grayscale values matter, but their spatial arrangement also contains information. A texture filter attempts to measure that arrangement.

2. The Gabor Filter

A Gabor filter combines a Gaussian envelope with an oscillating pattern.

Building a Gabor Filter
Gaussian Envelope
Limits the measurement to a local region
×
Oscillation
Responds to a particular direction and spacing
↓
Gabor Filter
Measures a particular local spatial pattern

In the separable form used here, one one-dimensional Gabor kernel is associated with the \(x\) direction and another with the \(y\) direction.

\[ h_x(x) = \exp \left( -\frac{x^2}{2\sigma^2} \right) \exp \left( j2\pi F x\cos\theta \right) \] \[ h_y(y) = \exp \left( -\frac{y^2}{2\sigma^2} \right) \exp \left( j2\pi F y\sin\theta \right) \]
Variables in the Gabor Filter
\(x,y\)
Spatial coordinates measured relative to the center of the filter.
\(h_x(x)\)
One-dimensional Gabor kernel used during filtering in the \(x\) direction.
\(h_y(y)\)
One-dimensional Gabor kernel used during filtering in the \(y\) direction.
\(\sigma\)
Standard deviation of the Gaussian envelope. It controls how broadly the filter is localized around its center.
\(F\)
Spatial frequency. It controls how quickly the oscillating pattern repeats across space.
\(\theta\)
Orientation angle. It controls the direction along which the oscillation changes.
\(j\)
Imaginary unit, where \(j^2=-1\). It allows the Gabor response to contain magnitude and phase information.
\(\exp(\cdot)\)
Exponential function.
The Gaussian part controls where the filter is active in space. The oscillating part controls the direction and spacing of the pattern to which it responds.

3. Orientation \(\theta\)

The orientation angle uses both cosine and sine. The \(x\) and \(y\) coordinates combine into an oriented coordinate:

\[ x_{\theta} = x\cos\theta + y\sin\theta \]
\(x_{\theta}\)
Position measured along the direction selected by \(\theta\).

The oscillating part can therefore be written as:

\[ \exp \left( j2\pi F x_{\theta} \right) \]
Changing the Orientation
\(\theta=0^\circ\)
\(\theta=45^\circ\)
\(\theta=90^\circ\)
\(\theta\) describes the direction along which the oscillation changes. The visible bands are perpendicular to that direction.
\(\theta=0^\circ\): the oscillation changes along \(x\), producing vertical bands.
\(\theta=45^\circ\): the oscillation changes along a diagonal direction.
\(\theta=90^\circ\): the oscillation changes along \(y\), producing horizontal bands.
Changing \(\theta\) changes which directional structure produces a strong Gabor response.

4. Spatial Frequency \(F\)

Spatial frequency describes how quickly a pattern repeats across space.

Lower Frequency
Wider spacing between repetitions
Medium Frequency
Medium spacing between repetitions
Higher Frequency
Narrower spacing between repetitions
Lower \(F\) corresponds to wider repeating patterns. Higher \(F\) corresponds to more closely spaced repetition.

5. Gaussian Width \(\sigma\)

The Gaussian envelope determines how broadly the filter is localized around its center.

Smaller \(\sigma\)
More localized region
Medium \(\sigma\)
Larger local region
Larger \(\sigma\)
Broader local region
\(\sigma\) controls the width of the Gaussian envelope. It is not exactly the same thing as the digital kernel size.

\(\sigma\) and the Digital Kernel Size

A computer represents the Gaussian using a finite number of pixels. In the interactive visualizer on this page, the radius is

\[ r=2\sigma \]

and the side length of the square kernel is

\[ N = 2r+1 = 4\sigma+1. \]
\(r\)
Radius of the finite digital kernel measured in pixels from its center.
\(N\)
Number of pixels along one side of the square digital kernel.
\(\sigma=2\) \(9\times9\)
\(\sigma=3\) \(13\times13\)
\(\sigma=4\) \(17\times17\)
\(N=4\sigma+1\) is the finite kernel-size rule used by this visualizer. Other implementations may choose a different finite support for the same Gaussian width.

6. Applying the Filter

In the separable implementation, filtering is performed in two one-dimensional stages.

Input grayscale image \(I(x,y)\)
↓
Convolve with \(h_x\) in the \(x\) direction
↓
Intermediate result \(m_1\)
↓
Convolve \(m_1\) with \(h_y\) in the \(y\) direction
↓
Complex Gabor response \(m_2\)
\[ m_1 = I\ast h_x \] \[ m_2 = m_1\ast h_y \]
Variables in the Filtering Equations
\(I\)
Input grayscale image.
\(\ast\)
Convolution operation.
\(m_1\)
Intermediate response after the first filtering stage.
\(m_2\)
Complex-valued Gabor response after both filtering stages.

7. Response Magnitude

Because the Gabor response can be complex-valued, its magnitude provides a nonnegative measure of response strength.

\[ m(x,y) = \left| m_2(x,y) \right| \]
\(m_2(x,y)\)
Complex Gabor response at image location \((x,y)\).
\(|\cdot|\)
Magnitude of a complex number.
\(m(x,y)\)
Nonnegative Gabor magnitude response at location \((x,y)\).
Input Texture
Original intensity pattern
Gabor Response
Response changes across the image
Magnitude
Larger values represent stronger responses
The magnitude response shows where the selected Gabor pattern produces a stronger response.

8. Smoothing the Response

The magnitude response can vary rapidly from one location to another. Gaussian smoothing can be applied to the response before thresholding.

Raw Response
Local response values can vary sharply.
Smoothed Response
Nearby response values become more spatially continuous.
This smoothing is applied to the Gabor response rather than directly to the original texture image.

9. Thresholding and Segmentation

A selected range of response values can be converted into a binary segmentation mask.

\[ S(x,y) = \begin{cases} 1, & T_L \lt R(x,y) \le T_H \\[6pt] 0, & \text{otherwise} \end{cases} \]
Variables in the Segmentation Equation
\(R(x,y)\)
Response value being tested at location \((x,y)\). It may be the magnitude response or its smoothed version.
\(T_L\)
Lower response threshold.
\(T_H\)
Upper response threshold.
\(S(x,y)\)
Binary segmentation result. \(1\) represents a selected pixel and \(0\) represents an unselected pixel.
Select a Range of Response Values
\(T_L\)
\(T_H\)
Original
Binary Mask
Overlay
Pixels whose response lies inside the selected range become foreground in the binary mask.

10. What Happens Near the Image Boundary?

A filter needs neighboring pixel values around the pixel being processed. To make the boundary problem easy to see, first consider a simple \(3\times3\) neighborhood.

A \(3\times3\) calculation requires nine pixel values. Away from the image boundary, all nine requested positions belong to the image. Near an edge or corner, some requested coordinates can fall outside the finite image domain.

Same 3 × 3 Neighborhood, Different Center Location
Center Away from the Image Edge
The complete 3 × 3 neighborhood remains inside the 5 × 5 image domain.
9 / 9 required pixel values are available
Every coordinate requested by the neighborhood belongs to the original image, so the filter can evaluate this location without inventing any additional values.
Center at the Upper-Left Corner
Five of the nine requested coordinates lie outside the 5 × 5 image domain.
?
?
?
?
?
4 / 9 required pixel values are available
Only the corner pixel itself, its right neighbor, its lower neighbor, and its lower-right neighbor belong to the original image. The remaining five requested coordinates have no original image value.
Dark outline = actual 5 × 5 image domain
Gray region = outside the image
Required image sample exists
Current filter-center pixel
? Requested coordinate is outside the image
The gray outer ring is not part of the image. It represents coordinates that the filtering equation may request even though no original pixel exists there.
For a \(3\times3\) neighborhood, an interior pixel has all \(9\) required image samples. At a corner, only \(4\) of the \(9\) requested samples belong to the original image.

Why Does the Program Need a Boundary Rule?

The mathematical filtering expression can request a location beyond the finite image domain. A computer implementation must therefore specify what should happen whenever such a coordinate is encountered.

The filter requests a neighboring sample
↓
The requested coordinate lies outside the image domain
↓
No original image value exists at that coordinate
↓
Apply the selected boundary-handling rule

Common Boundary-Handling Methods

Skip the Boundary
Evaluate the filter only at center locations where the complete kernel lies inside the image.
Zero Padding
Treat every requested coordinate outside the image as if its intensity were \(0\).
Replicate
Replace an outside request with the value of the nearest image-edge pixel.
Reflect
Mirror image values across the boundary to generate the required outside samples.

Connection to the Gabor Kernel

The \(3\times3\) example above is intentionally small so the boundary problem is easy to see. The same issue occurs with the larger Gabor kernels used by the visualizer.

Kernel Radius Used on This Page

\[ r=2\sigma \] \[ N=2r+1=4\sigma+1 \]

Here \(r\) is the distance from the kernel center to either side, and \(N\) is the kernel width and height.

Valid Centers with “Skip”

\[ r \le x \le W-1-r \] \[ r \le y \le H-1-r \]

For an image of width \(W\) and height \(H\), the kernel center must remain at least \(r\) pixels from every image edge.

For example, if \(\sigma=3\) in this visualizer, then \(r=6\) and the kernel size is \(N=13\). With Skip the Boundary, the Gabor response is therefore evaluated only where the \(13\times13\) kernel fits completely inside the image.
The interactive Gabor visualizer below uses Skip the Boundary. Pixels in the skipped border region do not receive a Gabor response from that implementation; they are not being treated as zero-padded pixels.
A larger Gabor kernel requires a wider neighborhood around every center pixel. Under the Skip rule, increasing the kernel radius therefore increases the width of the image border that cannot be evaluated.

11. Interactive Example

The interactive visualizer below lets you change the Gabor parameters and observe how the filter response and segmentation change.

Choose an input texture
↓
Change orientation \(\theta\), spatial frequency \(F\), and Gaussian width \(\sigma\)
↓
Inspect the Gabor kernel
↓
Inspect the magnitude response
↓
Optionally smooth the response
↓
Adjust the response thresholds
↓
Compare the segmentation with the original texture

Summary

Concept Meaning
Texture Spatial organization or repetition of image intensities.
Gabor Filter Gaussian-localized oscillating filter used to measure a particular local spatial pattern.
\(\theta\) Orientation angle controlling the direction along which the oscillation changes.
\(F\) Spatial frequency controlling how quickly the pattern repeats.
\(\sigma\) Width parameter of the Gaussian envelope.
\(N\) Number of pixels along one side of the finite digital kernel.
\(m_2\) Complex Gabor response.
\(m(x,y)\) Magnitude of the Gabor response at location \((x,y)\).
\(T_L,T_H\) Lower and upper response thresholds.
\(S(x,y)\) Binary segmentation mask.
Boundary Handling Rule used when filtering requires pixel values beyond the available image.

Gabor Texture Visualizer
Explore how orientation, spatial frequency, Gaussian width, response smoothing, and thresholding affect a texture response.
The default settings are tuned to respond strongly to the vertical texture on the left side of the Vertical + Diagonal example. Try changing the orientation to see a different directional texture become stronger.
Input Texture
Generated 8-bit grayscale texture
Gabor Kernel
Real part of the complex Gabor kernel
Gabor Magnitude Response
Brighter pixels indicate a stronger response
Response Used for Thresholding
No additional response smoothing
Segmentation Mask
Pixels inside the selected normalized response range
Segmentation Overlay
Orange identifies pixels selected by the mask
Orientation
0°
Spatial Frequency
0.12
Kernel Size
13 × 13
Mask Coverage
0%
For this teaching visualizer, the displayed Gabor response is normalized to the range 0–255 before thresholding. This lets the response use the same familiar grayscale range as an 8-bit image.

Published inDigital Image Processing

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *