MI.m
上传用户:xueli1969
上传日期:2022-07-27
资源大小:19k
文件大小:1k
- %Caculate MI of a and b in the region of the size(a)
- function mi = MI(a,b)
- %
- [M,N] = size(a);
- hab = zeros(256,256);
- ha = zeros(1,256);
- hb = zeros(1,256);
- if max(max(a))~=min(min(a))
- a = (a-min(min(a)))/(max(max(a))-min(min(a)));
- else
- a = zeros(M,N);
- end
-
- if max(max(b))-min(min(b))
- b = (b-min(min(b)))/(max(max(b))-min(min(b)));
- else
- b = zeros(M,N);
- end
- a = double(int16(a*255))+1;
- b = double(int16(b*255))+1;
- % a = int16(a)+1;
- % b = int16(b)+1;
- 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
- 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;