rhsimplex / image-match

🎇 Quickly search over billions of images
2.94k stars 405 forks source link

Question about searching #84

Open eromoe opened 6 years ago

eromoe commented 6 years ago

Hello,

I have a question about record generation. I don't understand why can set a word key like simple_word_0 and use it for search .

From code :

    def insert_single_record(self, rec):
        """Insert an image record.

        Must be implemented by derived class.

        Args:
            rec (dict): an image record. Will be in the format returned by
                make_record

                For example, rec could have the form:

                {'path': 'https://pixabay.com/static/uploads/photo/2012/11/28/08/56/mona-lisa-67506_960_720.jpg',
                 'signature': [0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 2, 2, 2, 2, 0 ... ]
                 'simple_word_0': 42252475,
                 'simple_word_1': 23885671,
                 'simple_word_10': 9967839,
                 'simple_word_11': 4257902,
                 'simple_word_12': 28651959,
                 'simple_word_13': 33773597,
                 'simple_word_14': 39331441,
                 'simple_word_15': 39327300,
                 'simple_word_16': 11337345,
                 'simple_word_17': 9571961,
                 'simple_word_18': 28697868,
                 'simple_word_19': 14834907,
                 'simple_word_2': 7434746,
                 'simple_word_20': 37985525,
                 'simple_word_21': 10753207,
                 'simple_word_22': 9566120,
                 ...
                 'metadata': {...}
                 }

                 The number of simple words corresponds to the attribute N

        """

As I see the detail implement in elasticsearch and mongodb . I found image-match's searching step is :

  1. generate words from signature
  2. convert signature into word dict { 'simple_word_0': 42252475, 'simple_word_1': 23885671, 'simple_word_10': 9967839}
  3. query for each word, get a word matched record list
  4. do signature comparison with each word matched signature , get the high score ones.

Here, what I can't understand is step 2 and 3. The word key is assign by order, how could it be match to another pic with some differences (translation or rotation). But actually image-match is doing so , the only reason I can imagine is phash could persist feature position, is that ture ?

If that is true, there come out another question: if phash could persist feature position , why not use some solution like simhash online query (http://www.wwwconference.org/www2007/papers/paper215.pdf) ?

image image

Split signature into several tables/blocks, comparison times can be reduced.