Calculation of entropy shows " the entropy of the image is = NaN", please help

2 ビュー (過去 30 日間)
ushamary sharma
ushamary sharma 2019 年 12 月 3 日
回答済み: Walter Roberson 2019 年 12 月 3 日
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)

回答 (2 件)

Image Analyst
Image Analyst 2019 年 12 月 3 日
Use entropy():
H = entropy(I)

Walter Roberson
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));

カテゴリ

Help Center および File ExchangeBiomedical Imaging についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by