We have two images, one as a reference and another image which we want to align like the reference using Matlab. In order to do this, we need to find similar points in both images and than calculate the kernel matrix using the Least Square method for the transformation like this code:
clear all; close all; clc; imtool close all;
I1 = rgb2gray(im);
I2 = rgb2gray(ref);
points1 = detectSURFFeatures(I1);
points2 = detectSURFFeatures(I2);
[features1,valid_points1] = extractFeatures(I1,points1,'SURFSize',64);
[features2,valid_points2] = extractFeatures(I2,points2,'SURFSize',64);
indexPairs = matchFeatures(features1,features2);
matchedPoints1 = valid_points1(indexPairs(:,1),:);
matchedPoints2 = valid_points2(indexPairs(:,2),:);
[tform, correct1,correct2] = estimateGeometricTransform(matchedPoints1,matchedPoints2,'projective','MaxNumTrials',100000,'Confidence',99.9999,'MaxDistance',4);
sourcepoints = correct1.Location;
targetpoints = correct2.Location;
sizenum = size(sourcepoints,1);
x_source = sourcepoints(:,1);
y_source = sourcepoints(:,2);
x_target = targetpoints(:,1);
y_target = targetpoints(:,2);
zero_vec = zeros([sizenum,1]);
one_vec = ones([sizenum,1]);
H = [x_source,y_source,one_vec,zero_vec,zero_vec,zero_vec,-x_source.*x_target,-y_source.*x_target;...
zero_vec,zero_vec,zero_vec,x_source,y_source,one_vec,-x_source.*y_target,-y_source.*y_target];
Y = [x_target;y_target];
variables = (inv(H'*H))*H'*Y;
variables(9) = 1;
kernel = reshape(variables,3,3)';
In this code we don't care much about the speed, the most important thing to us is the accuracy.
1) In here we are using the Surf method and we try to understand if this is the best method for this task, or maybe we should use other feature detection like HOG or FAST etc?
2) We try to understand what are the differences between each feature detector and when to use each one of them?
Thanks in advance.