Given three points calculate the affinity transformation

I have two images and found three similar 2D points using sieving. I need to calculate the affine transformation between images. Unfortunately, I missed the lecture, and the information is a little tight for me. What will be the general method for computing this 2x3 matrix?

I have a matrix of points in a 2x3 matrix [x1 y1; x2 y2; x3 y3], but I'm lost from there. Thanks for any help.

+12
image-processing geometry matlab computer-vision linear-algebra affinetransform
source share
3 answers

Usually affine trans morphine of two-dimensional points expersed as

x' = A*x 

Where x is a three-vector [x; y; 1] [x; y; 1] [x; y; 1] original 2D location, and x' is the transformed point. The affine matrix A is equal to

 A = [a11 a12 a13; a21 a22 a23; 0 0 1] 

This form is useful when x and A known, and you want to restore x' .

However, you can express this attitude differently. Let

 X = [xi yi 1 0 0 0; 0 0 0 xi yi 1 ] 

and A is the column vector

 a = [a11; a12; a13; a21; a22; a23] 

Then

 X*a = [xi'; yi'] 

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 want to restore the parameters A
Stacking all your points in a large matrix x (two rows for each point), you will have a 2 * n-6, x matrix multiplied by a 6-vector of unknown A , equal to 2 * n-by -1 column vector of stacked corresponding points (indicated by x_prime ):

 X*a = x_prime 

Solution for A :

 a = X \ x_prime 

Restores the parameters of A in the sense of least squares.

Good luck and stop skipping class!

+33
source share

Sorry for not using Matlab, but I did a bit of work with Python. I think this code can help you (sorry for the bad code style - I'm a mathematician, not a programmer)

 import numpy as np # input data ins = [[1, 1], [2, 3], [3, 2]] # <- points out = [[0, 2], [1, 2], [-2, -1]] # <- mapped to # calculations l = len(ins) B = np.vstack([np.transpose(ins), np.ones(l)]) D = 1.0 / np.linalg.det(B) entry = lambda r,d: np.linalg.det(np.delete(np.vstack([r, B]), (d+1), axis=0)) M = [[(-1)**i * D * entry(R, i) for i in range(l)] for R in np.transpose(out)] A, t = np.hsplit(np.array(M), [l-1]) t = np.transpose(t)[0] # output print("Affine transformation matrix:\n", A) print("Affine transformation translation vector:\n", t) # unittests print("TESTING:") for p, P in zip(np.array(ins), np.array(out)): image_p = np.dot(A, p) + t result = "[OK]" if np.allclose(image_p, P) else "[ERROR]" print(p, " mapped to: ", image_p, " ; expected: ", P, result) 

This code demonstrates how to reconstruct an affine transformation in the form of a matrix and a vector, and verifies that the starting points are displayed where they should. You can check this code with google colab , so you don't need to install anything. Perhaps you can translate it to Matlab.

As for the theory underlying this code: it is based on the equation presented in the โ€œ Beginner's Guide to Displaying Affinely Simplex Simplexes โ€, the matrix recovery is described in the โ€œRestoring Canonical Recordโ€ section. The same authors published a workbook on affine mapping of simplexes , which contains many practical examples of this kind.

+1
source share

You can check the following two preprints that were recently uploaded to Research Gate:

  • The book on the affine mapping of simplexes contains several examples, exactly the way you want the book
  • The "Guide for the Beginning Display of Affine Simplexes" develops a theory, but the "Small Example" section contains an example of reconstructing an affine display using given images of 3 points of the theory
0
source share

All Articles