Entropy
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
clear all;
close all;
clc;
x = imread('circuit.tif');
p = imhist(x);
[m,n] = size(p);
E = 0;
for i = 1:m
for j = 1:n
if(p(i,j) > 0)
E = E - (p(i,j) * log2(p(i,j)));
end
end
end
ex = entropy(p);
Why E and ex having different values ? How we can solve it ?
2 Kommentare
Walter Roberson
am 6 Jun. 2012
I do not have access at the moment to check: I wonder what the datatype of p is? If it turns out to be one of the integer data types, your expressions probably do not compute what you expect.
Image Analyst
am 6 Jun. 2012
p is a 1D variable since it's the counts. Also you didn't normalize p by dividing by numel(x).
Antworten (1)
Image Analyst
am 6 Jun. 2012
Try this:
p(p==0) = [];
E2 = -sum(p .* log2(p))
E3 = entropy(x)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!