why am i getting NaN from my function
古いコメントを表示
i was asked to write a function that gets b&w image and returns its entropy. im not allowed to use im_hist or entrtopy (obviously).
this is the function i wrote:
function [Entropy] = EntropyCalc(image)
image_hist = histogram(image);
values = image_hist.Values;
[size_x, size_y] = size(image);
total = size_x * size_y;
p = values./total;
Entropy = - sum(p.*log2(p));
end
but i keep getting NaN.
any ideas??
thanks!
2 件のコメント
David Goodmanson
2020 年 1 月 26 日
Hi tomer, don't forget 0*log(0) = nan
tomer orenshtein
2020 年 1 月 26 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Interpolation of 2-D Selections in 3-D Grids についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!