7 ms·
How Perceptual Hashes Work
- michaeldhopkins 15y agoThank you, I learned something. Since TinEye pre-computes the hashes, do they use something like Redis to retrieve information? Redis seems perfect for a such quick results using the hash as the key and a URL or object of some kind as the value.
- barrkel 15y agoIt seems to me that what you want is some kind of spatial index - you might not get an exact match on the hash, but instead get one that's one or two bits away, and you'll want something better than linear search to find it.
- cemerick 15y agoDoesn't scaling the images down (to 32x32 for the pHash approach) achieve essentially the same thing? Images that differ only slightly will likely scale down to the same thumbnail to begin with, and the resulting hash still bears some relationship to that thumbnail — so you should be able to look at similar hashes to find similar inputs.
- jbri 15y agoOften you get things like images that have had text added to them (e.g. I often use tineye to find the original source image that someone has added a caption to), which means that the thumbnails will differ to some degree.
- barrkel 15y agoThat's exactly what I'm saying - a simple index will only find exact hash matches, but what you want is images with "similar" hashes. If you define "similar" as a low Hamming distance - i.e. a small number of bit differences - and you want to find these image hashes with something better than a linear search / exhaustive combinatorial bit-twiddling, then you'll need to be smarter about your index.
- cdavid 15y agoThat would be a good idea as along as you have a good distance between images (d(image1, image2) small equivalent to image1 and image2 are equivalent). I have little experience in image processing, but this is generally a hard problem with complex signals (as images, music and speech are). Most of what is described in the article concerns dimension reduction, where the goal overlaps with the above.
- barrkel 15y agoThe article explicitly mentions Hamming distance, which is also what I mean by bit distance.
- cdavid 15y agoYes, but his remarks suggests that hamming distance is not very nice for pictures after his transformation (d(i1, i2) == 5 -> small, d(i1, i2) == 10 -> big). As I am not familiar with image signals, I don't know if this can be somehow mitigated with other techniques. Of course, the only way to be sure would be to actually test it, but I would not bet much on it. Another issue I forgot to mention is that each "point" (image ) is a k-dimensional vector. Organizing those so that to easily retrieve points which are close to each other quickly becomes intractable. Conventional techniques like kd-trees quickly break down when k is above a few units, because of the curse of dimensionality. This introduces a "non-linearity" in your distance which makes comparing points in a k-dimension space quite different than in 2/3 dimension spaces.
- jamii 15y agoIn the case of Hamming distance there is much more information to work with than in a bare metric. You can dump all the bitstrings into a suffix array, break the query into K pieces and search for an exact match for each piece. The resulting list of matches is usually small enough to just compute the Hamming distance against each element. I've used this on a corpus of 2m LaTeX strings withbgood results. See my above post for more details.
- jamii 15y agoHere is a good overview of existing approaches to approximate sequence matching - http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.96.7225&rep=rep1&type=pdf http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.96.... . I also wrote in a fair bit of detail about solving the similar problem of searching through LaTeX syntax trees - http://scattered-thoughts.net/one/1291/799313/731344 http://scattered-thoughts.net/one/1291/799313/731344 . Adapting my code to searching by Hamming distance should be trivial should anyone want to play around with image searches.
- kenjackson 15y agoThat was one of the best articles I've read in a while.
- andrewflnr 15y agoWow, I had no idea it was so easy. Could this in fact be used to combat copyright infringement for the likes of The Oatmeal on large scale, given someone (Google) with the requisite computing power?
- gsmaverick 15y agoFrom the looks of it this is actually TinEye's main commercial activity, they merely expose the search interface to demonstrate their technology.
- mail2345 15y agoFor that specific situation, this wouldn't help too much, seeing as the up-loaders are already removing source info, so it's reasonable to assume they will fudge the image somehow to change the hash value.
- mdonahoe 15y ago"I'll use a picture of my next wife, Alyson Hannigan." That had me doing a few google searches.
- joshu 15y agoSee also SIFT
- copper 15y agoIsn't SiFT still patented, though?
- deleted 15y ago[deleted]
- tsewlliw 15y agoThat is completely brilliant! I want to go out and write a image diff viewer that uses this on blobs in the image to detect pieces moving around!
- zackattack 15y agoI don't understand? :)
- tsewlliw 15y agoso you have a before and after image, say a webpage mockup thats where the logo moved from top left to top right. the blob finder finds the interesting pieces of each version, and the perceptual hash picks which blobs match each other, and the software can say with reasonable certainty that the top left part of the image was moved to top right. don't eat my lunch :)
- piotrSikora 15y agoThis reminds me of OpenSSH's fingerprint visualization support ("VisualHostKey yes"): $ ssh A.B.C.D Host key fingerprint is b0:c9:c9:96:fb:fd:ac:a4:ff:70:8f:1b:35:f4:f9:2e +--[ECDSA 256]---+ | | | | | . . | | o * . ..| | O S o..| | . . . ..| | . o o .| | . + + +E. | | o.++*....| +-----------------+ me@A.B.C.D's password: Original article introducing this feature: http://www.undeadly.org/cgi?action=article&sid=20080615022750 http://www.undeadly.org/cgi?action=article&sid=200806150... (2008/06/26).
- wickedchicken 15y agoThis is pretty much the opposite from what the article is talking about -- the article is trying to get a hash from an image in order to compare that image to another, while you're talking about synthesizing an image from an arbitrary hash...
- piotrSikora 15y agoHence "reminds me" :)
- killerswan 15y agoWell, one could use a variation of this technique to compare tons of other things... Music?
- bct 15y agohttp://musicbrainz.org/doc/Audio_Fingerprint http://musicbrainz.org/doc/Audio_Fingerprint The Picard MP3 tagger uses this kind of thing (and MusicBrainz' database of tracks and audio fingerprints) to identify files.
- neworbit 15y agoI can't be the only one who thinks "This looks like the visualization algorithm is nethack"
- wickedchicken 15y agoThe two main problems with this approach is it is not rotation-invariant and it does not work well if the image is damaged or added to. A more robust system (that, admittedly, will take longer) is to use one of the affine-invariant feature detection algorithms pioneered by SIFT. SURF is a faster, open-sourced version of SIFT that has many implementations. Essentially it scans chunks of the image at different scales and identifies features that peak even as the chunk around it gets bigger. Once these are identified, they are described in a way forcing them to the same size and orientation for lookup. Since these features should presumably be scattered throughout the image, the image can be recognized even if certain features are obscured or modified. It's certainly not as straight-forward as a DCT metric on a downsampled image, but the nature of widespread image capture, creation and manipulation usually requires this robustness.
- wickedchicken 15y agoAs a followup (and this is rather unrelated to the original post), you can combine a feature detector with a statistical clustering algorithm to automatically identify the generic visual properties of objects in an unsupervised manner. One of the first papers attempting this is http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.72.2610&rep=rep1&type=pdf http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.72.... but many have followed it. From what I understand these still simply check for the existence of features in an image instead of their spatial relationship ('a picture of a cat has two ears, a tail, and a blob for a body' versus 'a picture of a cat has two ears positioned on the end of a blob with a tail on the other end of the blob'). Nevertheless, they represent the current state-of-the-art in automatic object classification and recognition algorithms.
- sigil 15y agoI went to a talk by Yann LeCun [1] a few months back, "Learning Feature Hierarchies for Vision." The current state of the art in this field is mind-blowing to an outsider. The final demo was a program that he trained in a matter of seconds to recognize and distinguish faces of various random audience members, in real time, from different viewing angles. [1] http://yann.lecun.com/ http://yann.lecun.com/
- seanalltogether 15y agoI've always wondered how services like Shazam work. I'm amazed that they can do this kind of perceptual hash against ANY 10 second portion of a song. How do they search against something like that when they don't know the start or end time of the segment that is being input?
- kenjackson 15y agoFor pop/rock/rap music it probably doesn't matter. For classical, I'm not sure.
- thesz 15y agoI think you just suggested that classical music is all the same.
- kenjackson 15y agoI meant to suggest the near opposite. That with pop/rock/rap, a 10s chunk is enough to get a signature for the wole piece. While for classical, the music changes enough that any 10s chunk may not respesent adequately a different 10s chunk.
- T_S_ 15y agoYes the delta part is clever. Shazam is well described here: www.ee.columbia.edu/~dpwe/papers/Wang03-shazam.pdf
- stevetjoa 15y agoI do research in music information retrieval. See the ISMIR 2003 paper below. In short, it searches for landmarks in the spectrogram, hashes those landmarks, then compares those hashes against database hashes for temporal continuity. http://www.ee.columbia.edu/~dpwe/papers/Wang03-shazam.pdf http://www.ee.columbia.edu/~dpwe/papers/Wang03-shazam.pdf A seminal paper on audio fingerprinting is the one by Haitsma and Kalker. http://ismir2002.ismir.net/proceedings/02-fp04-2.pdf http://ismir2002.ismir.net/proceedings/02-fp04-2.pdf
- noblethrasher 15y ago"With pictures, high frequencies give you detail, while low frequencies show you structure." I have a vague idea of what this means but can someone please explain it in a bit more detail?
- sesqu 15y agoI believe he's referring to the DCT transform, in which the image is interpreted as a mixture of sinusoidal waves. Low frequencies then correspond to differences between separate areas of the picture, while high frequencies correspond to texture. I'm not a big fan of the periodic transforms, but they do have that nice perceptual interpretation.
- joshu 15y agoOk, I'll take a shot at this. Let's work in one dimension rather than two dimensions. It's easy enough to extend later. You know that a any signal is the sum of a (potentially infinite) number of sine waves. For example, a square wave is the sum of ever higher-frequency (but smaller-amplitude) sine waves. The higher frequencies are necessary to get the sharp edges. If you strip the high frequencies, the sharp edges dissapear, leaving only the larger motions of the lower-frequency (yet bigger amplitude) waves. So the low frequencies are the hill, and the high frequencies are the grass. Does that make sense? Edit: Here's an image: http://cnx.org/content/m0041/latest/fourier4.png http://cnx.org/content/m0041/latest/fourier4.png
- noblethrasher 15y agoThanks, that is a bit more helpful.
- zackattack 15y agoanother way i like to think of it (someone please correct me if i'm wrong) is that high-frequency means high-detail (highly frequently needing information to specify how it looks) whereas low-frequency means low-detail (is that completely off or is it an analogous transform?)
- NickC_dev 15y agoThere's a publicly available implementation of a perceptual hashing algorithm called phash at http://phash.org http://phash.org. I use some of their c++ code to detect reposts on an image sharing site I run (http://lolstack.com http://lolstack.com).
- pavel_lishin 15y agoCould you add RSS?
- NickC_dev 15y agoIt's definitely on my summer to-do list. You're the first person to ask.
- buddydvd 15y agoIsn't tineye's signature algorithm based on Fourier transform? http://www.reddit.com/r/programming/comments/bvmln/how_does_tineye_work/c0os84n http://www.reddit.com/r/programming/comments/bvmln/how_does_...
- icegreentea 15y agoAs the post notes, that algorithm is great at matching, but sucks at searching. Hashes on the other hand are probably better off at matching. My guess is that you use some variation of hashing to get a set of candidate images, and then do more detailed examinations.
- iandanforth 15y agoI have a feeling there is a deep connection between perceptual hashes and compressed sensing. Could someone more familiar with the latter weigh in?
- stevetjoa 15y agoKinda sorta not really. Compressed sensing and sparse coding show that, under certain sparsity assumptions, you can perfectly reconstruct your original data with fewer bits than previously thought. It is a coding principle. Perceptual hashes (or hashes in general) are used for fast indexing and retrieval. You cannot recreate the original data from a hash, pretty much by definition. So hashes and coding algorithms both provide smaller representations of data. But hashes are used for indexing and do not provide the original data, or even an approximation thereof, while compressed sensing can.
- mjb 15y agoThe key thing here is that compressed sensing is an attempt to throw away redundant data as early as possible in the process. Any data which is redundant in the actual data stream, or can be inferred from prior knowledge about the stream does not need to be measured. Perceptual hashing is instead an attempt to make the matching problem easier by throwing away data that is seen as irrelevant. In the case of the described algorithm, low frequencies are chosen as relevant and high frequencies as irrelevant. As you point out, this involves losing the ability to recover the original signal and adds the risk of mismatching in cases where data thought to be irrelevant to the task is actually relevant.
- iandanforth 15y agoIf we take the principles from compressed sensing and use a random-lens approach to subsampling the original image, we can create a fingerprint of the image which also happens to be able to reconstruct the original. Both techniques are compressions that rely on the sparse properties of images to devine which bits are meaningful and which are redundant. It appears to me that using compressed sensing is just a smarter way of doing it. Maybe a hash that starts with a random subsample is inherently slower for comparing millions of images, but I shouldn't think so.
- stevetjoa 15y agoIf you're interested in this article, then you may interested in locality sensitive hashing (LSH), a randomized hash that has been used seemingly everywhere. I recently used it to speed up music source separation (papers pending). The idea is similar to the one mentioned in this article, but more general. Unlike a cryptographically secure hash where x != y implies that h(x) != h(y) (collisions aside), LSH says that if x and y are "near", then P(h(x) = h(y)) is "high". This quality is important when doing robust similarity search. For example, if your image is noisy or rotated or scaled, you hope that you can still find the clean version in a database. LSH has been used in many application domains including images, video, music, text, bioinformatics, and more. LSH is not directly comparable to a feature extraction algorithm such as SIFT. [Edited for clarity.]
- cemerick 15y agoThank you for that term. LSH looks like a very useful technique.
- there 15y agolibpuzzle is good for this type of work: http://libpuzzle.pureftpd.org/project/libpuzzle http://libpuzzle.pureftpd.org/project/libpuzzle
- tobylane 15y agoTineye must take this so much further, one image I looked up was about half of one of the pictures returned, I think it was in a page of a book. From the reddit link further down - "A Fourier transform takes a signal in the time domain and breaks it down into its frequency components. Simplified, it takes a CD and produces sheet music.", "To be clear, OP says this is a matching algorithm - it's not what tineye uses, because matching the signature from the searched-for image with the database of previous signatures which is probably a nightmare."
- zackattack 15y agoI don't understand why compressing an image is going to generate the same 8x8 image each time no matter what aspect ratio it was originally... whether it has been stretched before.. If you stretch and then recompress a bunch of times don't you eventually lose the information? That math is for some reason totally counter-intuitive to me. Could someone do a proof?
- bryanh 15y agoFrom my understanding, its not a md5 hash or equivalent. Its just encoding the 64 bits to a "hash" thus allowing a fuzzy comparison between hashes. Someone correct me if I am wrong. Obviously, this isn't robust enough to find all matches. A simple cropping would throw it completely off.
- CountHackulus 15y agoThis is really interesting, but I'm sad that they skip over the step "convert to grayscale." There's a ton of ways to convert an image to grayscale, each with their own pros and cons. How do you weight each channel? Do you convert to HSL and just use L? Do you instead use Lab? HSV? Do you do a global or local algorithm? So many questions!
- mdaniel 15y agoIt was my understanding that (for a lot of the steps) it does not matter what mechanism you use, so long as you use the same one. The problem you are addressing would matter if someone were trying to query TinyEye's database without submitting the image to TinyEye's servers.
- krisw 15y agoWhat a fascinating topic, it's too bad that Gazopa (mentioned at the end of the article) just announced that they're shutting down their CBIR service: http://gazopablog.blogspot.com/2011/05/shut-down-notice-from-gazopa.html http://gazopablog.blogspot.com/2011/05/shut-down-notice-from...