Shanon entropy of a matrix
조회 수: 21 (최근 30일)
이전 댓글 표시
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
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!