spateo.alignment.methods.mesh_correction_utils

Functions

_transform_points(→ numpy.ndarray)

Transforms the given points by applying rotation, translation, and scaling.

_extract_contour_opencv(→ List[numpy.ndarray])

Extracts contours from a point cloud using OpenCV.

_extract_contour_alpha_shape(→ List[numpy.ndarray])

Extracts contours from a point cloud in a slice using the alpha shape method.

_smooth_contours(vertex[, window_size, iterations])

Smooths the contours using a moving average filter.

_extract_contours_from_mesh(mesh, z_values)

_generate_labeling(→ List[float])

Generates labeling values for a given parameter.

_update_parameter(transformation_labels, parameters)

_make_pairs([nVars])

_getUnaries(L[, N])

_get_parameters_from_pair(pair, transformation_labels)

_getBinary(contours, mesh, z_values, pairs, ...[, verbose])

_get_binary_values(contours, mesh, z_values, pair, ...)

_calculate_loss(contours, mesh, transformation, z_values)

ICP(→ Tuple[float, float, Union[float, numpy.ndarray], ...)

Iterative Closest Point (ICP) algorithm for aligning two sets of points.

solve_RT_by_correspondence(...)

Solve for the rotation matrix R and translation vector t that best align the points in X to the points in Y.

Module Contents

spateo.alignment.methods.mesh_correction_utils._transform_points(points: numpy.ndarray, rotation: numpy.ndarray | list, translation: numpy.ndarray | list, scaling: float) numpy.ndarray[source]

Transforms the given points by applying rotation, translation, and scaling.

Parameters:
points np.ndarray

The points to be transformed, with shape (N, 3).

rotation Union[np.ndarray, list]

The rotation angles (in degrees) around x, y, and z axes.

translation Union[np.ndarray, list]

The translation vector only for z axes.

scaling Union[float, np.ndarray]

The scaling factor with single float.

Returns:

The transformed points with shape (N, 3).

Return type:

np.ndarray

spateo.alignment.methods.mesh_correction_utils._extract_contour_opencv(points: numpy.ndarray, average_n: float = 0.2, kernel_size: int | None = None) List[numpy.ndarray][source]

Extracts contours from a point cloud using OpenCV.

Parameters:
points np.ndarray

A numpy array of shape (N, 2) representing the point cloud in a slice.

average_n float, optional

Average number of points per unit area. Defaults to 0.2.

kernel_size Optional[int], optional

Size of the structuring element for morphological operations. If None, it will be computed based on the image size. Defaults to None.

Returns:

A list of numpy arrays, each containing the contour of the points of slice.

Return type:

List[np.ndarray]

spateo.alignment.methods.mesh_correction_utils._extract_contour_alpha_shape(points: numpy.ndarray, alpha: float = 0.5) List[numpy.ndarray][source]

Extracts contours from a point cloud in a slice using the alpha shape method.

Parameters:
points np.ndarray

A numpy array of shape (N, 2) representing the point cloud.

alpha float, optional

Alpha parameter for the alpha shape algorithm. Defaults to 0.5.

Returns:

A list of numpy arrays, each containing the vertices of a contour.

Return type:

List[np.ndarray]

spateo.alignment.methods.mesh_correction_utils._smooth_contours(vertex: List[numpy.ndarray], window_size: int = 5, iterations: int = 1)[source]

Smooths the contours using a moving average filter.

Parameters:
vertex List[np.ndarray]

List of contour vertices to be smoothed.

window_size int, optional

Size of the smoothing window. Defaults to 5.

iterations int, optional

Number of smoothing iterations. Defaults to 1.

Returns:

List of smoothed contour vertices.

Return type:

List[np.ndarray]

spateo.alignment.methods.mesh_correction_utils._extract_contours_from_mesh(mesh, z_values)[source]
spateo.alignment.methods.mesh_correction_utils._generate_labeling(max_value: float, number_of_steps: int, scale_type: str = 'linear') List[float][source]

Generates labeling values for a given parameter.

Parameters:
max_value float

The maximum value for the parameter.

number_of_steps int

The number of labels to generate.

scale_type str, optional

The scale type (‘linear’ or ‘log’). Defaults to ‘linear’.

Returns:

A list of generated labels.

Return type:

List[float]

spateo.alignment.methods.mesh_correction_utils._update_parameter(transformation_labels, parameters)[source]
spateo.alignment.methods.mesh_correction_utils._make_pairs(nVars=5)[source]
spateo.alignment.methods.mesh_correction_utils._getUnaries(L, N=5)[source]
spateo.alignment.methods.mesh_correction_utils._get_parameters_from_pair(pair, transformation_labels)[source]
spateo.alignment.methods.mesh_correction_utils._getBinary(contours, mesh, z_values, pairs, transformation_labels, verbose: bool = False)[source]
spateo.alignment.methods.mesh_correction_utils._get_binary_values(contours, mesh, z_values, pair, transformation_labels)[source]
spateo.alignment.methods.mesh_correction_utils._calculate_loss(contours, mesh, transformation, z_values, method: Literal['CPD', 'ICP'] = 'ICP')[source]
spateo.alignment.methods.mesh_correction_utils.ICP(contour_1: numpy.ndarray, contour_2: numpy.ndarray, max_iter: int = 20, error_threshold: float = 1e-06, inlier_threshold: float = 0.1, subsample: int = 500, allow_rotation: bool = False) Tuple[float, float, float | numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray][source]

Iterative Closest Point (ICP) algorithm for aligning two sets of points.

Parameters:
contour_1 np.ndarray

Data points.

contour_2 np.ndarray

Model points.

max_iter int, optional

Maximum number of iterations. Defaults to 20.

error_threshold float, optional

Error threshold for convergence. Defaults to 1e-6.

inlier_threshold float, optional

Inlier threshold distance. Defaults to 0.1.

subsample int, optional

Number of points to subsample. Defaults to 500.

allow_rotation bool, optional

Whether to allow estimate rotation. Defaults to False.

Returns:

Convergence ratio, sigma2 (placeholder), translation vector, original contour, transformed contour, rotation matrix.

Return type:

Tuple[float, float, Union[float, np.ndarray], np.ndarray, np.ndarray, np.ndarray]

spateo.alignment.methods.mesh_correction_utils.solve_RT_by_correspondence(X: numpy.ndarray, Y: numpy.ndarray, return_scale: bool = False) Tuple[numpy.ndarray, numpy.ndarray] | Tuple[numpy.ndarray, numpy.ndarray, float][source]

Solve for the rotation matrix R and translation vector t that best align the points in X to the points in Y.

Parameters:
X np.ndarray

Source points, shape (N, D).

Y np.ndarray

Target points, shape (N, D).

return_scale bool, optional

Whether to return the scale factor. Defaults to False.

Returns:

If return_scale is False, returns the rotation matrix R and translation vector t. If return_scale is True, also returns the scale factor s.

Return type:

Union[Tuple[np.ndarray, np.ndarray], Tuple[np.ndarray, np.ndarray, float]]