entropy of image

hi, can anybody please help me to translate this code from python to processing?

import Image
import math

def image_entropy(img):
    """calculate the entropy of an image"""
    histogram = img.histogram()
    histogram_length = sum(histogram)

    samples_probability = [float(h) / histogram_length for h in histogram]

    return -sum([p * math.log(p, 2) for p in samples_probability if p != 0])

img = Image.open('headshot.jpg')
print image_entropy(img)


Sign In or Register to comment.