H
H
HaruAtari2014-03-10 21:34:20
PostgreSQL
HaruAtari, 2014-03-10 21:34:20

POSTGRES: how to search for similar images using phash?

Good evening.
Somehow I was interested in the question of searching for similar images: Compare images and search for similar ones?
The bottom line is this: the site stores images, the data of which is in the database. When a new image is uploaded, its phash is calculated and records with a small deviation are searched in the database. There are none - it means the image is new and has not been loaded before.
I found how to count phash. Java implementation: pastebin.com/Pj9d8jt5
I find the hash. But how to store hashes and how to search by Hamming distance?
Actually, that's what is not clear:
1. Store as a string or is there a more suitable format, provided that there are only ones and zeros?
2. How to search? Roughly speaking:

select * from tbl_iamge where hammingDistance(<мой хеш>, hash) < <минимальное допустимое различие>
Is there a built-in operator for such calculations or do I need to write my own function?
3. How to build an index on this field? Do I need to use a functional index on this function, or are there other means?
I am very poorly versed in this topic. Therefore, I will be glad to any advice.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuri Morozov, 2014-03-10
@metamorph

Like this: pgsimilarity.projects.pgfoundry.org

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question