class_docstr: Base class for storing and searching image signatures in a database
  
  Note:
      You must implement the methods search_single_record and insert_single_record
      in a derived class
docstr: Search for matches
  
  Args:
      path (string): path or image data. If bytestream=False, then path is assumed to be
          a URL or filesystem path. Otherwise, it's assumed to be raw image data
      all_orientations (Optional[boolean]): if True, search for all combinations of mirror
          images, rotations, and color inversions (default False)
      bytestream (Optional[boolean]): will the image be passed as raw bytes?
          That is, is the 'path_or_image' argument an in-memory image?
          (default False)
      pre_filter (Optional[dict]): filters list before applying the matching algorithm
          (default None)
  Returns:
      a formatted list of dicts representing unique matches, sorted by dist
  
      For example, if three matches are found:
  
      [
       {'dist': 0.069116439263706961,
        'id': u'AVM37oZq0osmmAxpPvx7',
        'path': u'https://pixabay.com/static/uploads/photo/2012/11/28/08/56/mona-lisa-67506_960_720.jpg'},
       {'dist': 0.22484320805049718,
        'id': u'AVM37nMg0osmmAxpPvx6',
        'path': u'https://upload.wikimedia.org/wikipedia/commons/thumb/e/ec/Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg/687px-Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg'},
       {'dist': 0.42529792112113302,
        'id': u'AVM37p530osmmAxpPvx9',
        'path': u'https://c2.staticflickr.com/8/7158/6814444991_08d82de57e_z.jpg'}
      ]
docstr_tok: ["Search","for","matches","Args",":","path","(","string",")",":","path","or","image","data",".","If","bytestream=False",",","then","path","is","assumed","to","be","a","URL","or","filesystem","path",".","Otherwise",",","it","'s","assumed","to","be","raw","image","data","all_orientations","(","Optional","[","boolean","]",")",":","if","True",",","search","for","all","combinations","of","mirror","images",",","rotations",",","and","color","inversions","(","default","False",")","bytestream","(","Optional","[","boolean","]",")",":","will","the","image","be","passed","as","raw","bytes","?","That","is",",","is","the","'path_or_image","'","argument","an","in-memory","image","?","(","default","False",")","pre_filter","(","Optional","[","dict","]",")",":","filters","list","before","applying","the","matching","algorithm","(","default","None",")","Returns",":","a","formatted","list","of","dicts","representing","unique","matches",",","sorted","by","dist","For","example",",","if","three","matches","are","found",":","[","{","'dist","'",":","0.069116439263706961",",","'id","'",":","u'AVM37oZq0osmmAxpPvx7","'",",","'path","'",":","u'https",":","\/\/pixabay.com\/static\/uploads\/photo\/2012\/11\/28\/08\/56\/mona-lisa-67506_960_720.jpg","'","}",",","{","'dist","'",":","0.22484320805049718",",","'id","'",":","u'AVM37nMg0osmmAxpPvx6","'",",","'path","'",":","u'https",":","\/\/upload.wikimedia.org\/wikipedia\/commons\/thumb\/e\/ec\/Mona_Lisa",",","_by_Leonardo_da_Vinci",",","_from_C2RMF_retouched.jpg\/687px-Mona_Lisa",",","_by_Leonardo_da_Vinci",",","_from_C2RMF_retouched.jpg","'","}",",","{","'dist","'",":","0.42529792112113302",",","'id","'",":","u'AVM37p530osmmAxpPvx9","'",",","'path","'",":","u'https",":","\/\/c2.staticflickr.com\/8\/7158\/6814444991_08d82de57e_z.jpg","'","}","]"]
code: def search_image(
      self,
      path,
      all_orientations=False,
      bytestream=False,
      pre_filter=None,
  ):
      """Search for matches
  
      Args:
          path (string): path or image data. If bytestream=False, then path is assumed to be
              a URL or filesystem path. Otherwise, it's assumed to be raw image data
          all_orientations (Optional[boolean]): if True, search for all combinations of mirror
              images, rotations, and color inversions (default False)
          bytestream (Optional[boolean]): will the image be passed as raw bytes?
              That is, is the 'path_or_image' argument an in-memory image?
              (default False)
          pre_filter (Optional[dict]): filters list before applying the matching algorithm
              (default None)
      Returns:
          a formatted list of dicts representing unique matches, sorted by dist
  
          For example, if three matches are found:
  
          [
           {'dist': 0.069116439263706961,
            'id': u'AVM37oZq0osmmAxpPvx7',
            'path': u'https://pixabay.com/static/uploads/photo/2012/11/28/08/56/mona-lisa-67506_960_720.jpg'},
           {'dist': 0.22484320805049718,
            'id': u'AVM37nMg0osmmAxpPvx6',
            'path': u'https://upload.wikimedia.org/wikipedia/commons/thumb/e/ec/Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg/687px-Mona_Lisa,_by_Leonardo_da_Vinci,_from_C2RMF_retouched.jpg'},
           {'dist': 0.42529792112113302,
            'id': u'AVM37p530osmmAxpPvx9',
            'path': u'https://c2.staticflickr.com/8/7158/6814444991_08d82de57e_z.jpg'}
          ]
  
      """
      img = self.gis.preprocess_image(path, bytestream)
  
      if all_orientations:
          # initialize an iterator of composed transformations
          inversions = [lambda x: x, lambda x: -x]
  
          mirrors = [lambda x: x, np.fliplr]
  
          # an ugly solution for function composition
          rotations = [
              lambda x: x,
              np.rot90,
              lambda x: np.rot90(x, 2),
              lambda x: np.rot90(x, 3),
          ]
  
          # cartesian product of all possible orientations
          orientations = product(inversions, rotations, mirrors)
  
      else:
          # otherwise just use the identity transformation
          orientations = [lambda x: x]
  
      # try for every possible combination of transformations; if all_orientations=False,
      # this will only take one iteration
      result = []
  
      orientations = set(np.ravel(list(orientations)))
      for transform in orientations:
          # compose all functions and apply on signature
          transformed_img = transform(img)
  
          # generate the signature
          transformed_record = make_record(
              transformed_img, self.gis, self.k, self.N
          )
  
          l = self.search_single_record(
              transformed_record, pre_filter=pre_filter
          )
          result.extend(l)
  
      ids = set()
      unique = []
      for item in result:
          if item["id"] not in ids:
              unique.append(item)
              ids.add(item["id"])
  
      r = sorted(unique, key=itemgetter("dist"))
      return r
  
file_path: image-match/image_match/signature_database_base.py
imports: from image_match.goldberg import ImageSignature
  from itertools import product
  from operator import itemgetter
  import numpy
label_desc: Use image node_id 5 for calling the SignatureDatabaseBase obj's underlying member method code with example usage: obj.search_image(path, all_orientations, bytestream, pre_filter) and returns: r