matlab几何纠正,间接法,双线性内插
超简洁,超级快,两个文件
datapre.m文件代码:
global X;
global Y;
global A;
global l;
global i;
global I;
global m;
global n;
global k;
global dx;
A=[];
l=[];
i=0;
m=[];
n=[];
dx=[];
fig=figure;
subplot(1,2,1);
I=imread('编程实习2-待纠正图像.bmp');
imshow(I);
J=imread('编程实习2-参考图像.bmp');
subplot(1,2,2);
imshow(J);
dcm_obj = datacursormode(fig);
datacursormode on;
set(dcm_obj,'UpdateFcn',@myupdatefcn);
myupdatefcn文件代码:
function txt = myupdatefcn(empt,event_obj)
% Customizes text of data tips
global X;
global Y;
global A;
global l;
global i;
global I;
global m;
global n;
global k;
global dx;
pos = get(event_obj,'Position');
X=pos(1);
Y=pos(2);
txt = {['待纠正图像X: ',num2str(X)],...
['待纠正图像Y: ',num2str(Y)]};
i=i+1;
if(rem(i,2)==1)
k=(i+1)/2;
A(k,1)=1;
A(k,2)=X;
A(k,3)=Y;
else
l(i/2,1)=X;
l(i/2,2)=Y;
end
[m,n]=size(l);
if(m==4)
datacursormode off;
dx=inv(A'*A)*(A'*l);
[m,n,k]=size(I);
dis=sqrt((A(2,2)-A(1,2))*(A(2,2)-A(1,2))+(A(2,3)-A(1,3))*(A(2,3)-A(1,3)));
dist=sqrt((l(2,1)-l(1,1))*(l(2,1)-l(1,1))+(l(2,2)-l(1,2))*(l(2,2)-l(1,2)));
sca=dist/dis;
cosa=(dx(2,1)+dx(3,2))/(2*sca);
sina=(-dx(2,2)+dx(3,1))/(2*sca);
alfa=atan(sina/cosa);
alfa=alfa*180/3.1415926;
ResImage=imresize(I,sca,'bilinear');
ResImage=imrotate(ResImage,alfa,'bilinear');
figure;
imshow(ResImage);
end
end