Overview
Marr-Hildreth Hash is a perceptual hashing algorithm based on the method described in “Implementation and Benchmarking of Perceptual Image Hash Functions” by Zauner et al. It uses the Marr-Hildreth edge detector (Laplacian of Gaussian) to extract structural features. The algorithm applies Gaussian blur, histogram equalization, and a Marr-Hildreth kernel to detect edges, then computes block sums and thresholds them to create the hash.When to Use
Use Marr-Hildreth Hash when you need:- Edge-based features for robust matching
- High robustness to various transformations
- Academic rigor with benchmarking results
- Larger hash sizes for better discrimination
- Scale-space analysis through kernel parameters
Marr-Hildreth Hash produces a 72-byte (576-bit) hash by default, making it suitable for applications requiring high precision.
Constructor
Available Options
WithSize(width, height uint)- Sets the resize dimensionsWithInterpolation(interp Interpolation)- Sets the resize interpolation methodWithScale(scale float64)- Sets the scale parameter for Marr-Hildreth kernelWithAlpha(alpha float64)- Sets the alpha parameter for Marr-Hildreth kernelWithKernelSize(size int)- Sets the Gaussian kernel size for pre-blurWithSigma(sigma float64)- Sets the Gaussian sigma for pre-blur (0 = auto)WithDistance(fn DistanceFunc)- Overrides the default Hamming distance function
Supported Interpolation Methods
NearestNeighborBilinearBicubic(default)MitchellNetravaliLanczos2Lanczos3BilinearExact
Usage Example
With Custom Options
Default Settings
- Hash size: 576 bits (72 bytes)
- Resize dimensions: 512×512 pixels
- Interpolation: Bicubic
- Scale: 1.0
- Alpha: 2.0
- Gaussian kernel size: 7
- Gaussian sigma: 0 (auto-computed)
- Block size: 16×16 pixels
- Number of blocks: 31×31
- Sub-block size: 3×3
- Sub-block stride: 4
- Distance metric: Hamming distance
How It Works
The Marr-Hildreth Hash algorithm:- Converts image to grayscale
- Applies Gaussian blur with specified kernel size and sigma
- Resizes to 512×512 pixels
- Applies histogram equalization for contrast enhancement
- Applies 2D Marr-Hildreth (Laplacian of Gaussian) filter
- Divides filtered image into 16×16 pixel blocks (31×31 blocks total)
- Computes sum of each block
- Creates hash by:
- Stepping through blocks with 3×3 sub-blocks at stride 4
- Computing average of each 3×3 sub-block
- Comparing each value to the sub-block average
- Setting bit to 1 if value > average, 0 otherwise
- Produces a 576-bit binary hash
Scale and Alpha Parameters
The Marr-Hildreth kernel is computed using the formula:scalecontrols the decomposition levelalphadetermines the kernel sigma:σ = 4 * alpha^level
Comparison
Marr-Hildreth hashes are compared using Hamming distance:Due to the larger hash size (576 bits), threshold values for similarity will be proportionally higher than for 64-bit hashes.
Performance Characteristics
- Speed: Slow (Gaussian blur, histogram equalization, LoG filter, block processing)
- Memory: Moderate (72-byte hash, 512×512 intermediate image)
- Robustness: Very high for various transformations
- Rotation: Not rotation-invariant
- Scaling: Very robust to scaling
Hash Size Calculation
References
- Implementation and Benchmarking of Perceptual Image Hash Functions - Zauner et al.
- Source:
marrhildreth.go:19-22