Computing Entropy from Matlab Matrix in Matlab

I am trying to extract entropy from matrices with zero elements in Matlab. From the definition of the entropy of the match matrix:

definition of entropy
must be calculated where c ijmeans the record (i, j) of the match matrix. Thus, it seems to me that if there is one null entry, the entropy will be undefined. Are you setting some kind of lower limit for log (x) when x = 0, or how do you handle this?

Link to pdf with definition of entropy for GLCM: http://www.code.ucsd.edu/pcosman/glcm.pdf

EDIT: Thanks for the suggestions on working with the log (0), but the equation actually requires an estimate of 0 * log (0), which is 0. It would be easier to explain if I can use the formulas, but maybe my question was more mathematical, and therefore in the wrong forum.

+4
source share
2 answers

I usually use the following workaround to avoid this problem:

X = C .* log2(C + (C == 0));
entropy = -sum(X(:));

For those elements C(matching matrices) that are 0, the argument is a logarithm function 1, since the expression (C == 0)evaluates to 1.

+1
source

I always do this if I don't want -Inf when I record something.

set epsilon, which is very, very small, and apply your C matrix as

e = 1e-99;
C = C + e;

, -Inf.

@CrisLuengo

+4

Source: https://habr.com/ru/post/1692916/


All Articles