熵(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