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: Initialize the signature generator.
  
  The default parameters match those given in Goldberg's paper.
  
  Note:
      Non-default parameters have not been extensively tested. Use carefully.
  
  Args:
      n (Optional[int]): size of grid imposed on image. Grid is n x n (default 9)
      crop_percentiles (Optional[Tuple[int]]): lower and upper bounds when considering how much
          variance to keep in the image (default (5, 95))
      P (Optional[int]): size of sample region, P x P. If none, uses a sample region based
          on the size of the image (default None)
      diagonal_neighbors (Optional[boolean]): whether to include diagonal grid neighbors
          (default True)
      identical_tolerance (Optional[float]): cutoff difference for declaring two adjacent
          grid points identical (default 2/255)
      n_levels (Optional[int]): number of positive and negative groups to stratify neighbor
          differences into. n = 2 -> [-2, -1, 0, 1, 2] (default 2)
docstr_tok: ["Initialize","the","signature","generator",".","The","default","parameters","match","those","given","in","Goldberg","'s","paper",".","Note",":","Non-default","parameters","have","not","been","extensively","tested",".","Use","carefully",".","Args",":","n","(","Optional","[","int","]",")",":","size","of","grid","imposed","on","image",".","Grid","is","n","x","n","(","default","9",")","crop_percentiles","(","Optional","[","Tuple","[","int","]","]",")",":","lower","and","upper","bounds","when","considering","how","much","variance","to","keep","in","the","image","(","default","(","5",",","95",")",")","P","(","Optional","[","int","]",")",":","size","of","sample","region",",","P","x","P.","If","none",",","uses","a","sample","region","based","on","the","size","of","the","image","(","default","None",")","diagonal_neighbors","(","Optional","[","boolean","]",")",":","whether","to","include","diagonal","grid","neighbors","(","default","True",")","identical_tolerance","(","Optional","[","float","]",")",":","cutoff","difference","for","declaring","two","adjacent","grid","points","identical","(","default","2\/255",")","n_levels","(","Optional","[","int","]",")",":","number","of","positive","and","negative","groups","to","stratify","neighbor","differences","into",".","n","=","2","-",">","[","-2",",","-1",",","0",",","1",",","2","]","(","default","2",")"]
code: def __init__(
      self,
      n=9,
      crop_percentiles=(5, 95),
      P=None,
      diagonal_neighbors=True,
      identical_tolerance=2 / 255.0,
      n_levels=2,
      fix_ratio=False,
  ):
      """Initialize the signature generator.
  
      The default parameters match those given in Goldberg's paper.
  
      Note:
          Non-default parameters have not been extensively tested. Use carefully.
  
      Args:
          n (Optional[int]): size of grid imposed on image. Grid is n x n (default 9)
          crop_percentiles (Optional[Tuple[int]]): lower and upper bounds when considering how much
              variance to keep in the image (default (5, 95))
          P (Optional[int]): size of sample region, P x P. If none, uses a sample region based
              on the size of the image (default None)
          diagonal_neighbors (Optional[boolean]): whether to include diagonal grid neighbors
              (default True)
          identical_tolerance (Optional[float]): cutoff difference for declaring two adjacent
              grid points identical (default 2/255)
          n_levels (Optional[int]): number of positive and negative groups to stratify neighbor
              differences into. n = 2 -> [-2, -1, 0, 1, 2] (default 2)
  
      """
  
      # check inputs
      assert (
          crop_percentiles is None or len(crop_percentiles) == 2
      ), "crop_percentiles should be a two-value tuple, or None"
      if crop_percentiles is not None:
          assert crop_percentiles[0] >= 0, (
              "Lower crop_percentiles limit should be > 0 (%r given)"
              % crop_percentiles[0]
          )
          assert crop_percentiles[1] <= 100, (
              "Upper crop_percentiles limit should be < 100 (%r given)"
              % crop_percentiles[1]
          )
          assert (
              crop_percentiles[0] < crop_percentiles[1]
          ), "Upper crop_percentile limit should be greater than lower limit."
          self.lower_percentile = crop_percentiles[0]
          self.upper_percentile = crop_percentiles[1]
          self.crop_percentiles = crop_percentiles
      else:
          self.crop_percentiles = crop_percentiles
          self.lower_percentile = 0
          self.upper_percentile = 100
  
      assert type(n) is int, "n should be an integer > 1"
      assert n > 1, "n should be greater than 1 (%r given)" % n
      self.n = n
  
      assert (
          type(P) is int or P is None
      ), "P should be an integer >= 1, or None"
      if P is not None:
          assert P >= 1, "P should be greater than 0 (%r given)" % n
      self.P = P
  
      assert (
          type(diagonal_neighbors) is bool
      ), "diagonal_neighbors should be boolean"
      self.diagonal_neighbors = diagonal_neighbors
      self.sig_length = self.n**2 * (4 + self.diagonal_neighbors * 4)
  
      assert type(fix_ratio) is bool, "fix_ratio should be boolean"
      self.fix_ratio = fix_ratio
  
      assert (
          type(identical_tolerance) is float
          or type(identical_tolerance) is int
      ), "identical_tolerance should be a number between 1 and 0"
      assert 0.0 <= identical_tolerance <= 1.0, (
          "identical_tolerance should be greater than zero and less than one (%r given)"
          % identical_tolerance
      )
      self.identical_tolerance = identical_tolerance
  
      assert type(n_levels) is int, "n_levels should be an integer"
      assert n_levels > 0
      "n_levels should be > 0 (%r given)" % n_levels
      self.n_levels = n_levels
  
      self.handle_mpo = True
  
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 1 to create a new ImageSignature object from inherited base classes: object with example: obj = ImageSignature(n, crop_percentiles, P, diagonal_neighbors, identical_tolerance, n_levels, fix_ratio)