KDJDEV/imagehash-reverse-image-search-tutorial

Does this code gives 1 image as a response?

mehrdadasadiut opened this issue · 2 comments

Hello.
I am looking for a way that if I pass an image, it finds the most similar one from the database.
Does this works by this code?

Yes, this article can help you do exactly that. In the literal code in the article, there is nothing that prevents you from getting more than one match(all images that are similar will be returned). However, if you increase the maximumHammingDistance that I talk about in the article, you should be able to fine tune things so that you only get one image back(as long as you don't have duplicate images in your database).

You could also hard limit Postgres to return only one match by using a limit 1 with your queries.

For example:

SELECT url FROM hashes WHERE hash <@ (hashInt, maximumHammingDistance) limit 1;

where you replace hashInt and maximumHammingDistance with your desired values as I explain in the article.

I thought I should also mention, since you asked if you can find the "most" similar image, that the pg-spgist_hamming extension used in this tutorial does not sort values by how good of a match they are.

fake-name/pg-spgist_hamming#10

So you'll probably need to use the methods I already mentioned.