图像相似性度量——互信息计算Matlab实现

图像相似性度量——互信息计算Matlab实现
前⾔
之前写了⼀篇关于计算互信息的,基本的原理已经在那篇⽂章⾥⾯写出来了,这⾥就不在赘述了。在这⽚⽂章中将介绍采⽤的是直⽅图计算的⽅式,⽐之前的⽅法快了很多,软件的代码是Matlab实现的,这⾥贴出来与⼤家分享。
1. 代码
%将图像B经过⼏何变换之后再计算互信息
%x:⽔平⽅向上的位移
%y:垂直⽅向上的位移
%ang:图像的旋转⾓度
%A:参考图像
%B:浮动图像
function [mi]=PV(x, y, ang, A, B)
a=A;
a=double(a);
b=B;
b=double(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);
endserver 2003
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;
[width,height]=size(b);
u=(width-1)/2;
v=(height-1)/2;
rad=pi/180*ang;
t1=[1 0 0;0 1 0;x y 1];
t2=[1 0 0;0 1 0;-u -v 1];
t3=[cos(rad) -sin(rad) 0;sin(rad) cos(rad) 0;0 0 1];
t4=[1 0 0;0 1 0;u v 1];
T=t2*t3*t4*t1;
tform=maketform('affine',T);
coordinate_x=zeros(width,height);
coordinate_y=zeros(width,height);
for i=1:width
for j=1:height
coordinate_x(i,j)=i;
end
end
for i=1:width
for j=1:height
coordinate_y(i,j)=j;
end
end
[w z]=tforminv(tform,coordinate_x,coordinate_y);
for i=1:width
for j=1:height
source_x=w(i,j);
source_y=z(i,j);
if (source_x>width-1||source_y>height-1||...
if (source_x>width-1||source_y>height-1||...
double(uint16(source_x))<=1||...
double(uint16(source_y))<=1)
hab(a(1,1),a(1,1))=hab(a(1,1),a(1,1))+1;
else
m=fix(source_x);
n=fix(source_y);
index_b=b(i,j);
index_a0=a(m,n);
index_a1=a(m+1,n);
index_a2=a(m,n+1);
index_a3=a(m+1,n+1);
dx=source_x-m;
dy=source_x-n;
hab(index_a0,index_b)=hab(index_a0,index_b)+(1-dx)*(1-dy);
hab(index_a1,index_b)=hab(index_a1,index_b)+dx*(1-dy);
hab(index_a2,index_b)=hab(index_a2,index_b)+(1-dx)*dy;
atp系统
hab(index_a3,index_b)=hab(index_a3,index_b)+dx*dy;
end
end
end
hadsum=sum(sum(hab));
index=find(hab~=0);
pab=hab/hadsum;
大战略2001Hab=sum(sum(-pab(index).*log2(pab(index))));
pa=sum(pab');
曾凡亚index=find(pa~=0);
Ha=sum(sum(-pa(index).*log2(pa(index))));
pb=sum(pab);
index=find(pb~=0);
Hb=sum(sum(-pb(index).*log2(pb(index))));
fprintf('图⽚A/B的互信息为:%f, x=%f,y=%f,angle=%f \n', (Ha+Hb-Hab),x,y,ang); mi = Ha+Hb-Hab;

本文发布于:2024-09-22 12:31:42,感谢您对本站的认可!

本文链接:https://www.17tex.com/xueshu/435612.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:互信息   计算   图像   度量
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议