Overview
Zernike is a perceptual hash algorithm that uses Zernike moments to create a rotation-invariant image descriptor. It computes complex Zernike moments up to a specified degree and stores their magnitudes, making the hash invariant to image rotation. This algorithm is ideal for:- Matching images regardless of rotation angle
- Finding similar shapes and structures
- Applications requiring rotation invariance
- Pattern recognition and image retrieval
Zernike returns a Float64 hash type (not Binary). Use L2 (Euclidean) distance for comparison.
How It Works
- Resize: Image is resized to the specified dimensions (default: 64×64)
- Grayscale: Converts to grayscale
- Zernike Computation: Computes Zernike moments for all valid orders up to maximum degree
- Magnitude Extraction: Stores |A(n,m)| values (magnitude only, discarding phase)
- Normalization: Normalizes by DC component for intensity invariance
Constructor
Available Options
WithSize(width, height uint)- Set resize dimensions (default: 64×64)WithInterpolation(interp Interpolation)- Set interpolation method (default: Bilinear)WithDegree(degree int)- Set maximum Zernike degree (default: 8)WithDistance(fn DistanceFunc)- Override default L2 distance function
Usage Example
Default Settings
Image resize width
Image resize height
Resize interpolation method
Maximum Zernike degree (must be > 0). Higher values capture more detail but increase hash size.
Distance comparison function
Hash Type
Returnshashtype.Float64 - a slice of float64 values containing normalized Zernike moment magnitudes.
Hash size depends on the degree parameter:
- Degree 8: 20 values (excluding A(0,0))
- Degree 12: 42 values
- Generally: approximately (degree+1)×(degree+2)/4 values
Distance Metric
Default comparison uses L2 (Euclidean) distance. Lower values indicate more similar images. You can override with:similarity.L1- Manhattan distancesimilarity.Cosine- Cosine distance- Custom distance function
Degree Parameter
Thedegree parameter controls the maximum order n:
- Lower degrees (4-8): Faster computation, captures coarse structure
- Higher degrees (12-16): More detailed representation, larger hash size
- Trade-off between discriminative power and computational cost