Perceptual image hash: are these the same picture?
Compare two images by aHash, dHash and pHash in the browser - a re-encoded, resized or recompressed copy has a different checksum and nearly the same perceptual hash.
Open in ctfpalA cryptographic hash answers "are these the same bytes", which is almost never the question you have. Save a photograph as JPEG at a different quality, resize it, or let a chat client re-encode it, and the SHA-256 changes completely while the picture is obviously the same.
A perceptual hash answers the question you actually have. It reduces an image to a 32x32 thumbnail, throws away colour, and encodes the coarse structure that survives re-encoding into 64 bits. Two versions of the same picture differ by a handful of those bits; two unrelated pictures differ by about half of them.
Three algorithms, because they fail differently
| Hash | How it works | Where it breaks |
|---|---|---|
| aHash | 8x8 thumbnail; each pixel above the mean is a 1 | A brightness or gamma change moves the mean under everything, so the whole hash shifts. |
| dHash | 9x8 thumbnail; each pixel brighter than the one to its right is a 1 | Encodes gradients rather than levels, so brightness changes cost nothing. The best default. |
| pHash | 32x32, 2-D DCT, the low-frequency coefficients above their median | The most robust - it survives small rotations, heavy compression and watermarks - and the slowest. |
The 9-wide thumbnail for dHash is not a typo. Eight comparisons per row need nine pixels, and an 8x8 dHash silently compares the last pixel of one row against the first of the next - which produces a hash that looks fine and is subtly wrong at every row boundary.
Reading the distance
Two hashes are compared by Hamming distance: how many of the 64 bits differ. The thresholds every practical implementation converges on are worth knowing rather than looking up:
- 0 bits - the same picture, to the resolution the hash sees.
- 1 to 5 - almost certainly the same image, re-encoded, resized or recompressed.
- 6 to 10 - plausibly the same scene or a heavy edit. Worth looking at; not evidence.
- Over 10 - no perceptual relationship at this hash size.
Why this is local and reverse search is not
"Who else has published this picture" needs an index of the web, and there is no honest way to do that in a browser tab - so that part of OSINT mode builds a link and stops. "Are these two pictures the same" is arithmetic on 1,024 pixels, and asking a third party to do arithmetic on a photograph of a real person is a decision made for you rather than by you. This runs here.