熵函数的用法
我试图在 MATLAB 中求某个概率分布的熵。对于 p,我尝试
E = -sum(p .* log2(p))
这样做 Echeck = entropy(p)
E 和 Echeck 不应该相同吗?
matlab关于熵的帮助确实说熵被定义为 -sum(p.*log2(p)) 其中 p 包含从 imhist 返回的直方图计数。而且,熵还将逻辑以外的任何类转换为 uint8 以进行直方图计数计算,因为它实际上是在尝试计算灰度图像的熵,因此希望像素值是离散的。 所以我想使用这个函数来达到我的目的是不正确的? 有好的选择吗?
I was trying to find the entropy of a certain probability distribution in MATLAB. For p, I tried doing
E = -sum(p .* log2(p))
and Echeck = entropy(p)
Shouldn't E and Echeck be same?
The matlab help on entropy does say Entropy is defined as -sum(p.*log2(p))
where p contains the histogram counts returned from imhist.But also that entropy converts any class other than logical to uint8 for the histogram count calculation since it is actually trying to calculate the entropy of a grayscale image and hence wants the pixel values to be discrete.
So I guess it's incorrect to use this function for my purpose?
Is there a good alternative?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我用
open entropy
检查代码,有一行:意思是把输入转成uint8,然后函数计算输入的直方图的熵,而不是输入本身。
这就解释了其中的差异。
I used
open entropy
to check the code, and there is a line:which mean that the input is converted to uint8, and then the function computes the entropy of the histogram of the input, and not of the input itself.
That explains the difference.