Search code examples
matlabsiftransac

RANSAC estimating Affine transformation


For a image mosaic application, I took the matches of the descriptors and stored it in a matrix matches 2xM. I now want to apply Ransac with affine, so i got my random sample with was 2x3 matrix, then i tried applying the code

[tform,inlier1,inlier2] = estimateGeometricTransform(sample(1,:),sSample(2,:),'affine');

This doesn't seem to work because it requires that my columns to be 2, transposing it to 3x2 doesnt work as well since for affine i need 3 points of correspondences.

Matches also returns only the index of matched descriptors, how can I extract its coordinates and apply it to my tform transformation?

[f,d] = vl_sift(image1);
[f1,d2] = vl_sift(image2);
[matches, scores] = vl_ubcmatch(d, d2) ;

ranMatch = randperm(size(matches,2),3); 
sample = matches(:,ranMatch);
[tform,inlier1,inlier2] = 
estimateGeometricTransform(sample(1,:),sample(2,:),'affine');

Solution

  • I don't have your data to test this, nor your functions vl_sift and vl_ubcmatch. So please excuse any issues.

    According to the documentation, f and f2 contain the coordinates of the points returned by vl_sift, and have a size of 4xM (possibly with different M), where the first two rows are the x and y coordinates.

    I will also assume that matches is a 2xN array in which matches(1,:) are indicates into f and matches(2,:) are indices into f2, such that f(1:2,matches(1,i)) is a point that corresponds to f2(1:2,matches(2,i)). Please double-check this assumption, the documentation does not specify the output.

    You should be able to find the transformation between the two sets of points as follows:

    matched_f = f(1:2,matches(1,:))';
    matched_f2 = f2(1:2,matches(2,:))';
    [tform,inlier1,inlier2] = estimateGeometricTransform(matched_f,matched_f2,'affine');
    

    This will use all the matched points, and furthermore will discard outliers.

    For more information, see the documentation to estimateGeometricTransform.