Overview
ColorMoment is a perceptual hash algorithm that uses color invariant moments to create a robust image fingerprint. It operates by computing Hu moments from both YCrCb and HSV color spaces, combining them into a single Float64 hash descriptor. This algorithm is particularly effective for:- Color image matching where color information is important
- Finding images with similar color distributions
- Detecting images that have been color-adjusted or filtered
- Applications requiring rotation-invariant features
ColorMoment 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: 512×512)
- Gaussian Blur: Applies Gaussian smoothing to reduce noise
- Color Space Conversion: Converts to both YCrCb and HSV color spaces
- Moment Extraction: Computes image moments from each color space
- Hu Moments: Calculates Hu invariant moments for rotation invariance
- Descriptor: Combines Hu moments from both color spaces into a single vector
Constructor
Available Options
WithSize(width, height uint)- Set resize dimensions (default: 512×512)WithInterpolation(interp Interpolation)- Set interpolation method (default: Bicubic)WithKernelSize(size int)- Set Gaussian kernel size (default: 3)WithSigma(sigma float64)- Set Gaussian kernel sigma (default: 0)WithDistance(fn DistanceFunc)- Override default L2 distance function
Usage Example
Default Settings
Image resize width
Image resize height
Resize interpolation method
Gaussian kernel size (must be > 0)
Gaussian kernel standard deviation (0 = auto-calculate)
Distance comparison function
Hash Type
Returnshashtype.Float64 - a slice of float64 values containing the combined Hu moments from HSV and YCrCb color spaces (typically 14 values: 7 from each color space).
Distance Metric
Default comparison uses L2 (Euclidean) distance. Lower values indicate more similar images. You can override with:similarity.L1- Manhattan distancesimilarity.Cosine- Cosine distancesimilarity.ChiSquare- Chi-square distance- Custom distance function