findOptimalPointAlignment: Optimally aligns one point set to another

Description Usage Arguments Details Value Note Author(s) References See Also Examples

View source: R/findOptimalPointAlignment.R

Description

This function translates and rotates one point set, optimally aligning it with another point set.

Usage

1

Arguments

m1

a point set matrix

m2

a second point set matrix of the same dimensions as m1

sign

Used for debugging.

Details

This function optimally aligns point set m2 with point set m1. m1 and m2 must contain the exact same landmarks or points in the same order. Points present in m2 but not m1 should be NA in m1. They do not need to be NA in m2; all translations and rotations will be applied to all points in m2 even though only shared points will be used in the alignment.

The function first centers the centroid m2 about the centroid of m1. The function svd() is then used to find the 3D rotation matrix that optimally aligns m2 to m1 based on common points. The positions of points in m2 relative to one another are unchanged. Thus, optimal rotation is constrained to already translated point sets. Depending on the point sets, a better alignment may be possible by allowing translation and rotation to be optimized simultaneously.

This function is called by unifyLandmarks to align landmark sets and by dltTestCalibration to test accuracy in reconstructed calibration grids.

Value

m2 after alignment.

Note

Modified from unifyVD() by Annat Haber.

Author(s)

Annat Haber, Aaron Olsen

References

Rohlf, F.J. (1990) "Chapter 10. Rotational fit (Procrustes) Methods." Proceedings of the Michigan Morphometrics Workshop. Ed. F. James Rohlf and Fred L. Bookstein. The University of Michigan Museum of Zoology, 1990. 227–236. Info page at lib.umich.edu

See Also

unifyLandmarks

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
## MAKE MATRIX OF 3D POINTS
m1 <- matrix(c(0,0,0, 1,3,2, 4,2,1, 5,5,3, 1,4,2, 3,6,4), nrow=6, ncol=3)

## COPY TO M2
m2 <- m1

## MAKE MISSING POINT IN M1
## ALTHOUGH NOT USED IN THE ALIGNMENT THE CORRESPONDING POINT
##  IN M2 IS STILL RETURNED AFTER ALIGNMENT
m1[3, ] <- NA

## CENTER M2 ABOUT CE
m2 <- m2 %*% rotationMatrixZYX_SM(pi/6, -pi/3, pi/8)

## TRANSLATE M2
m2 <- m2 + matrix(c(2,3,4), nrow=6, ncol=3, byrow=TRUE)

## ALIGN M2 TO M1
m3 <- findOptimalPointAlignment(m1, m2)

## NOTE THAT RETURNED MATRIX IS IDENTICAL TO M1
## OF COURSE REAL WORLD DATA WILL HAVE SOME ERROR
m1
m3

StereoMorph documentation built on May 26, 2021, 1:07 a.m.