class_docstr: Image signature generator.
  
  Based on the method of Goldberg, et al. Available at http://www.cs.cmu.edu/~hcwong/Pdfs/icip02.ps
docstr: Generates an image signature.
  
  See section 3 of Goldberg, et al.
  
  Args:
      path_or_image (string or numpy.ndarray): image path, or image array
      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)
  
  Returns:
      The image signature: A rank 1 numpy array of length n x n x 8
          (or n x n x 4 if diagonal_neighbors == False)
  
  Examples:
      >>> from image_match.goldberg import ImageSignature
      >>> gis = ImageSignature()
      >>> gis.generate_signature('https://pixabay.com/static/uploads/photo/2012/11/28/08/56/mona-lisa-67506_960_720.jpg')
      array([ 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,  0,  0, -2,  2,  2,  1,  2,  0,  0,
              0, -2,  2, -1, -1,  2,  0,  0,  0, -2, -2, -2, -2, -1,  0,  0,  0,
              2, -1,  2,  2,  2,  0,  0,  0,  1, -1,  2,  2, -1,  0,  0,  0,  1,
              0,  2, -1,  0,  0, -2, -2,  0, -2,  0,  2,  2, -2, -2, -2,  2,  2,
              2,  2,  2, -2, -2, -2, -2, -2,  1,  2, -2, -2, -1,  1,  2,  1,  2,
             -1,  1, -2,  1,  2, -1,  2, -1,  0,  2, -2,  2, -2, -2,  1, -2,  1,
              2,  1, -2, -2, -1, -2,  1,  1, -1, -2, -2, -2,  2, -2,  2,  2,  2,
              1,  1,  0,  2,  0,  2,  2,  0,  0, -2, -2,  0,  1,  0, -1,  1, -2,
             -2, -1, -1,  1, -1,  1,  1, -2, -2, -2, -1, -2, -1,  1, -1,  2,  1,
              1,  2,  1,  2,  2, -1, -1,  0,  2, -1,  2,  2, -1, -1, -2, -1, -1,
             -2,  1, -2, -2, -1, -2, -1, -2, -1, -2, -2, -1, -1,  1, -2, -2,  2,
             -1,  1,  1, -2, -2, -2,  0,  1,  0,  1, -1,  0,  0,  1,  1,  0,  1,
              0,  1,  1, -1, -1,  1, -1,  1, -1,  1, -1, -1, -1, -2, -1, -1, -1,
             -2, -2,  1, -2, -2,  1, -2, -2, -2, -2,  1,  1,  2,  2,  1, -2, -2,
             -1,  1,  2,  2, -1,  2, -2, -1,  1,  1,  1, -1, -2, -1, -2, -2,  0,
              1, -1, -1,  1, -2, -2,  0,  1,  2,  1,  0,  2,  0,  2,  2,  0,  0,
             -1,  1,  0,  1,  0,  1,  2, -1, -1,  1, -1, -1, -1,  2,  1,  1,  2,
              2,  1, -2,  2,  2,  1,  2,  2,  2,  2, -1,  2,  2,  2,  2,  2,  2,
              1,  2,  2,  2,  2,  1,  1,  2, -2,  2,  2,  2,  2, -1,  2,  2, -2,
              2,  2,  2,  2,  0,  0, -2, -2,  1,  0, -1,  1, -1, -2,  0, -1,  0,
             -1,  1,  0,  0, -1,  1,  0,  2,  0,  2,  2, -2, -2, -2, -2, -1, -1,
             -1,  0, -1, -2, -2,  1, -1, -1,  1,  1, -1, -2, -2,  1,  1,  1,  1,
              2, -2, -2, -2, -1,  1,  1,  1,  2, -2, -2, -2, -1, -1,  0,  1,  1,
             -2, -2,  0,  1, -1,  1,  1,  1, -2,  1,  1,  1,  2,  2,  2,  2, -1,
             -1,  0, -2,  0,  0,  1,  0,  0, -2,  1,  0, -1,  0, -1, -2, -2,  1,
              1,  1,  1, -1, -1, -2,  0, -1, -1, -1, -1, -2, -2, -2, -1, -1, -1,
              1,  1, -2, -2,  1, -2, -1,  0, -1,  0, -2, -1,  1, -2, -1, -1,  0,
              0, -1,  0,  0, -1, -1, -2,  0, -1,  0,  0, -1, -1, -2,  0,  1,  1,
              1,  0,  1, -2, -1,  0, -1,  0, -1,  0,  0,  0,  1,  1,  0, -1,  0,
              2, -1,  2,  1,  2,  1, -2,  2, -1, -2,  2,  2,  2,  2,  2,  2,  2,
              2,  2,  2,  2, -2,  2,  1,  2,  2, -1,  1,  1, -2,  1, -2, -2, -1,
             -1,  0,  0, -1,  0, -2, -1, -1,  0,  0, -1,  0, -1, -1, -1, -1,  1,
              0,  1,  1,  1, -1,  0,  1, -1,  0,  0, -1,  0, -1,  0,  0,  0, -2,
             -2,  0, -2,  0,  0,  0,  1,  1, -2,  2, -2,  0,  0,  0,  2, -2, -1,
              2,  2,  0,  0,  0, -2, -2,  2, -2,  1,  0,  0,  0, -2,  2,  2, -1,
              2,  0,  0,  0,  1,  1,  1, -2,  1,  0,  0,  0,  1,  1,  1, -1,  1,
              0,  0,  0,  1,  0,  1, -1,  1,  0,  0,  0, -1,  0,  0, -1,  0,  0,
              0,  0], dtype=int8)
docstr_tok: ["Generates","an","image","signature",".","See","section","3","of","Goldberg",",","et","al",".","Args",":","path_or_image","(","string","or","numpy.ndarray",")",":","image","path",",","or","image","array","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",")","Returns",":","The","image","signature",":","A","rank","1","numpy","array","of","length","n","x","n","x","8","(","or","n","x","n","x","4","if","diagonal_neighbors","==","False",")","Examples",":",">",">",">","from","image_match.goldberg","import","ImageSignature",">",">",">","gis","=","ImageSignature","(",")",">",">",">","gis.generate_signature","(","'https",":","\/\/pixabay.com\/static\/uploads\/photo\/2012\/11\/28\/08\/56\/mona-lisa-67506_960_720.jpg","'",")","array","(","[","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",",","0",",","0",",","-2",",","2",",","2",",","1",",","2",",","0",",","0",",","0",",","-2",",","2",",","-1",",","-1",",","2",",","0",",","0",",","0",",","-2",",","-2",",","-2",",","-2",",","-1",",","0",",","0",",","0",",","2",",","-1",",","2",",","2",",","2",",","0",",","0",",","0",",","1",",","-1",",","2",",","2",",","-1",",","0",",","0",",","0",",","1",",","0",",","2",",","-1",",","0",",","0",",","-2",",","-2",",","0",",","-2",",","0",",","2",",","2",",","-2",",","-2",",","-2",",","2",",","2",",","2",",","2",",","2",",","-2",",","-2",",","-2",",","-2",",","-2",",","1",",","2",",","-2",",","-2",",","-1",",","1",",","2",",","1",",","2",",","-1",",","1",",","-2",",","1",",","2",",","-1",",","2",",","-1",",","0",",","2",",","-2",",","2",",","-2",",","-2",",","1",",","-2",",","1",",","2",",","1",",","-2",",","-2",",","-1",",","-2",",","1",",","1",",","-1",",","-2",",","-2",",","-2",",","2",",","-2",",","2",",","2",",","2",",","1",",","1",",","0",",","2",",","0",",","2",",","2",",","0",",","0",",","-2",",","-2",",","0",",","1",",","0",",","-1",",","1",",","-2",",","-2",",","-1",",","-1",",","1",",","-1",",","1",",","1",",","-2",",","-2",",","-2",",","-1",",","-2",",","-1",",","1",",","-1",",","2",",","1",",","1",",","2",",","1",",","2",",","2",",","-1",",","-1",",","0",",","2",",","-1",",","2",",","2",",","-1",",","-1",",","-2",",","-1",",","-1",",","-2",",","1",",","-2",",","-2",",","-1",",","-2",",","-1",",","-2",",","-1",",","-2",",","-2",",","-1",",","-1",",","1",",","-2",",","-2",",","2",",","-1",",","1",",","1",",","-2",",","-2",",","-2",",","0",",","1",",","0",",","1",",","-1",",","0",",","0",",","1",",","1",",","0",",","1",",","0",",","1",",","1",",","-1",",","-1",",","1",",","-1",",","1",",","-1",",","1",",","-1",",","-1",",","-1",",","-2",",","-1",",","-1",",","-1",",","-2",",","-2",",","1",",","-2",",","-2",",","1",",","-2",",","-2",",","-2",",","-2",",","1",",","1",",","2",",","2",",","1",",","-2",",","-2",",","-1",",","1",",","2",",","2",",","-1",",","2",",","-2",",","-1",",","1",",","1",",","1",",","-1",",","-2",",","-1",",","-2",",","-2",",","0",",","1",",","-1",",","-1",",","1",",","-2",",","-2",",","0",",","1",",","2",",","1",",","0",",","2",",","0",",","2",",","2",",","0",",","0",",","-1",",","1",",","0",",","1",",","0",",","1",",","2",",","-1",",","-1",",","1",",","-1",",","-1",",","-1",",","2",",","1",",","1",",","2",",","2",",","1",",","-2",",","2",",","2",",","1",",","2",",","2",",","2",",","2",",","-1",",","2",",","2",",","2",",","2",",","2",",","2",",","1",",","2",",","2",",","2",",","2",",","1",",","1",",","2",",","-2",",","2",",","2",",","2",",","2",",","-1",",","2",",","2",",","-2",",","2",",","2",",","2",",","2",",","0",",","0",",","-2",",","-2",",","1",",","0",",","-1",",","1",",","-1",",","-2",",","0",",","-1",",","0",",","-1",",","1",",","0",",","0",",","-1",",","1",",","0",",","2",",","0",",","2",",","2",",","-2",",","-2",",","-2",",","-2",",","-1",",","-1",",","-1",",","0",",","-1",",","-2",",","-2",",","1",",","-1",",","-1",",","1",",","1",",","-1",",","-2",",","-2",",","1",",","1",",","1",",","1",",","2",",","-2",",","-2",",","-2",",","-1",",","1",",","1",",","1",",","2",",","-2",",","-2",",","-2",",","-1",",","-1",",","0",",","1",",","1",",","-2",",","-2",",","0",",","1",",","-1",",","1",",","1",",","1",",","-2",",","1",",","1",",","1",",","2",",","2",",","2",",","2",",","-1",",","-1",",","0",",","-2",",","0",",","0",",","1",",","0",",","0",",","-2",",","1",",","0",",","-1",",","0",",","-1",",","-2",",","-2",",","1",",","1",",","1",",","1",",","-1",",","-1",",","-2",",","0",",","-1",",","-1",",","-1",",","-1",",","-2",",","-2",",","-2",",","-1",",","-1",",","-1",",","1",",","1",",","-2",",","-2",",","1",",","-2",",","-1",",","0",",","-1",",","0",",","-2",",","-1",",","1",",","-2",",","-1",",","-1",",","0",",","0",",","-1",",","0",",","0",",","-1",",","-1",",","-2",",","0",",","-1",",","0",",","0",",","-1",",","-1",",","-2",",","0",",","1",",","1",",","1",",","0",",","1",",","-2",",","-1",",","0",",","-1",",","0",",","-1",",","0",",","0",",","0",",","1",",","1",",","0",",","-1",",","0",",","2",",","-1",",","2",",","1",",","2",",","1",",","-2",",","2",",","-1",",","-2",",","2",",","2",",","2",",","2",",","2",",","2",",","2",",","2",",","2",",","2",",","2",",","-2",",","2",",","1",",","2",",","2",",","-1",",","1",",","1",",","-2",",","1",",","-2",",","-2",",","-1",",","-1",",","0",",","0",",","-1",",","0",",","-2",",","-1",",","-1",",","0",",","0",",","-1",",","0",",","-1",",","-1",",","-1",",","-1",",","1",",","0",",","1",",","1",",","1",",","-1",",","0",",","1",",","-1",",","0",",","0",",","-1",",","0",",","-1",",","0",",","0",",","0",",","-2",",","-2",",","0",",","-2",",","0",",","0",",","0",",","1",",","1",",","-2",",","2",",","-2",",","0",",","0",",","0",",","2",",","-2",",","-1",",","2",",","2",",","0",",","0",",","0",",","-2",",","-2",",","2",",","-2",",","1",",","0",",","0",",","0",",","-2",",","2",",","2",",","-1",",","2",",","0",",","0",",","0",",","1",",","1",",","1",",","-2",",","1",",","0",",","0",",","0",",","1",",","1",",","1",",","-1",",","1",",","0",",","0",",","0",",","1",",","0",",","1",",","-1",",","1",",","0",",","0",",","0",",","-1",",","0",",","0",",","-1",",","0",",","0",",","0",",","0","]",",","dtype=int8",")"]
code: def generate_signature(self, path_or_image, bytestream=False):
      """Generates an image signature.
  
      See section 3 of Goldberg, et al.
  
      Args:
          path_or_image (string or numpy.ndarray): image path, or image array
          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)
  
      Returns:
          The image signature: A rank 1 numpy array of length n x n x 8
              (or n x n x 4 if diagonal_neighbors == False)
  
      Examples:
          >>> from image_match.goldberg import ImageSignature
          >>> gis = ImageSignature()
          >>> gis.generate_signature('https://pixabay.com/static/uploads/photo/2012/11/28/08/56/mona-lisa-67506_960_720.jpg')
          array([ 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,  0,  0, -2,  2,  2,  1,  2,  0,  0,
                  0, -2,  2, -1, -1,  2,  0,  0,  0, -2, -2, -2, -2, -1,  0,  0,  0,
                  2, -1,  2,  2,  2,  0,  0,  0,  1, -1,  2,  2, -1,  0,  0,  0,  1,
                  0,  2, -1,  0,  0, -2, -2,  0, -2,  0,  2,  2, -2, -2, -2,  2,  2,
                  2,  2,  2, -2, -2, -2, -2, -2,  1,  2, -2, -2, -1,  1,  2,  1,  2,
                 -1,  1, -2,  1,  2, -1,  2, -1,  0,  2, -2,  2, -2, -2,  1, -2,  1,
                  2,  1, -2, -2, -1, -2,  1,  1, -1, -2, -2, -2,  2, -2,  2,  2,  2,
                  1,  1,  0,  2,  0,  2,  2,  0,  0, -2, -2,  0,  1,  0, -1,  1, -2,
                 -2, -1, -1,  1, -1,  1,  1, -2, -2, -2, -1, -2, -1,  1, -1,  2,  1,
                  1,  2,  1,  2,  2, -1, -1,  0,  2, -1,  2,  2, -1, -1, -2, -1, -1,
                 -2,  1, -2, -2, -1, -2, -1, -2, -1, -2, -2, -1, -1,  1, -2, -2,  2,
                 -1,  1,  1, -2, -2, -2,  0,  1,  0,  1, -1,  0,  0,  1,  1,  0,  1,
                  0,  1,  1, -1, -1,  1, -1,  1, -1,  1, -1, -1, -1, -2, -1, -1, -1,
                 -2, -2,  1, -2, -2,  1, -2, -2, -2, -2,  1,  1,  2,  2,  1, -2, -2,
                 -1,  1,  2,  2, -1,  2, -2, -1,  1,  1,  1, -1, -2, -1, -2, -2,  0,
                  1, -1, -1,  1, -2, -2,  0,  1,  2,  1,  0,  2,  0,  2,  2,  0,  0,
                 -1,  1,  0,  1,  0,  1,  2, -1, -1,  1, -1, -1, -1,  2,  1,  1,  2,
                  2,  1, -2,  2,  2,  1,  2,  2,  2,  2, -1,  2,  2,  2,  2,  2,  2,
                  1,  2,  2,  2,  2,  1,  1,  2, -2,  2,  2,  2,  2, -1,  2,  2, -2,
                  2,  2,  2,  2,  0,  0, -2, -2,  1,  0, -1,  1, -1, -2,  0, -1,  0,
                 -1,  1,  0,  0, -1,  1,  0,  2,  0,  2,  2, -2, -2, -2, -2, -1, -1,
                 -1,  0, -1, -2, -2,  1, -1, -1,  1,  1, -1, -2, -2,  1,  1,  1,  1,
                  2, -2, -2, -2, -1,  1,  1,  1,  2, -2, -2, -2, -1, -1,  0,  1,  1,
                 -2, -2,  0,  1, -1,  1,  1,  1, -2,  1,  1,  1,  2,  2,  2,  2, -1,
                 -1,  0, -2,  0,  0,  1,  0,  0, -2,  1,  0, -1,  0, -1, -2, -2,  1,
                  1,  1,  1, -1, -1, -2,  0, -1, -1, -1, -1, -2, -2, -2, -1, -1, -1,
                  1,  1, -2, -2,  1, -2, -1,  0, -1,  0, -2, -1,  1, -2, -1, -1,  0,
                  0, -1,  0,  0, -1, -1, -2,  0, -1,  0,  0, -1, -1, -2,  0,  1,  1,
                  1,  0,  1, -2, -1,  0, -1,  0, -1,  0,  0,  0,  1,  1,  0, -1,  0,
                  2, -1,  2,  1,  2,  1, -2,  2, -1, -2,  2,  2,  2,  2,  2,  2,  2,
                  2,  2,  2,  2, -2,  2,  1,  2,  2, -1,  1,  1, -2,  1, -2, -2, -1,
                 -1,  0,  0, -1,  0, -2, -1, -1,  0,  0, -1,  0, -1, -1, -1, -1,  1,
                  0,  1,  1,  1, -1,  0,  1, -1,  0,  0, -1,  0, -1,  0,  0,  0, -2,
                 -2,  0, -2,  0,  0,  0,  1,  1, -2,  2, -2,  0,  0,  0,  2, -2, -1,
                  2,  2,  0,  0,  0, -2, -2,  2, -2,  1,  0,  0,  0, -2,  2,  2, -1,
                  2,  0,  0,  0,  1,  1,  1, -2,  1,  0,  0,  0,  1,  1,  1, -1,  1,
                  0,  0,  0,  1,  0,  1, -1,  1,  0,  0,  0, -1,  0,  0, -1,  0,  0,
                  0,  0], dtype=int8)
  
      """
  
      # Step 1:    Load image as array of grey-levels
      im_array = self.preprocess_image(
          path_or_image,
          handle_mpo=self.handle_mpo,
          bytestream=bytestream,
      )
  
      # Step 2a:   Determine cropping boundaries
      if self.crop_percentiles is not None:
          image_limits = self.crop_image(
              im_array,
              lower_percentile=self.lower_percentile,
              upper_percentile=self.upper_percentile,
              fix_ratio=self.fix_ratio,
          )
      else:
          image_limits = None
  
      # Step 2b:   Generate grid centers
      x_coords, y_coords = self.compute_grid_points(
          im_array, n=self.n, window=image_limits
      )
  
      # Step 3:    Compute grey level mean of each P x P
      #           square centered at each grid point
      avg_grey = self.compute_mean_level(
          im_array, x_coords, y_coords, P=self.P
      )
  
      # Step 4a:   Compute array of differences for each
      #           grid point vis-a-vis each neighbor
      diff_mat = self.compute_differentials(
          avg_grey, diagonal_neighbors=self.diagonal_neighbors
      )
  
      # Step 4b: Bin differences to only 2n+1 values
      self.normalize_and_threshold(
          diff_mat,
          identical_tolerance=self.identical_tolerance,
          n_levels=self.n_levels,
      )
  
      # Step 5: Flatten array and return signature
      return np.ravel(diff_mat).astype("int8")
  
imports: from skimage.color import rgb2gray
  from skimage.io import imread
  from PIL import Image
  from PIL.MpoImagePlugin import MpoImageFile
  from six import string_types, text_type
  from io import BytesIO
  import numpy
  import xml.etree
  import xml.etree.ElementTree
label_desc: Use image node_id 2 for calling the ImageSignature obj's underlying member method code with example usage: obj.generate_signature(path_or_image, bytestream) and returns: np