Calculation of entropy shows " the entropy of the image is = NaN", please help
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Walter Roberson
2019-12-3
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Biomedical Imaging 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!