Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.25 KB | None | 0 0
  1. def shannon_entropy(img):
  2.  
  3. histogram = img.histogram()
  4. histogram_length = sum(histogram)
  5.  
  6. samples_probability = [float(h) / histogram_length for h in histogram]
  7.  
  8. return -sum([p * math.log(p, 2) for p in samples_probability if p != 0])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement