Return to Snippet

Revision: 18310
at September 28, 2009 06:47 by vasilije


Initial Code
from math import log

def get_histogram_dispersion(histogram):
	log2 = lambda x:log(x)/log(2)
	
	total = len(histogram)
	counts = {}
	for item in histogram:
		counts.setdefault(item,0)
		counts[item]+=1
		
	ent = 0
	for i in counts:
		p = float(counts[i])/total
		ent-=p*log2(p)
	return -ent*log2(1/ent)

Initial URL

                                

Initial Description

                                

Initial Title
Image entropy from PIL histogram

Initial Tags
python

Initial Language
Python