Shanon entropy of a matrix
17 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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?
0 Kommentare
Akzeptierte Antwort
Jan
am 18 Mär. 2021
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!