I have two images and found three similar 2D points using a sift. I need to compute the affine transformation between the images. Unfortunately, I missed lecture and the information out there is a little dense for me. What would the general method be for computing this 2x3 matrix?
I have the matrix of points in a 2x3 matrix [x1 y1;x2 y2;x3 y3] but I am lost from there. Thanks for any help.
Usually, an affine transormation of 2D points is experssed as
Where
x
is a three-vector[x; y; 1]
of original 2D location andx'
is the transformed point. The affine matrixA
isThis form is useful when
x
andA
are known and you wish to recoverx'
.However, you can express this relation in a different way. Let
and
a
is a column vectorThen
Holds for all pairs of corresponding points
x_i, x_i'
.This alternative form is very useful when you know the correspondence between pairs of points and you wish to recover the paramters of
A
.Stacking all your points in a large matrix
X
(two rows for each point) you'll have 2*n-by-6 matrixX
multiplyied by 6-vector of unknownsa
equals a 2*n-by-1 column vector of the stacked corresponding points (denoted byx_prime
):Solving for
a
:Recovers the parameters of
a
in a least-squares sense.Good luck and stop skipping class!
Sorry for not using Matlab, but I only worked with Python a little bit. I think this code may help you (sorry for bad codestyle -- I'm mathematician, not programmer)
This code demonstrates how to recover affine transformation as matrix and vector and tests that initial points are mapped to where they should. You can test this code with Google colab, so you don't have to install anything. Probably, you can translate it to Matlab.
Regarding theory behind this code: it is based on equation presented in "Beginner's guide to mapping simplexes affinely", matrix recovery is described in section "Recovery of canonical notation". The same authors published "Workbook on mapping simplexes affinely" that contains many practical examples of this kind.