Overview
LBP (Local Binary Patterns) is a perceptual hash algorithm that excels at texture description and classification. It computes local binary patterns for each pixel by comparing it with its neighbors, then builds histograms of these patterns across grid cells.How It Works
The LBP algorithm processes images through the following steps:- Preprocessing: The image is resized and converted to grayscale
- LBP code computation: For each pixel, compare its value with its 8 neighbors (clockwise from right):
- If neighbor ≥ center: set bit to 1
- If neighbor < center: set bit to 0
- Creates an 8-bit code (0-255) for each pixel
- Grid division: The LBP code image is divided into grid cells
- Histogram computation: A 256-bin histogram is built for each cell
- Normalization: Each histogram is normalized (0-255 range)
- Concatenation: All cell histograms are concatenated into a single descriptor
LBP returns a UInt8 hash type with size = gridX × gridY × 256 bytes.
When to Use LBP
LBP is particularly effective for:- Texture classification and recognition
- Face recognition and detection
- Material identification
- Surface analysis
- Pattern matching in grayscale images
- Rotation-invariant texture matching (with rotation-invariant variants)
- Color-based matching (uses grayscale only)
- Images where color is more important than texture
- Smooth images without texture variation
Constructor
Options
Sets the resize dimensions before hash computation. The image is resized to this size before processing.Default: 256×256 pixels
Sets the interpolation method used when resizing the image.Default:
BilinearAvailable options: NearestNeighbor, Bilinear, Bicubic, LanczosSets the number of grid cells used to divide the image for spatial histogram computation.Default: 1×1 (single histogram for entire image)Larger grids capture more spatial information but produce longer hashes.
Overrides the default distance function used by the
Compare method.Default: similarity.ChiSquareAvailable functions: Hamming, L1, L2, Cosine, ChiSquare, PCC, JaccardUsage Example
Default Settings
| Parameter | Default Value |
|---|---|
| Width | 256 pixels |
| Height | 256 pixels |
| Interpolation | Bilinear |
| Grid Size | 1×1 |
| Distance Function | Chi-Square |
| Hash Length | 256 bytes (for 1×1 grid) |
Technical Details
- Hash Type:
hashtype.UInt8 - Hash Length: gridX × gridY × 256 bytes
- Default Comparison: Chi-Square distance
- Color Processing: Converted to grayscale
- Neighborhood: 8 neighbors (3×3 window)
- Pattern Range: 0-255 (256 possible patterns)
- Border Handling: Out-of-bounds neighbors treated as zero
Grid Size Considerations
| Grid Size | Hash Length | Spatial Detail | Use Case |
|---|---|---|---|
| 1×1 | 256 bytes | Global texture | Overall texture matching |
| 2×2 | 1024 bytes | Basic spatial | Quadrant-based matching |
| 4×4 | 4096 bytes | Detailed spatial | Regional texture analysis |
| 8×8 | 16384 bytes | Very detailed | Fine-grained spatial matching |
References
- Ojala, T., Pietikäinen, M., & Mäenpää, T. (2002). “Multiresolution Gray-Scale and Rotation Invariant Texture Classification with Local Binary Patterns.” IEEE Transactions on Pattern Analysis and Machine Intelligence.
- IEEE Xplore