why am i getting NaN from my function
Ältere Kommentare anzeigen
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 Kommentare
David Goodmanson
am 26 Jan. 2020
Hi tomer, don't forget 0*log(0) = nan
tomer orenshtein
am 26 Jan. 2020
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Image Arithmetic finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!