r/compsci • • Dec 24 '20

Demonstration of a reverse image search algorithm for detecting transformed images, partial images, and sub-images (link in comments)

1.0k Upvotes

28 comments sorted by

19

u/[deleted] Dec 24 '20

This demo showcases a reverse image search algorithm which performs 2D affine transformation-invariant partial image-matching in sublinear time. The algorithm compares an input image to its database of preprocessed images and determines if the input matches any image in the database. The database need not contain the original image as inputs can be matched to any 2D affine transformation of the original. This means that images which have been scaled (uniformly or non-uniformly), skewed, translated, cropped or rotated (or have undergone any combination of these transformations) can be identified as coming from the same source image.

The algorithm runs in sublinear time with respect to the number of images in the database regardless of the number of transformations applied. Note that if image-matching could not be done in sublinear time it would not function at the scale that the likes of Google or Microsoft require.

online demo: https://pippy360.github.io/transformationInvariantImageSearch/

github: https://github.com/pippy360/transformationInvariantImageSearch/

Does anyone know of other algorithms for sub-image detection, or papers on the subject?

8

u/Atom_101 Dec 24 '20

This seems like what Google uses for their reverse image search. It can find where the exact image you uploaded occurs but it cannot accurately find other images with similar information content.

I know of deep learning approaches which are obviously much slower but much more performant. Checkout the DELG model from Google. You can also look at the Google Landmark Retrieval Kaggle competitions for other approaches that people have used.

1

u/QSCFE Dec 25 '20

This seems like what Google uses for their reverse image search. It can find where the exact image you uploaded occurs but it cannot accurately find other images with similar information content.

Oh, that the reason. I thought their recent updates ruined the main search and the reverse image search algorithms, because Google is superior in finding the accurate place of origin of the image but their similarity search is so shitty, while yandex reverse search algorithm is far superior to any other search engine in finding the similar images even from very shitty image resuloation, and their similarity search is next to none.

Any paper on Google (or yandex) image's reverses algorithms they use?

2

u/Atom_101 Dec 25 '20

I was speculating. I am not sure of what Google uses, but guessed it is something like the one in this post because of its "shittiness". What Google actually uses is likely not public knowledge. Google is very secretive of its search algorithms. They say it is to prevent abuse of the search result ranking.

35

u/nekokattt Dec 24 '20

So how does it take into account varying resolutions and stuff like shitty JPEG compression artifacts over an image?

Surely if it uses a hash algorithm, (thinking of SHA-256 for example), you'd get wildly different results when you compare them.

Also, how do you know exactly what points to take on the transformed example to get the correct hash for the non transformed image? How does it take into account stuff like varying light or colourspaces?

Genuinely curious, if anyone could ELI5 this for me? Audiovisual processing isn't my strong point

47

u/[deleted] Dec 24 '20 edited Dec 24 '20

Instead of a cryptographic hash like SHA-256, a perceptual hash is used for comparing the similarity of images. In this case they use pHash. Here is an explanation of how a perceptual hash works.

It generates the keypoints using an edge detection algorithm.

7

u/nekokattt Dec 24 '20

ah okay, thanks for the link :)

2

u/merlinsbeers Dec 25 '20

How badly does the image have to be warped before the edge detection stops finding the same points?

1

u/ItzWarty Dec 25 '20 edited Dec 25 '20

You expect to have feature points flicker or be subject to noise but that's why the algorithm deals with triplets and leveraged a scale / orientation / affine transformation invariant feature detector. It's common in some other algorithms to then compute a mapping (homography) from one image to another to compute how many points match up from one image to another, and then from there you can compute a best fit on matched points to further refine your result.

3

u/FrAxl93 Dec 24 '20

How does the hash work? What if the image in the database is stored with a different color map or maybe same color map but different brightness/contrast/whatever? Equal hash means that they are equal at a bit level.

Edit: u/nekokattt has already asked this and an answer was provided :)

8

u/[deleted] Dec 24 '20

It's a perceptual hash. Similar images (different color, compression artifacts, slight cropping, etc) have similar hashes.

4

u/hawkinsst7 Dec 25 '20

I feel like "most" people are most familiar with Crypto hashes (they get all the publicity) but there are whole worlds of other areas of cs that is, in many ways, harder and interesting

2

u/Empty_Direction_3102 Dec 24 '20

So that’s how repostsleuthbot works. Nice

6

u/[deleted] Dec 24 '20

Kinda, but not this complicated. I'm pretty sure it's just generating a single perceptual hash for the entire image.

57

u/liveloveslaughter Dec 24 '20

I have often wondered how reverse searching works. Thanks for posting!

17

u/inconspicuous_male Dec 25 '20 edited Dec 27 '20

I'm a dumb little piece of shit who doesn't read.

1

u/[deleted] Dec 24 '20

Its really wonky when they start doing this for audio.

Wont just be able to slightly alter pitch or duration anymore to avoid detection

3

u/[deleted] Dec 24 '20

I think that's already being done, for things like Shazam, or for Youtube's copyright detection system.

1

u/_w1kke_ Dec 25 '20

Do you know of an open source implementation for audio?

2

u/[deleted] Dec 24 '20

Totally- but i think its still very weak?

3

u/[deleted] Dec 25 '20

Cool Kodaline!

2

u/ahmadns9 Dec 24 '20

Suddenly Illuminati

1

u/Syntaximus Dec 24 '20

So is this going to put an end to all the family guy clips on youtube?

1

u/rspktprvcybee Dec 25 '20

That’s amazing you figured that out. Explain what interested you in finding algorithms or hash cryptography or other secret math and why hide it in ways so secretive? It would be perfect for a crook like a money laundering thief who are usually the ones with that kind of time to invest brain power like that or i bet you’re a genius. That’s it I bet you’re super clever.

1

u/wjholden Dec 25 '20

Ahh wish I had understood all of this before r/adventofcode 2020 day 20!