original_docstring: 
      Calculate the entropy of an image. Used for "smart cropping".
      
docstring: Calculate the entropy of an image. Used for "smart cropping".
docstring_tokens: Calculate the entropy of an image . Used for " smart cropping " .
code: def image_entropy(im):
      """
      Calculate the entropy of an image. Used for "smart cropping".
      """
      if not isinstance(im, Image.Image):
          # Can only deal with PIL images. Fall back to a constant entropy.
          return 0
      hist = im.histogram()
      hist_size = float(sum(hist))
      hist = [h / hist_size for h in hist]
      return -sum([p * math.log(p, 2) for p in hist if p != 0])
code_tokens: def image_entropy ( im ) : if not isinstance ( im , Image . Image ) : return 0 hist = im . histogram ( ) hist_size = float ( sum ( hist ) ) hist = [ h / hist_size for h in hist ] return - sum ( [ p * math . log ( p , 2 ) for p in hist if p != 0 ] )
short_docstring: Calculate the entropy of an image.
short_docstring_tokens: Calculate the entropy of an image .
comment: """
      Calculate the entropy of an image. Used for "smart cropping".
      """$SEP$# Can only deal with PIL images. Fall back to a constant entropy.