图像熵的意义以及计算

熵(entropy)指的是体系的混乱的程度,它在控制论、概率论、数论、天体物理、生命科学等领域都有重要应用,在不同的学科中也有引申出的更为具体的 定义,是各领域十分重要的参量。熵由鲁道夫·克劳修斯(Rudolf Clausius)提出,并应用在热力学中。后来在,克劳德·艾尔伍德·香农(Claude Elwood Shannon)第一次将熵的概念引入到信息论中来。

图像熵表示为图像灰度级集合的比特平均数,单位比特/像素,也描述了图像信源的平均信息量。

: H(p)=-∑i,jp(i.j)lnp(i,j), 其中p(i,j)=x(i,j)∑i,jx(i,j),x(i,j)为图像的像元

%%%%%%%%%%%%%%%%Matlab源码%%%%%%%%%%%%%%

%计算一副图像的熵

%随机生成图像
A=floor(rand(8,8).*255);

[M,N]=size(A);
temp=zeros(1,256);

%对图像的灰度值在[0,255]上做统计
for m=1:M;
for  n=1:N;

if A(m,n)==0;
i=1;
else
i=A(m,n);
end
temp(i)=temp(i)+1;
end
end
temp=temp./(M*N);

%由熵的定义做计算
result=0;

for  i=1:length(temp)
if temp(i)==0;
result=result;
else
result=result-temp(i)*log2(temp(i));
end
end
result

%计算联合熵

%随机生成图像
A=floor(rand(8,8).*255);
B=floor(rand(8,8).*255);

[M,N]=size(A);
temp=zeros(256,256);

%对图像的灰度值成对地做统计
for m=1:M;
for n=1:N;

if  A(m,n)==0;
i=1;
else
i=A(m,n);
end

if B(m,n)==0;
j=1;
else
j=B(m,n);
end

temp(i,j)=temp(i,j)+1;
end
end
temp=temp./(M*N);

%由熵的定义做计算
result=0;

for  i=1:size(temp,1)
for j=1:size(temp,2)
if temp(i,j)==0;
result=result;
else
result=result-temp(i,j)*log2(temp(i,j));
end
end
end
result

 转:http://www.zhizhihu.com/html/y2010/1367.html

原文地址:https://www.cnblogs.com/lanye/p/4164136.html