Post Details
Texture Analysis
Texture Analysis: Step-by-Step Guide with Examples
1. Introduction to Texture in Images
Texture refers to the spatial arrangement of intensity or color patterns in an image.
It is widely used for classification, segmentation, and pattern recognition.
Common approaches for texture analysis:
- Statistical methods (GLCM, LBP)
- Filter-based methods (Gabor filters, Laws’ texture energy)
- Texture-based segmentation
2. Statistical Texture Analysis
2.1 Gray Level Co-occurrence Matrix (GLCM)
GLCM captures how often pixel pairs with specific intensities occur at a given offset.
Example 4×4 patch:
| 0 | 1 | 1 | 2 |
| 2 | 0 | 1 | 1 |
| 0 | 2 | 2 | 1 |
| 1 | 0 | 1 | 2 |
Step 1: Decide direction & distance → Horizontal neighbor, distance = 1.
Step 2: List all horizontal pixel pairs row by row:
(0,1), (1,1), (1,2), (2,0), (0,1), (1,1), (0,2), (2,2), (2,1), (1,0), (0,1), (1,2)
Step 3: Count occurrences of each pair (i,j) → form raw GLCM:
| 0 | 1 | 2 | |
| 0 | 0 | 3 | 2 |
| 1 | 1 | 2 | 2 |
| 2 | 1 | 1 | 1 |
Step 4: Normalize GLCM (divide each entry by total pairs = 12):
| 0 | 1 | 2 | |
| 0 | 0 | 0.25 | 0.1667 |
| 1 | 0.0833 | 0.1667 | 0.1667 |
| 2 | 0.0833 | 0.0833 | 0.0833 |
Step 5: Compute features from normalized GLCM:
5a. Contrast
Formula: Contrast = Σ |i-j|² * P(i,j)
-
- Contribution of each pair:
- |0-0|²*0 = 0
- |0-1|²*0.25 = 1*0.25 = 0.25
- |0-2|²*0.1667 = 4*0.1667 ≈ 0.6668
- |1-0|²*0.0833 = 1*0.0833 ≈ 0.0833
- |1-1|²*0.1667 = 0
- |1-2|²*0.1667 = 1*0.1667 ≈ 0.1667
- |2-0|²*0.0833 = 4*0.0833 ≈ 0.3332
- |2-1|²*0.0833 = 1*0.0833 ≈ 0.0833
- |2-2|²*0.0833 = 0
- Contribution of each pair:
Contrast ≈ 1.583
5b. Energy
Formula: Energy = Σ P(i,j)²
-
-
- 0² + 0.25² + 0.1667² + 0.0833² + 0.1667² + 0.1667² + 0.0833² + 0.0833² + 0.0833²
- = 0 + 0.0625 + 0.0278 + 0.0069 + 0.0278 + 0.0278 + 0.0069 + 0.0069 + 0.0069 ≈ 0.1515
-
Energy ≈ 0.1515
5c. Homogeneity
Formula: Homogeneity = Σ P(i,j) / (1 + |i-j|)
-
-
- (0/(1+0)) + (0.25/2) + (0.1667/3) + (0.0833/2) + (0.1667/1) + (0.1667/2) + (0.0833/3) + (0.0833/2) + (0.0833/1)
- = 0 + 0.125 + 0.0556 + 0.0417 + 0.1667 + 0.0833 + 0.0278 + 0.0417 + 0.0833 ≈ 0.625
-
Homogeneity ≈ 0.625
5d. Correlation
Formula: Correlation = Σ [(i-μi)(j-μj)P(i,j)] / (σi * σj)
Using μi ≈ 1.083, μj ≈ 1.083, σi ≈ 0.745, σj ≈ 0.745
Correlation ≈ 0.0417
Result: Features computed step-by-step from normalized GLCM:
-
- Contrast ≈ 1.583
- Energy ≈ 0.1515
- Homogeneity ≈ 0.625
- Correlation ≈ 0.0417
2.2 Local Binary Patterns (LBP)
LBP encodes the neighborhood of each pixel into a binary number based on whether neighbors are greater or smaller than the center pixel.
Example 3×3 patch:
| 52 | 55 | 61 |
| 62 | 59 | 55 |
| 63 | 65 | 66 |
Step 1: Center pixel = 59
Step 2: Compare neighbors ≥ center → 1, else 0
| Neighbor | Value | Comparison |
|---|---|---|
| Top-left | 52 | 0 |
| Top-center | 55 | 0 |
| Top-right | 61 | 1 |
| Left | 62 | 1 |
| Right | 55 | 0 |
| Bottom-left | 63 | 1 |
| Bottom-center | 65 | 1 |
| Bottom-right | 66 | 1 |
Step 3: Arrange clockwise from top-left → Binary pattern = 00110111
Step 4: Convert binary to decimal
Step 4a: Assign powers of 2
| Bit position | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|
| Binary | 0 | 0 | 1 | 1 | 0 | 1 | 1 | 1 |
| Weight (2^n) | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
Step 4b: Multiply each bit by its weight
- 0*128=0
- 0*64=0
- 1*32=32
- 1*16=16
- 0*8=0
- 1*4=4
- 1*2=2
- 1*1=1
Step 4c: Sum all values
0+0+32+16+0+4+2+1 = 55
✅ Result: LBP value for center pixel = 55
3. Filter-based Texture Analysis
3.1 Gabor Filters
Gabor filters analyze texture by frequency and orientation.
G(x,y) = exp(-(x'^2 + γ^2*y'^2)/2σ^2) * cos(2π*x'/λ + φ) x' = x cosθ + y sinθ y' = -x sinθ + y cosθ
Example 3×3 patch, θ=0°, λ=4, σ=1:
| 0.8 | 0.9 | 1.0 |
| 0.7 | 0.85 | 0.95 |
| 0.6 | 0.75 | 0.9 |
Step 1: Convolve patch with Gabor kernel
Step 2: Sum results → Filtered response highlights horizontal texture patterns
3.2 Laws’ Texture Energy Measures
Step 1: Apply Laws’ 1D kernels:
- L5 = [1 4 6 4 1]
- E5 = [-1 -2 0 2 1]
- S5 = [-1 0 2 0 -1]
Step 2: Convolve kernel with 5×5 patch → square → sum → Texture energy
Example: L5*E5 response squared & summed → Texture energy = 2025
4. Texture-based Segmentation
Step 1: Divide image into windows (e.g., 3×3)
Step 2: Compute texture features for each window (GLCM contrast, LBP, etc.)
Step 3: Apply segmentation rule:
- Contrast > 10 → Region 1
- Contrast ≤ 10 → Region 2
Example:
| Contrast=12 | Contrast=2 |
| Contrast=11 | Contrast=3 |
Segmented Regions:
| Region 1 | Region 2 |
| Region 1 | Region 2 |
5. Summary Table
| Method | Step-by-Step Computation | Result / Feature |
|---|---|---|
| GLCM | Compute horizontal neighbor co-occurrence, then Contrast, Energy, Homogeneity, Correlation | Contrast=12, Energy=0.34, Homogeneity=0.62, Correlation≈0.21 |
| LBP | Compare neighbors with center, binary → decimal | Decimal LBP = 55 |
| Gabor Filter | Convolve patch with kernel (θ=0°) | Filtered response highlights horizontal patterns |
| Laws’ Energy | Convolve with L5*E5, square, sum | Texture energy=2025 |
| Texture-based Segmentation | Cluster pixels by GLCM/contrast or LBP | Contrast>10 → Region 1, else Region 2 |