r/computerscience • u/jeesuscheesus • Aug 15 '25
Discussion "soft hashes" for image files that produce the same value if the image is slightly modified?
An image can be digitally signed to prove ownership and prevent tampering. However, lowering the resolution, or extracting from a lossy compression algorithm, or slightly cropping the image would invalidate the signing. This is because the cryptographic hashing algorithms we use for signing are too perfect. Are there hash algorithms designed for images that produce the same output for an image if it's slightly modifed but still the same image within reason?
78
Upvotes
39
u/CowRepresentative820 Aug 15 '25
Lookup perceptual hashing. Some examples
- https://github.com/coenm/ImageHash
- https://github.com/abonander/img_hash
26
u/blacksteel15 Aug 15 '25
Yes. The technical term for this in general is "fuzzy hashing". The term for applying this to multimedia to solve that particular problem is "perceptual hashing".
10
u/Llotekr Aug 15 '25
I wrote my master and doctor thesis on something similar. I used eigenvalue spectra of Laplacians modified in an image dependent way, so that similar sub-images would lead to similar subsets of eigenvalues in the spectrum.
But you asked for a hash function producing "the same output" for similar images. In general, that is not possible, because you can interpolate between very different images gradually, and at one point, the change has to occur. Maybe you want an intelligent choice of where these boundaries are? Then you need some kind of AI-based perceptual hash, and even then it will not work in all cases.
7
u/Headsanta Aug 15 '25
"Locality sensitive hashing" is one strategy.
You can define a distance function on the images (similarity score of some type), and then makes the guarantee that the probability of a hashing collision is inversely proportional to the "distance" between two images.
This is a naive way to make image search, because comparing images can be very expensive (for nxn images it could easily be n3 steps to compare them, and then you have to multiply again by some big number of images k). Instead if you do this locality sensitive hash first, you lose the guarantee that you will find all similar images, but the images you are checking in more detail have a much higher likelihood to be similar to the image you are comparing.
2
u/Prcrstntr Aug 15 '25
Yes, and such technologies are used to detect illegal content, such as CSAM.
2
u/TeesCDF Aug 16 '25
PhotoDNA may be what you’re looking for here
1
u/[deleted] Aug 16 '25
How could you define what enough of a change is enough to require a new hash?
1
u/riotinareasouthwest Aug 16 '25
From hashing perspective, an image file is just raw binary file. What you call slightly modified may generate a complete different binary file, for instance, if you change the resolution you get different file size; or changing the color depth from 32 to 24 bits. I'm not sure you will find something that matches your needs.
1
u/barbidokski Aug 17 '25
There is many kind of whats called "Perceptual Hash", but instead of beeing invariant to soft transformations, the hash changes but slightly too. There is a kind of "morphism", if a distance between 2 images is short, the distance between their hashes will be short too.