DCT Perceptual Hash

A C# image-similarity component that derives a 64-bit perceptual signature from a 64×64 DCT workspace and reduces later comparisons to XOR and Hamming distance.

The useful scaling property of this implementation is that image analysis happens once per asset. A source image is mapped to a 64×64 working representation, converted to an intensity sequence and transformed with a separable DCT. The low-frequency 8×8 region is then quantized around its median, producing one UInt64 signature.

After that preprocessing step, a collection search no longer needs another DCT for every pair. Similarity becomes a Hamming-distance operation: popcount(hash1 XOR hash2). Precomputed cosine coefficients and Vector4.Dot in the transform path keep repeated arithmetic work bounded without changing the representation.

The resulting value is perceptual, not cryptographic. Collisions are normal, and a useful Hamming threshold has to be calibrated on the target corpus. The method also makes no general claim of invariance to large crops, rotations or perspective changes. Variance Image Quantizer sits nearby in the image-processing set but solves a different problem: palette reduction and encoded PNG size.

The implementation history and design choices are documented in Perceptual Image Similarity with DCT and SIMD.

Repository: GitHub Zenodo snapshot: Zenodo DOI: DOI

QR code for this page