www.pudn.com > 1111111registrationbasedoncorrelation.rar > EMI.m


%Caculate MI of a and b in the region of the size(a) 
 
function [mi] = EMI(a,b) 
% 
[M,N] = size(a); 
% change a, b to range 1:n 
if min(a(:))<1 
    a = a-min(a(:))+1; 
end 
if min(b(:))<1 
    b = b-min(b(:))+1; 
end 
     
 
% ncolora = max(a(:))-min(a(:))+1; 
% ncolorb = max(b(:))-min(b(:))+1; 
ncolora = max(a(:)); 
ncolorb = max(b(:)); 
 
hab = zeros(ncolora,ncolorb); 
ha = zeros(1,ncolora); 
hb = zeros(1,ncolorb); 
 
%count begins 
[M,N]=size(a); 
for i=1:M 
    for j=1:N 
       indexx =  a(i,j); 
       indexy =  b(i,j); 
 
       hab(indexx,indexy) = hab(indexx,indexy)+1; 
       ha(indexx) = ha(indexx)+1; 
       hb(indexy) = hb(indexy)+1; 
 
   end 
end 
 
%cal ha,hb,hab 
hsum = sum(sum(hab)); 
index = find(hab~=0); 
p = hab/hsum; 
Hab = sum(sum(-p(index).*log(p(index)))); 
 
hsum = sum(sum(ha)); 
index = find(ha~=0); 
p = ha/hsum; 
Ha = sum(sum(-p(index).*log(p(index)))); 
 
hsum = sum(sum(hb)); 
index = find(hb~=0); 
p = hb/hsum; 
Hb = sum(sum(-p(index).*log(p(index)))); 
 
mi = Ha+Hb-Hab; 
% cal EMI 
% feature efficiency coefficient 
n =2/5; 
if Hab ~= 0 
    e = (mi^n) / ( Hab^(1-n)); 
else% not usual happen, just for test 
    e = -1;%(mi^n) / ( Hab^(1-n)+1e-10); 
end 
mi = e; 
% %