gpt4 book ai didi

python - 计算图像熵时如何处理直方图零计数?

转载 作者:行者123 更新时间:2023-12-03 19:44:37 25 4
gpt4 key购买 nike

我正在尝试实现 Matlab 函数 entropy()在 Python 中。

Entropy

Entropy is a statistical measure of randomness that can be used to characterize the texture of the input image.

Entropy is defined as -sum(p.*log2(p)), where p contains the normalized histogram counts returned from imhist.

我使用 openCV 获取归一化直方图计数。直方图计数出现零怎么办?

最佳答案

由于您正在将函数移植到另一个编程框架中,所以在我看来,对您的问题的一个很好的回答是:“与 Matlab 做的一样”

Matlab 在对直方图进行归一化之前丢弃等于 0 的计数。如果您使用命令 open entropy 打开原始函数,您将在其代码中找到您要查找的内容:

% calculate histogram counts
p = imhist(I(:));

% remove zero entries in p
p(p==0) = [];

% normalize p so that sum(p) is one.
p = p ./ numel(I);

E = -sum(p.*log2(p));

关于python - 计算图像熵时如何处理直方图零计数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49600169/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com