cedalion.geometry.registration

Registrating optodes to scalp surfaces.

Functions

find_spread_points(points_xr)

Selects three points that are spread apart from each other in the dataset.

gen_xform_from_pts(p1, p2)

Calculate the affine transformation matrix T that transforms p1 to p2.

icp_with_full_transform(opt_centers, ...[, ...])

Perform Iterative Closest Point algorithm with full transformation capabilities.

register_icp(surface, landmarks, geo3d[, ...])

Iterative Closest Point algorithm for registration.

register_trans_rot(coords_target, coords_trafo)

Finds affine transformation between coords_target and coords_trafo.

register_trans_rot_isoscale(coords_target, ...)

Finds affine transformation between coords_target and coords_trafo.

register_trans_rot_scale(coords_target, ...)

Finds affine transformation between coords_target and coords_trafo.

simple_scalp_projection(geo3d)

Projects 3D coordinates onto a 2D plane using a simple scalp projection.

cedalion.geometry.registration.register_trans_rot(
coords_target: Annotated[DataArray, DataArraySchema(dims='label', coords='label', 'label', 'type')],
coords_trafo: Annotated[DataArray, DataArraySchema(dims='label', coords='label', 'label', 'type')],
)[source]

Finds affine transformation between coords_target and coords_trafo.

Uses translation and roatation rotation. Requires at least 3 common labels between the two point clouds.

Parameters:
  • coords_target (LabeledPointCloud) – Target point cloud.

  • coords_trafo (LabeledPointCloud) – Source point cloud.

Returns:

Affine transformation between the two point clouds.

Return type:

cdt.AffineTransform

cedalion.geometry.registration.register_trans_rot_isoscale(
coords_target: Annotated[DataArray, DataArraySchema(dims='label', coords='label', 'label', 'type')],
coords_trafo: Annotated[DataArray, DataArraySchema(dims='label', coords='label', 'label', 'type')],
)[source]

Finds affine transformation between coords_target and coords_trafo.

Uses translation, rotation and isotropic scaling. Requires at least 3 common labels between the two point clouds.

Parameters:
  • coords_target (LabeledPointCloud) – Target point cloud.

  • coords_trafo (LabeledPointCloud) – Source point cloud.

Returns:

Affine transformation between the two point clouds.

Return type:

cdt.AffineTransform

cedalion.geometry.registration.register_trans_rot_scale(
coords_target: Annotated[DataArray, DataArraySchema(dims='label', coords='label', 'label', 'type')],
coords_trafo: Annotated[DataArray, DataArraySchema(dims='label', coords='label', 'label', 'type')],
)[source]

Finds affine transformation between coords_target and coords_trafo.

Uses translation, rotation and scaling. Requires at least 3 common labels between the two point clouds.

Parameters:
  • coords_target (LabeledPointCloud) – Target point cloud.

  • coords_trafo (LabeledPointCloud) – Source point cloud.

Returns:

Affine transformation between the two point clouds.

Return type:

cdt.AffineTransform

cedalion.geometry.registration.gen_xform_from_pts(p1: ndarray, p2: ndarray) ndarray[source]

Calculate the affine transformation matrix T that transforms p1 to p2.

Parameters:
  • p1 (np.ndarray) – Source points (p x m) where p is the number of points and m is the number of dimensions.

  • p2 (np.ndarray) – Target points (p x m) where p is the number of points and m is the number of dimensions.

Returns:

Affine transformation matrix T.

cedalion.geometry.registration.register_icp(
surface: Surface,
landmarks: Annotated[DataArray, DataArraySchema(dims='label', coords='label', 'label', 'type')],
geo3d: Annotated[DataArray, DataArraySchema(dims='label', coords='label', 'label', 'type')],
niterations=1000,
random_sample_fraction=0.5,
)[source]

Iterative Closest Point algorithm for registration.

Parameters:
  • surface (Surface) – Surface mesh to which to register the points.

  • landmarks (LabeledPointCloud) – Landmarks to use for registration.

  • geo3d (LabeledPointCloud) – Points to register to the surface.

  • niterations (int) – Number of iterations for the ICP algorithm (default 1000).

  • random_sample_fraction (float) – Fraction of points to use in each iteration (default 0.5).

Returns:

Tuple containing the losses and transformations

Return type:

Tuple[np.ndarray, np.ndarray]

cedalion.geometry.registration.icp_with_full_transform(
opt_centers: Annotated[DataArray, DataArraySchema(dims='label', coords='label', 'label', 'type')],
montage_points: Annotated[DataArray, DataArraySchema(dims='label', coords='label', 'label', 'type')],
max_iterations: int = 50,
tolerance: float = 500.0,
)[source]

Perform Iterative Closest Point algorithm with full transformation capabilities.

Parameters:
  • opt_centers – Source point cloud for alignment.

  • montage_points – Target reference point cloud.

  • max_iterations – Maximum number of iterations for convergence.

  • tolerance – Tolerance for convergence check.

Returns:

Transformed source points as a numpy array with their coordinates

updated to reflect the best alignment.

np.ndarray: Transformation parameters array consisting of

[tx, ty, tz, rx, ry, rz, sx, sy, sz], where ‘t’ stands for translation components, ‘r’ for rotation components (in radians), and ‘s’ for scaling components.

np.ndarray: Indices of the target points that correspond to each source point as

per the nearest neighbor search.

Return type:

np.ndarray

cedalion.geometry.registration.find_spread_points(points_xr: DataArray) ndarray[source]

Selects three points that are spread apart from each other in the dataset.

Parameters:

points_xr – An xarray DataArray containing the points from which to select.

Returns:

Indices of the initial, farthest, and median-distanced points from the initial point as determined by their positions in the original dataset.

cedalion.geometry.registration.simple_scalp_projection(
geo3d: Annotated[DataArray, DataArraySchema(dims='label', coords='label', 'label', 'type')],
) Annotated[DataArray, DataArraySchema(dims='label', coords='label', 'label', 'type')][source]

Projects 3D coordinates onto a 2D plane using a simple scalp projection.

Parameters:

geo3d (LabeledPointCloud) – 3D coordinates of points to project. Requires the landmarks Nz, LPA, and RPA.

Returns:

A LabeledPointCloud containing the 2D coordinates of the projected points.