Shanon entropy of a matrix

17 次查看(过去 30 天)
ali eskandari
ali eskandari 2021-3-18
回答: Jan 2021-3-18
I defined a matrix like A and I want to calculate its entropy and when I use the entropy function it returns zero :
A = [2,3,4;4,5,6;10,12,1]
entropy(A)
ans =
0
but when I read the matlab entropy help, it mentioned that this funtion will return the entropy of a grayscale image, so I have decided to apply mat2gray to convert my matrix into the grayscale, and now it returns 2.9477.
b= mat2gray(A)
b =
0.0909 0.1818 0.2727
0.2727 0.3636 0.4545
0.8182 1.0000 0
entropy(b)
ans =
2.9477
so, could you please help to find is this way correct?

采纳的回答

Jan
Jan 2021-3-18
As the documentation tells, the input is expected to be a gray scale image. Then value over 1.0 are limit to 1.0 and you matrix is interpreted as [1, 1, 1; 1, 1, 1; 1, 1, 1] with zero entropy.
Converting the matrix by mat2gray divides the values by the larges element after subtracting the smalles element:
A = [2,3,4; 4,5,6; 10,12,1]
mA = min(A(:));
B = (A - mA) / (max(A(:)) - mA) % same as MAT2GRAY
As far as I understand, this is the correct way to determine the entropy.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by