Entropy

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
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
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개)

Image Analyst
Image Analyst 2012년 6월 6일

0 개 추천

Try this:
p(p==0) = [];
E2 = -sum(p .* log2(p))
E3 = entropy(x)

카테고리

도움말 센터File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

태그

질문:

2012년 6월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by