spateo.alignment.methods.mesh_correction_utils ============================================== .. py:module:: spateo.alignment.methods.mesh_correction_utils Functions --------- .. autoapisummary:: spateo.alignment.methods.mesh_correction_utils._transform_points spateo.alignment.methods.mesh_correction_utils._extract_contour_opencv spateo.alignment.methods.mesh_correction_utils._extract_contour_alpha_shape spateo.alignment.methods.mesh_correction_utils._smooth_contours spateo.alignment.methods.mesh_correction_utils._extract_contours_from_mesh spateo.alignment.methods.mesh_correction_utils._generate_labeling spateo.alignment.methods.mesh_correction_utils._update_parameter spateo.alignment.methods.mesh_correction_utils._make_pairs spateo.alignment.methods.mesh_correction_utils._getUnaries spateo.alignment.methods.mesh_correction_utils._get_parameters_from_pair spateo.alignment.methods.mesh_correction_utils._getBinary spateo.alignment.methods.mesh_correction_utils._get_binary_values spateo.alignment.methods.mesh_correction_utils._calculate_loss spateo.alignment.methods.mesh_correction_utils.ICP spateo.alignment.methods.mesh_correction_utils.solve_RT_by_correspondence Module Contents --------------- .. py:function:: _transform_points(points: numpy.ndarray, rotation: Union[numpy.ndarray, list], translation: Union[numpy.ndarray, list], scaling: float) -> numpy.ndarray Transforms the given points by applying rotation, translation, and scaling. :param points: The points to be transformed, with shape (N, 3). :type points: np.ndarray :param rotation: The rotation angles (in degrees) around x, y, and z axes. :type rotation: Union[np.ndarray, list] :param translation: The translation vector only for z axes. :type translation: Union[np.ndarray, list] :param scaling: The scaling factor with single float. :type scaling: Union[float, np.ndarray] :returns: The transformed points with shape (N, 3). :rtype: np.ndarray .. py:function:: _extract_contour_opencv(points: numpy.ndarray, average_n: float = 0.2, kernel_size: Optional[int] = None) -> List[numpy.ndarray] Extracts contours from a point cloud using OpenCV. :param points: A numpy array of shape (N, 2) representing the point cloud in a slice. :type points: np.ndarray :param average_n: Average number of points per unit area. Defaults to 0.2. :type average_n: float, optional :param kernel_size: Size of the structuring element for morphological operations. If None, it will be computed based on the image size. Defaults to None. :type kernel_size: Optional[int], optional :returns: A list of numpy arrays, each containing the contour of the points of slice. :rtype: List[np.ndarray] .. py:function:: _extract_contour_alpha_shape(points: numpy.ndarray, alpha: float = 0.5) -> List[numpy.ndarray] Extracts contours from a point cloud in a slice using the alpha shape method. :param points: A numpy array of shape (N, 2) representing the point cloud. :type points: np.ndarray :param alpha: Alpha parameter for the alpha shape algorithm. Defaults to 0.5. :type alpha: float, optional :returns: A list of numpy arrays, each containing the vertices of a contour. :rtype: List[np.ndarray] .. py:function:: _smooth_contours(vertex: List[numpy.ndarray], window_size: int = 5, iterations: int = 1) Smooths the contours using a moving average filter. :param vertex: List of contour vertices to be smoothed. :type vertex: List[np.ndarray] :param window_size: Size of the smoothing window. Defaults to 5. :type window_size: int, optional :param iterations: Number of smoothing iterations. Defaults to 1. :type iterations: int, optional :returns: List of smoothed contour vertices. :rtype: List[np.ndarray] .. py:function:: _extract_contours_from_mesh(mesh, z_values) .. py:function:: _generate_labeling(max_value: float, number_of_steps: int, scale_type: str = 'linear') -> List[float] Generates labeling values for a given parameter. :param max_value: The maximum value for the parameter. :type max_value: float :param number_of_steps: The number of labels to generate. :type number_of_steps: int :param scale_type: The scale type ('linear' or 'log'). Defaults to 'linear'. :type scale_type: str, optional :returns: A list of generated labels. :rtype: List[float] .. py:function:: _update_parameter(transformation_labels, parameters) .. py:function:: _make_pairs(nVars=5) .. py:function:: _getUnaries(L, N=5) .. py:function:: _get_parameters_from_pair(pair, transformation_labels) .. py:function:: _getBinary(contours, mesh, z_values, pairs, transformation_labels, verbose: bool = False) .. py:function:: _get_binary_values(contours, mesh, z_values, pair, transformation_labels) .. py:function:: _calculate_loss(contours, mesh, transformation, z_values, method: Literal['CPD', 'ICP'] = 'ICP') .. py:function:: 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, Union[float, numpy.ndarray], numpy.ndarray, numpy.ndarray, numpy.ndarray] Iterative Closest Point (ICP) algorithm for aligning two sets of points. :param contour_1: Data points. :type contour_1: np.ndarray :param contour_2: Model points. :type contour_2: np.ndarray :param max_iter: Maximum number of iterations. Defaults to 20. :type max_iter: int, optional :param error_threshold: Error threshold for convergence. Defaults to 1e-6. :type error_threshold: float, optional :param inlier_threshold: Inlier threshold distance. Defaults to 0.1. :type inlier_threshold: float, optional :param subsample: Number of points to subsample. Defaults to 500. :type subsample: int, optional :param allow_rotation: Whether to allow estimate rotation. Defaults to False. :type allow_rotation: bool, optional :returns: Convergence ratio, sigma2 (placeholder), translation vector, original contour, transformed contour, rotation matrix. :rtype: Tuple[float, float, Union[float, np.ndarray], np.ndarray, np.ndarray, np.ndarray] .. py:function:: solve_RT_by_correspondence(X: numpy.ndarray, Y: numpy.ndarray, return_scale: bool = False) -> Union[Tuple[numpy.ndarray, numpy.ndarray], Tuple[numpy.ndarray, numpy.ndarray, float]] Solve for the rotation matrix R and translation vector t that best align the points in X to the points in Y. :param X: Source points, shape (N, D). :type X: np.ndarray :param Y: Target points, shape (N, D). :type Y: np.ndarray :param return_scale: Whether to return the scale factor. Defaults to False. :type return_scale: bool, optional :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. :rtype: Union[Tuple[np.ndarray, np.ndarray], Tuple[np.ndarray, np.ndarray, float]]