Python (numpy?) - build transformation matrix from sets of source and destination points

Viewed 53

Let's imagine I have two sets points in a 2d Euclidean system:

src = [
    [722.6, 1571.4],
    [832, 1466],
    [419, 1482],
    [1005, 2804],
    <snip>
]
dst = [
    [35839.65, 49808.55],
    [42771.08, 41488.07],
    [15764.26, 44065.95],
    [72760.36, 76645.15],
    <snip>
]

where src[0] is mapped to dst[0], src[1] is mapped to dst[1], etc.

Assuming I have enough points to do this (several thousand, actually), how could one use a sample to solve the transformation matrix M that results in all src coordinates becoming their respective dst coordinates?

so src[0] in the old system is mapped to dst[0], src[1] is mapped to dst[1], src[2] is mapped to dst[2], src[3] is mapped to dst[3], and so on.

so for each point pair:

dst[i] = M x src[i]
1 Answers

You are probably looking for a rigid registration, which aligns the point sets allowing rotation and translation, or you may be looking for an affine registration, which also allows changes in scale, shear or reflection.

You can use the function affine_matrix_from_points() from the Transforms3d library (although it works in 3D).

Related