1
$\begingroup$

I'm trying to register 2 images.First image don't change and second image is changing at each iteration by homography matrix and I'm using minimizer to find maximum of phase correlation, but for some reason it's doesn't work, maybe I'm conceptually wrong or maybe I'm using minimizer in a wrong way.

here is code on matlab.

main.m

global model; 
global scene; 

scene = imread('001_001.tif'); 
%test distortion homography matrix m11 m12 m21 m22 m31 m32 then we add nonchangeble m13=0 m23=0 m33=1 
H= [0.95 -0.05 0.0000 1.0000 -0.0000 -0.0000];% so we can test precision
model=warp_im(scene,H); 

%m11 m12 m21 m22 m31 m32 
init_sol= [1 0 0 1 0 0]; %initial solution

opts= optimset('Algorithm','interior-point','MaxFunEvals',5000,'MaxIter',5000,'TolFun',1e-6,'TolX',1e-10); 

problem= createOptimProblem('fmincon','objective','compute_NCC','x0',init_sol,'options',opts); 

gs= GlobalSearch; 
[x,f]= run(gs,problem) 
param=x;

compute_NCC.m

function peak = compute_NCC(param) 

global scene; 
global model; 

img= warp_im(model,param); 

%padd with zeros
sz1= size(scene); % y x  
sz2= size(img); 
sz= abs(sz2-sz1); 
pad_im1=scene;pad_im2=img; 
if(sz1(1)>sz2(1))%y 
pad_im2= padarray(img,[sz(1),0],'post'); 
else 
pad_im1= padarray(scene,[sz(1),0],'post'); 
end; 
if(sz1(2)>sz2(2))%x 
pad_im2= padarray(pad_im2,[0,sz(2)],'post'); 
else 
pad_im1= padarray(pad_im1,[0,sz(2)],'post'); 
end; 

FFT1 = fftshift(fft2(pad_im1)); 
FFT2 = fftshift(fft2(pad_im2)); 

FFT = FFT1.*conj(FFT2); 
FFT = FFT./abs(FFT); 

mag = (ifft2(FFT)); 

peak= -abs(max(max(mag))) % minimize

warp_im.m

function out = warp_im(img,param) 
param=[param(1:2),0,param(3:4),0,param(5:6),1] 
H=reshape(param,3,3)' 

tform = maketform('projective',H'); 
out= imtransform(img,tform);
$\endgroup$
  • $\begingroup$ (Phase) correlation will give you the translation offset, nothing more. So I don't see the need to have an iterative procedure, nor will you have enough information to find a projective transform. $\endgroup$ – Maurits Oct 15 '12 at 8:23
  • 1
    $\begingroup$ @Maurits You don't understand. I change second image(perspective transform) and look at correlation peak at each iteration and then I choose best case. $\endgroup$ – mrgloom Oct 15 '12 at 9:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.