Overview
RASH (Rotation Aware Spatial Hash) is a perceptual hash designed to be robust against image rotation. It combines concentric ring sampling for rotation invariance, a 1-D DCT for frequency compaction, and median thresholding for binarization. Because ring-mean features are inherently rotation-invariant (rotating the image only permutes pixels within a ring, leaving its mean unchanged), the resulting hash stays stable under arbitrary rotations.When to Use
Use RASH when you need:- Rotation-invariant hashing without multiple hash variants
- Compact hash (64-bit default) with rotation robustness
- Ring-based spatial features for circular symmetry
- Efficient rotation handling compared to Block Mean rotation variants
- DCT-based frequency analysis of radial features
RASH provides rotation invariance in a compact 64-bit hash, unlike Block Mean rotation variants that require 6,144+ bits.
Constructor
Available Options
WithSize(width, height uint)- Sets the resize dimensionsWithRings(rings int)- Sets the number of concentric ringsWithSigma(sigma float64)- Sets the Gaussian blur sigmaWithInterpolation(interp Interpolation)- Sets the resize interpolation methodWithDistance(fn DistanceFunc)- Overrides the default Hamming distance function
Supported Interpolation Methods
NearestNeighborBilinear(default)BicubicMitchellNetravaliLanczos2Lanczos3BilinearExact
Usage Example
With Custom Options
Default Settings
- Hash size: 64 bits (8 bytes)
- Resize dimensions: 256×256 pixels
- Number of rings: 180
- Gaussian sigma: 1.0
- Interpolation: Bilinear
- Distance metric: Hamming distance
How It Works
The RASH algorithm:- Resizes the image to specified dimensions (default 256×256)
- Converts to grayscale
- Applies Gaussian blur with specified sigma
- Divides the image into concentric rings around the center
- Computes the mean pixel intensity for each ring:
- Ring width = max_radius / number_of_rings
- Each pixel assigned to a ring based on distance from center
- Applies 1-D DCT to the ring mean vector
- Keeps the first 64 low-frequency coefficients (skipping DC component)
- Computes the median of these coefficients
- Thresholds coefficients against the median:
- Sets bit to 1 if coefficient > median
- Sets bit to 0 if coefficient ≤ median
- Produces a 64-bit binary hash
Ring Sampling Illustration
Number of Rings
The number of rings affects hash quality and rotation invariance:With 180 rings (default), the DCT extracts 64 coefficients from 180 ring means, providing good frequency compaction.
Gaussian Blur
The sigma parameter controls pre-blur strength:Comparison
RASH hashes are compared using Hamming distance:RASH vs. Other Rotation-Robust Methods
| Algorithm | Hash Size | Speed | Rotation Robustness |
|---|---|---|---|
| RASH | 64 bits | Fast | Excellent |
| Block Mean (Rotation) | 6,144 bits | Very Slow | Excellent |
| PHash | 64 bits | Medium | None |
| PDQ | 256 bits | Medium | None |
Performance Characteristics
- Speed: Fast (ring sampling, 1-D DCT)
- Memory: Very low (64-bit hash)
- Rotation: Invariant to arbitrary rotations
- Scaling: Robust to scaling
- Cropping: Not robust to cropping (changes ring structure)
Use Cases
- Logo detection with unknown rotation
- Duplicate detection for user-uploaded photos (arbitrary orientations)
- Satellite/aerial imagery matching
- Artwork comparison with varying orientations
- Medical imaging (scans at different angles)
Limitations
Technical Inspiration
RASH is inspired by ring-partition hashing literature:- Tang et al., “Robust Image Hashing with Ring Partition and Invariant Vector Distance” (2016)
- De Roover et al., “Robust image hashing based on radial variance of pixels” (2005)
rash.go:13-24
References
- Source:
rash.go:13-24