wHash (Wavelet Hash)
Also known as: wavelet hash, whash image, wavelet hash
Wavelet hash (wHash) is a perceptual image-hashing method that uses a discrete wavelet transform to produce a compact fingerprint of an image. Visually similar photos get near-identical hashes, making it useful for finding duplicate and similar images.
- Uses a discrete wavelet transform (often Haar) to build a compact image fingerprint.
- Similarity is measured by Hamming distance between two hashes.
- Robust to resizing and compression, unlike exact or cryptographic hashes.
How wavelet hashing works
Like other perceptual hashes, wHash starts by shrinking the image to a small square (commonly 8x8 or 16x16) and converting it to grayscale. It then applies a discrete wavelet transform (DWT), typically using Haar wavelets, which decomposes the image into frequency bands that capture both overall structure and coarse detail.
The low-frequency coefficients, which represent the dominant visual content, are compared against their median value. Each coefficient becomes a single bit depending on whether it is above or below the median, yielding a fixed-length binary fingerprint such as a 64-bit hash.
How it compares to aHash, dHash, and pHash
Average hash (aHash) is the simplest, comparing each pixel to the overall mean. Difference hash (dHash) encodes gradients between adjacent pixels. Perceptual hash (pHash) uses a discrete cosine transform. wHash sits between these: the wavelet transform retains some spatial information that the DCT-based pHash discards, so it can be more robust to certain edits while remaining fast.
Two hashes are compared with Hamming distance, the count of differing bits. A small distance means the images are perceptually close, so they survive minor resizing, compression, or brightness changes. There is no single best algorithm; each trades speed against tolerance to specific transformations.
Use in similar-photo cleanup
Perceptual hashes like wHash let a cleaner group near-duplicate shots, such as burst photos or lightly edited copies, that an exact byte-for-byte or cryptographic hash would treat as completely different files. The app computes one short fingerprint per image and clusters those within a small Hamming distance.
Cleanor uses perceptual fingerprinting to surface similar and duplicate photos for review, so you can keep the best frame from a burst and remove the rest. wHash is one of several fingerprinting approaches; the practical choice depends on balancing accuracy against the speed needed to scan an entire camera roll on-device.