Skip to contents

Least-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.

Usage

affine_from_landmarks(from, to)

Arguments

from, to

Matrices (or data frames) with two columns, x and y, and one row per landmark: the landmarks in the source and the matching ones in the target, in the same order. Three or more are needed, and not all on one line. With exactly three the map is exact, with more it is the least-squares fit.

Value

A 2 x 3 matrix.

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