Search code examples
matlabtransformationsift

how to calculate a transformation matrix based on data obtained from vl_sift?


I have used the SIFT implementation of Andrea Vedaldi, to calculate the sift descriptors of two images in order to align them,

   Ia = imread('roofs1.jpg')) ;
   Ib = imread('roofs2.jpg')) ;

   %calculate descriptors

   [fa,da] = vl_sift(im2single(rgb2gray(Ia))) ;
   [fb,db] = vl_sift(im2single(rgb2gray(Ib))) ;
    %matching
   [matches, scores] = vl_ubcmatch(da,db) ;
   [drop, perm] = sort(scores) ;
   matches = matches(:, perm(1:50)) ;
   scores  = scores(perm(1:50)) 

and after I get the keypoints

d1=fa(1:2,matches(1,:));
d2=fb(1:2,matches(2,:));

Now i want to calculate the transformation matrix M between this two images

Pos1=d1';
Pos2=d2';
Pos1(:,3)=1; Pos2(:,3)=1;
M=Pos1'/Pos2';

then apply a transformation with a function affine_warp to get a tranformed image

Ia_warped=affine_warp(Ia,M,'bicubic');

But in reality i get this result image results

If someone can help me to identify where's mistake in my code


Solution

  • You need to ascertain the homography or transformation matrix which maps the points from the first set to the other. This can be done with the Direct Linear Transform algorithm which is explained in the book Multiple View Geometry. Matlab also has a tutorial.

    RANSAC is usually used to rid the set of ouliers, demos of which can be found on the vlfeat site and the site of Peter Kovesi .