www.pudn.com > duge.rar > MI.m, change:2015-06-01,size:1991b

```function [ value ] = MI( I1,I2 )
%MI 此处显示有关此函数的摘要
%   计算互信息，越大图像越相似，融合效果越好
% J_H=join_H(I1,I2);
% count_J=sum(J_H);
%
% I1=rgb2gray(I1);
% [counts_I1,x]=imhist(I1);
% counts_I1=counts_I1/(size(I1,1)*size(I1,2));
%
% I2=rgb2gray(I2);
% [counts_I2,x]=imhist(I2);
% counts_I2=counts_I2/(size(I2,1)*size(I2,2));
%
% E=0;
% for i=0:255
%     if(counts_J(i+1)~=0)
%        E=E+counts_J(i+1)*log2(counts_J(i+1)/(counts_I1(i+1)*counts_I2(i+1)));
%     end
% end
% value=-E;

I1=double(rgb2gray(I1));
I2=double(rgb2gray(I2));
[M N]=size(I1);
H1=zeros(1,256);
H2=zeros(1,256);
H12=zeros(256,256);
for rows=1:M
for cols=1:N
H1(I1(rows,cols))=H1(I1(rows,cols))+1;
H2(I2(rows,cols))=H2(I2(rows,cols))+1;
H12(I1(rows,cols)+1,I2(rows,cols)+1)=H12(I1(rows,cols)+1,I2(rows,cols)+1)+1;
end
end
H1=H1/(M*N);
H2=H2/(M*N);
H12=H12/(M*N);
MI=0;
for i=0:255
for j=0:255
if(H12(i+1,j+1)~=0&&H1(i+1)~=0&&H2(j+1)~=0)
MI=MI+H12(i+1,j+1)*log2(H12(i+1,j+1)/(H1(i+1)*H2(j+1)));
end
end
end
value=MI;

% I1=rgb2gray(I1);
% [counts,x]=imhist(I1);
% counts=counts/(size(I1,1)*size(I1,2));
% E1=0;
% for i=0:255
%     if(counts(i+1)~=0)
%        E1=E1+counts(i+1)*log2(counts(i+1));
%     end
% end
%
% I2=rgb2gray(I2);
% [counts,x]=imhist(I2);
% counts=counts/(size(I2,1)*size(I2,2));
% E2=0;
% for i=0:255
%     if(counts(i+1)~=0)
%        E2=E2+counts(i+1)*log2(counts(i+1));
%     end
% end
%
% I1=double(I1);
% I2=double(I2);
% [M N]=size(I1);
% H12=zeros(256,256);
% for rows=1:M
%     for cols=1:N
%         H12(I1(rows,cols)+1,I2(rows,cols)+1)=H12(I1(rows,cols)+1,I2(rows,cols)+1)+1;
%     end
% end
% counts=H12/(M*N);
% E12=0;
% for i=0:255
%     for j=0:255
%         if(counts(i+1,j+1)~=0)
%            E12=E12+counts(i+1,j+1)*log2(counts(i+1,j+1));
%     end
% end
%
% % value=E12/(E1+E2);
% value=E1+E2-E12;

end

```