Reference

dHash

dHash (difference hash) is a fast perceptual hashing algorithm that fingerprints an image by comparing the brightness of adjacent pixels. Each bit records whether one pixel is brighter than its neighbor, producing a compact 64-bit hash that stays stable across resizes and re-compression.

APIs & internalsGeneral

dHash

Also known as: difference hash, dhash image

dHash (difference hash) is a fast perceptual hashing algorithm that fingerprints an image by comparing the brightness of adjacent pixels. Each bit records whether one pixel is brighter than its neighbor, producing a compact 64-bit hash that stays stable across resizes and re-compression.

  • dHash compares each pixel to its right-hand neighbor on a 9x8 grayscale grid, yielding a 64-bit hash.
  • It is faster than DCT-based pHash because it needs no frequency transform, only a resize and pixel comparisons.
  • Encoding brightness gradients makes dHash robust to contrast and brightness changes.

How dHash works

The difference hash algorithm shrinks an image to a tiny grayscale grid, typically 9x8 pixels (72 pixels). It then walks each row and compares every pixel to the one immediately to its right.

Each comparison yields one bit: 1 if the left pixel is brighter, 0 otherwise. With 8 comparisons per row across 8 rows, this produces a 64-bit hash. Because it encodes gradients (relative brightness changes) rather than absolute values, the fingerprint is robust to overall brightness and contrast shifts.

dHash vs pHash

dHash is much cheaper to compute than a DCT-based perceptual hash: it needs only a resize and a row of pixel comparisons, no frequency transform. This makes it ideal as a first-pass filter when scanning large photo libraries.

The trade-off is that dHash is slightly less tolerant of heavy edits than pHash. In practice many dedup engines run dHash first to quickly cluster candidates, then optionally confirm with a more expensive hash. Similarity between two dHashes is measured with Hamming distance over the 64 bits.

Where Cleanor uses it

Cleanor relies on dHash as a fast fingerprint for grouping duplicate and similar photos entirely on-device. Its speed lets Cleanor scan thousands of images in your camera roll without draining the battery or sending data anywhere.

Because gradient-based hashing survives resizing and JPEG re-encoding, a shared image and the version that came back smaller through a chat app still hash close together. Cleanor flags those as likely duplicates so you can reclaim storage.

Related terms

Keep reading the reference.

Act on it

Guides and tools for this topic.