Calculation of entropy shows " the entropy of the image is = NaN", please help
2 views (last 30 days)
Show older comments
Img = imread('test1.jpg');
I=rgb2gray(Img);
[Height,Width] = size(I);
[m,Binsx] = imhist(I);
m = m/(Height*Width);
sprintf('the sum of the histogram value is = %g',sum(m));
figure,plot(Binsx,m,'k')
xlabel('pixel value'),ylabel('relative count')
H = sum(-m.*log2(m));
sprintf('the entropy of the image is = %g',H)
0 Comments
Answers (2)
Walter Roberson
on 3 Dec 2019
H = sum(-m.*log2(m));
The problem with the code is that you have some entries which are 0. You should only be calculating based upon the non-zero entries.
mp = m(m>0);
H = sum(-mp.*log2(mp));
0 Comments
See Also
Categories
Find more on Biomedical Imaging in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!