def image_entropy(img):
w,h = img.shape
a = np.array(img.reshape((w*h,1)))
h,e = np.histogramdd(a, bins=(16,), range=((0,256),))
prob = h/np.sum(h) # normalize
prob = prob[prob>0] # remove zeros
return -np.sum(prob*np.log2(prob))
评论列表
文章目录