This Matlab tutorial I use SIFT, RANSAC, and homography to find corresponding points between two images. Here I have used vlfeat to find SIFT features.
Full code is available at my GitHub repository
Major steps are:
0.Adding vlfeat to your Matlab workspace:
1.Detect key points and extract descriptors. In the image below you can see some SIFT key points and their descriptor.
[f_image_left,d_image_left] = vl_sift(image_left) ;
diff = double(d_image_right(:,i)) - double(d_image_left(:,j)) ;
distance = sqrt(diff' * diff);
In this step, I only took first k top matches.
M=(M < M_Vec( number_of_top_matches_to_select ) );
4.Estimating transformation using RANSAC
I used RANSAC to estimate the transformation.
N= (log (1-p))/(log(1-(1-e)^s))
iter=N;%we choose this so with probability of 99% at least one random sample is free from ouliers
num=3;%minmum number of samples to make the model i.e for line is 2 and for affine is 3
threshDist=5; %5 pixel
5.Compute optimal transformation
Finally, I used the least square method to find the affine transformation between two images.