def _image_entropy(im):
    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])
Calculate the entropy of an image. Used for "smart cropping".
dataset/ETHPy150Open hcarvalhoalves/django-rest-thumbnails/restthumbnails/processors.py/_image_entropy