Warp
Namespace: MATHLIB · Library: Math Library
#include <math/warp.h>
class UTILSLIB::Warp
Thin-plate-spline (Bookstein) 3-D warp that maps source landmarks exactly onto destination landmarks and extends smoothly to the rest of R^3.
Used for non-rigid registration of EEG/MEG sensors and template-to-subject mesh warping.
Thin-plate-spline 3-D warp fitted from landmark correspondences.
// Landmarks moved by a pure translation: the thin-plate spline must reproduce it exactly
MatrixXf sourceLm(5, 3);
sourceLm << 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1;
const MatrixXf destLm = sourceLm.rowwise() + RowVector3f(0.5f, -0.2f, 0.1f);
MatrixXf vertices(2, 3);
vertices << 0.3f, 0.4f, 0.5f, 0.9f, 0.1f, 0.2f;
Warp warp;
const MatrixXf warped = warp.calculate(sourceLm, destLm, vertices);
Public Methods
calculate(sLm, dLm, sVert)
Calculates the TPS Warp of given setup.
Parameters:
-
sLm : const Eigen::MatrixXf & 3D Landmarks of the source geometry.
-
dLm : const Eigen::MatrixXf & 3D Landmarks of the destination geometry.
-
sVert : const Eigen::MatrixXf & Vertices of the source geometry.
Returns:
- Eigen::MatrixXf — wVert Vertices of the warped destination geometry.
calculate(sLm, dLm, vertList)
Calculates the TPS Warp of a given setup for a List of vertices.
Parameters:
-
sLm : const Eigen::MatrixXf & 3D Landmarks of the source geometry.
-
dLm : const Eigen::MatrixXf & 3D Landmarks of the destination geometry.
-
vertList : QList< Eigen::MatrixXf > & List of Vertices of the source geometry that are warped to the destination.
readsLm(electrodeFileName)
Read electrode positions from MRI Database.
Parameters:
- electrodeFileName : const QString & .txt file of electrodes.
Returns:
- Eigen::MatrixXf — electrodes Matrix with electrode positions.
readsLm(electrodeFileName)
Read electrode positions from MRI Database.
Parameters:
- electrodeFileName : const std::string & .txt file of electrodes.
Returns:
- Eigen::MatrixXf — electrodes Matrix with electrode positions.
Example
- Full source:
src/examples/ex_math/main.cpp - Build target:
ex_math(runs under CTest)
Used in examples
ex_math
Math library on inputs with known answers.
const MatrixXf destLm = sourceLm.rowwise() + RowVector3f(0.5f, -0.2f, 0.1f);
MatrixXf vertices(2, 3);
vertices << 0.3f, 0.4f, 0.5f, 0.9f, 0.1f, 0.2f;
Warp warp;
const MatrixXf warped = warp.calculate(sourceLm, destLm, vertices);
const float warpErr = (warped - (vertices.rowwise() + RowVector3f(0.5f, -0.2f, 0.1f))).cwiseAbs().maxCoeff();
ok &= expect(warpErr < 1e-4f, QString("TPS warp reproduces the translation (max error %1)").arg(warpErr));
ex_warp
Example demonstrating thin-plate-spline (TPS) warping with UTILSLIB::Warp.
// Fit the thin-plate spline from the landmark correspondences and apply it to
// the source vertices in one call.
//
Warp warp;
MatrixXf warpedVert = warp.calculate(sourceLm, destLm, sourceVert);
Authors of this file
- Christoph Dinh <christoph.dinh@mne-cpp.org>