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: Loads an image and converts to greyscale.
  
  Corresponds to 'step 1' in Goldberg's paper
  
  Args:
      image_or_path (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)
      handle_mpo (Optional[boolean]): try to compute a signature for steroscopic
          images by extracting the first image of the set (default False)
  
  Returns:
      Array of floats corresponding to greyscale level at each pixel
  
  Examples:
      >>> gis.preprocess_image('https://pixabay.com/static/uploads/photo/2012/11/28/08/56/mona-lisa-67506_960_720.jpg')
      array([[ 0.26344431,  0.32423294,  0.30406745, ...,  0.35069725,
               0.36499961,  0.36361569],
             [ 0.29676627,  0.28640118,  0.34523255, ...,  0.3703051 ,
               0.34931333,  0.31655686],
             [ 0.35305216,  0.31858431,  0.36202   , ...,  0.40588196,
               0.37284275,  0.30871373],
             ...,
             [ 0.05932863,  0.05540706,  0.05540706, ...,  0.01954745,
               0.01954745,  0.01562588],
             [ 0.0632502 ,  0.05540706,  0.05148549, ...,  0.01954745,
               0.02346902,  0.01562588],
             [ 0.06717176,  0.05540706,  0.05148549, ...,  0.02346902,
               0.02739059,  0.01954745]])
docstr_tok: ["Loads","an","image","and","converts","to","greyscale",".","Corresponds","to","'step","1","'","in","Goldberg","'s","paper","Args",":","image_or_path","(","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",")","handle_mpo","(","Optional","[","boolean","]",")",":","try","to","compute","a","signature","for","steroscopic","images","by","extracting","the","first","image","of","the","set","(","default","False",")","Returns",":","Array","of","floats","corresponding","to","greyscale","level","at","each","pixel","Examples",":",">",">",">","gis.preprocess_image","(","'https",":","\/\/pixabay.com\/static\/uploads\/photo\/2012\/11\/28\/08\/56\/mona-lisa-67506_960_720.jpg","'",")","array","(","[","[","0.26344431",",","0.32423294",",","0.30406745",",","...",",","0.35069725",",","0.36499961",",","0.36361569","]",",","[","0.29676627",",","0.28640118",",","0.34523255",",","...",",","0.3703051",",","0.34931333",",","0.31655686","]",",","[","0.35305216",",","0.31858431",",","0.36202",",","...",",","0.40588196",",","0.37284275",",","0.30871373","]",",","...",",","[","0.05932863",",","0.05540706",",","0.05540706",",","...",",","0.01954745",",","0.01954745",",","0.01562588","]",",","[","0.0632502",",","0.05540706",",","0.05148549",",","...",",","0.01954745",",","0.02346902",",","0.01562588","]",",","[","0.06717176",",","0.05540706",",","0.05148549",",","...",",","0.02346902",",","0.02739059",",","0.01954745","]","]",")"]
code: def preprocess_image(
      image_or_path, bytestream=False, handle_mpo=False
  ):
      """Loads an image and converts to greyscale.
  
      Corresponds to 'step 1' in Goldberg's paper
  
      Args:
          image_or_path (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)
          handle_mpo (Optional[boolean]): try to compute a signature for steroscopic
              images by extracting the first image of the set (default False)
  
      Returns:
          Array of floats corresponding to greyscale level at each pixel
  
      Examples:
          >>> gis.preprocess_image('https://pixabay.com/static/uploads/photo/2012/11/28/08/56/mona-lisa-67506_960_720.jpg')
          array([[ 0.26344431,  0.32423294,  0.30406745, ...,  0.35069725,
                   0.36499961,  0.36361569],
                 [ 0.29676627,  0.28640118,  0.34523255, ...,  0.3703051 ,
                   0.34931333,  0.31655686],
                 [ 0.35305216,  0.31858431,  0.36202   , ...,  0.40588196,
                   0.37284275,  0.30871373],
                 ...,
                 [ 0.05932863,  0.05540706,  0.05540706, ...,  0.01954745,
                   0.01954745,  0.01562588],
                 [ 0.0632502 ,  0.05540706,  0.05148549, ...,  0.01954745,
                   0.02346902,  0.01562588],
                 [ 0.06717176,  0.05540706,  0.05148549, ...,  0.02346902,
                   0.02739059,  0.01954745]])
  
      """
      if bytestream:
          try:
              img = Image.open(BytesIO(image_or_path))
          except IOError:
              # could be an svg, attempt to convert
              try:
                  img = Image.open(BytesIO(svg2png(image_or_path)))
              except (NameError, xml.etree.ElementTree.ParseError):
                  raise CorruptImageError()
          img = img.convert("RGB")
          return rgb2gray(np.asarray(img, dtype=np.uint8))
      elif (
          type(image_or_path) in string_types
          or type(image_or_path) is text_type
      ):
          return imread(image_or_path, as_gray=True)
      elif type(image_or_path) is bytes:
          try:
              img = Image.open(image_or_path)
              arr = np.array(img.convert("RGB"))
          except IOError:
              # try again due to PIL weirdness
              return imread(image_or_path, as_gray=True)
          if handle_mpo:
              # take the first images from the MPO
              if arr.shape == (2,) and isinstance(
                  arr[1].tolist(), MpoImageFile
              ):
                  return rgb2gray(arr[0])
              else:
                  return rgb2gray(arr)
          else:
              return rgb2gray(arr)
      elif type(image_or_path) is np.ndarray:
          return rgb2gray(image_or_path)
      else:
          raise TypeError("Path or image required.")
  
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 3 for calling the ImageSignature obj's underlying member method code with example usage: obj.preprocess_image(image_or_path, bytestream, handle_mpo) and returns: rgb2gray, imread, rgb2gray, rgb2gray, imread, rgb2gray, rgb2gray