图像的熵是多少,如何计算? [英] What is the entropy of an image and how is it calculated?

查看:59
本文介绍了图像的熵是多少,如何计算?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解到这是像素的随机性.但是,请帮助您以数学方式计算这种随机性.以及不同的图像如何具有不同的熵.

I have learnt that it is the randomness of the pixels. But please help with how this randomness is being calculated mathematically. And also how different images will have different entropy.

推荐答案

您也可以直接从 img 计算Shannon熵.只要做:

You may as well calculate the Shannon entropy straight from your img. Just do:

import skimage.measure    
entropy = skimage.measure.shannon_entropy(img)

如果您想查看背后的数学公式:

If you want to see the maths behind:

import numpy as np
marg = np.histogramdd(np.ravel(img), bins = 256)[0]/img.size
marg = list(filter(lambda p: p > 0, np.ravel(marg)))
entropy = -np.sum(np.multiply(marg, np.log2(marg)))

首先, marg 是二维灰度图像 img 的边缘分布.对于8位图像, bins 设置为256.然后,您需要过滤出等于零的概率,并最终求和其余元素 np.multiply(marg,np.log2(marg)),具体由

First, marg is the marginal distribution of the two dimensional grayscale image img. bins is set to 256 for an 8-bit image. Then you need to filter out the probabilities that are equal to zero and finally sum over the remaining elements np.multiply(marg, np.log2(marg)), as defined by Shannon's entropy.

这篇关于图像的熵是多少,如何计算?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆