Affine map from landmark pairs
affine_from_landmarks.RdLeast-squares affine map taking landmarks of a source to the matching landmarks of a target.
This is what landmark_affine() computes from the points you click.
Details
The result is a 2 x 3 matrix M = [L | T] that acts on positions (x, y) (x first):
(x', y') = L (x, y) + T, with L = M[, 1:2] and T = M[, 3]. Apply it with apply_affine().
This is not the matrix A of lddmm(). A is 3 x 3 and works on (row, column) = (y, x)
coordinates of the rasterized images. The usual route is to move the source cells with
apply_affine() before rasterizing, as in vignette("lddmm-merfish").
Examples
from <- cbind(x = c(0, 10, 0, 10), y = c(0, 0, 10, 10))
to <- cbind(x = c(5, 5, -5, -5), y = c(0, 10, 0, 10)) # a counter-clockwise quarter turn, then +5 in x
M <- affine_from_landmarks(from, to)
round(M, 6)
#> [,1] [,2] [,3]
#> [1,] 0 -1 5
#> [2,] 1 0 0
apply_affine(from, M)
#> x y
#> [1,] 5 -1.880575e-15
#> [2,] 5 1.000000e+01
#> [3,] -5 -6.268584e-16
#> [4,] -5 1.000000e+01