function [xtran,ytran,delta]=computedelta(im1,im2)
% pre-align two images in frequecy domain
% author: bugzhao bugzhao@sdu.edu.cn
% May 09th,2005
% Please refer to "Mosaics of Scenes with Moving Objectc" for this method
% 粗估算两幅图像之间的平移差,返回水平方向平移差到xtran,返回垂直方向平移差到ytran
% 用在图像配准中的粗匹配中,对噪声、图像中物体发生运动等极为鲁棒!
if(size(im1,3)==3)
im1=rgb2gray(im1);
im2=rgb2gray(im2);
end
im1=double(im1);
im2=double(im2);
F1=fft2(im1);
F2=fft2(im2);
fz=F1.*conj(F2);
fm=abs(F1.*F2);
div=fz./fm;
delta=ifft2(div);
maxvalue=max(max(delta));
delta=fliplr(flipud(delta));
imshow(delta,[]);
[ytran,xtran]=find(delta==maxvalue);
if(max(max(delta))==1) %完全相关,即表明两幅图像完全一样
xtran=0;
ytran=0;
else if(ytran==size(im1,1))
ytran=0;
else if (xtran==size(im1,2))
xtran=0;
end
end
end
fprintf('图像2相对于图像1的位移量(单位-像素):\n 水平方向(x方向) : %d \n 竖直方向(y方向) : %d \n',xtran,ytran);
end
评论6