
Perceptual hash from scratch: 32x32 pixels, one DCT, 64 bits, in Swift
Take a photo, resize it by 1 percent, and save it again. A byte hash such as SHA-256 of the two files has nothing in common. That is by design: change one bit of input and about half the output bits flip. It is the right property for checksums and the wrong one for finding near-duplicate photos. A perceptual hash wants the opposite property. Similar images should give similar hashes, so that “how different are these two images” becomes “how many bits differ between two 64-bit numbers”. ...