Entropy
11 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2012-6-6
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
2012-6-6
p is a 1D variable since it's the counts. Also you didn't normalize p by dividing by numel(x).
回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multidimensional Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!