probreg

repository·master·Indexed 21 days ago

https://github.com/neka-nat/probreg

A Python library for probabilistic point cloud registration (version 0.3.8) that implements stochastic models like Coherent Point Drift (CPD) for increased robustness over standard ICP. It features seamless integration with Open3D and supports CUDA acceleration via cupy. The library includes various algorithms such as Extended CPD, Color CPD, FilterReg, Bayesian CPD (BCPD), GMMReg/SVR, and GMMTree, supporting both rigid (6D pose, scale) and non-rigid (Affine, MCT, TPS, Deformable Kinematic) transformations.

Tokens
14.8K
Snippets
50
Records
59
Agent score
76%

What's inside probreg

  1. Explore the probreg package modules

    master

    The probreg package is organized into several specialized modules for point cloud registration and processing. Key modules include:

    • cpd: Coherent Point Drift (CPD) registration algorithms.
    • cost_functions: Various cost functions used for registration optimization.
    • filterreg: Filtering-based registration methods.
    • features: Feature extraction and description tools.
    • se3_op: Operations related to the SE(3) Lie group (transformations in 3D space).
    • transformation: Tools for applying and managing transformations.
    • gmmtree: Gaussian Mixture Model tree structures.
    • gauss_transform & gaussian_filtering: Gaussian-based transformations and filtering.
    • l2dist_regs: L2 distance-based registration methods.
    • math_utils: General mathematical utility functions.
    • callbacks: Support for callback functions during optimization processes.
  2. Overview of probreg algorithms and transformations

    master

    Probreg implements several probabilistic point cloud registration algorithms. The available transformations (Rigid vs Non-Rigid) vary by algorithm:

    Maximum Likelihood Algorithms

    • Coherent Point Drift (CPD): Supports Scale + 6D pose (Rigid) and Affine, MCT (Non-Rigid).
    • Extended CPD: Adds correspondence priors to CPD.
    • Color CPD: Color-aware registration.
    • FilterReg: Supports 6D pose (Point-to-point, Point-to-plane, FPFH-based) and experimental Deformable Kinematic (Non-Rigid).

    Variational Bayesian Inference

    • Bayesian CPD (BCPD): Experimental Combined model (Rigid + Scale + NonRigid-term).

    Distance Minimization

    • GMMReg / SVR: Supports 6D pose (Rigid) and TPS (Non-Rigid).
    • GMMTree: Supports 6D pose (Rigid).
  3. Install probreg

    master

    You can install probreg using pip for a standard installation, or clone the repository and install it in editable mode from source.

    Standard Installation

    pip install probreg

    Installation from Source

    git clone https://github.com/neka-nat/probreg.git --recursive
    cd probreg
    pip install -e .
  4. How the Transformation base class works

    master

    All transformation types inherit from the Transformation abstract base class.

    Key behaviors:

    • transform(points, array_type): This is the primary method for users. It accepts points as a numpy array or an open3d.utility.Vector3dVector. If using Open3D vectors, it converts them to the backend array type (xp), performs the transformation, and converts them back to the original array_type.
    • _transform(points): This is the internal method that subclasses must implement to define the actual mathematical operation.
    • Backend Support: The xp parameter allows the transformation to run on either numpy or cupy (GPU) for accelerated computations.
  5. How GaussTransform selects its implementation

    master

    The GaussTransform class uses a hybrid approach to balance accuracy and performance. It switches between two internal implementations based on the bandwidth parameter h:

    1. Direct Method: Used when h < sw_h. This calculates the transform directly using the formula: $$\sum_{j} \text{weights}[j] \cdot \exp\left( - \frac{||\text{target}[i] - \text{source}[j]||^2}{h^2} \right)$$
    2. IFGT (Improved Fast Gauss Transform): Used when h >= sw_h. This is an optimized implementation (via _ifgt.Ifgt) designed for efficiency when the bandwidth is larger.

    Adjusting sw_h allows you to control when the library switches from the exact direct calculation to the faster IFGT approximation.

  6. Configure FilterReg objective types

    master

    FilterReg supports two types of objective functions via the objective_type parameter:

    1. pt2pt (Point-to-Point): Standard alignment where source points are matched to target points. This is the default.
    2. pt2pl (Point-to-Plane): Alignment where source points are matched to the tangent planes of the target points. This requires providing target_normals to the algorithm.
  7. Choose a CPD transformation type

    master

    When calling registration_cpd, specify the tf_type_name to determine the degrees of freedom in the registration:

    • "rigid": Computes rotation, translation, and optionally scale. Use update_scale=True (default) to include scale.
    • "affine": Computes an affine transformation (linear mapping plus translation).
    • "nonrigid": Computes a non-rigid deformation using an RBF kernel. Requires beta (RBF kernel parameter) and lmd (regularization parameter).
    • "nonrigid_constrained": An extended non-rigid CPD that allows incorporating known point correspondences using idx_source and idx_target.
  8. How BCPD registration works (Concept)

    master

    Bayesian Coherent Point Drift (BCPD) is an Expectation-Maximization (EM) based algorithm for point cloud registration. It models the correspondence between source and target points using a probabilistic framework.

    The EM Process

    1. Expectation Step (E-step): Calculates the posterior probability of correspondences between the transformed source points and the target points, given the current transformation and noise parameters.
    2. Maximization Step (M-step): Updates the transformation parameters (rotation, translation, scale) and the noise parameters ($\sigma^2$) to maximize the expected likelihood found in the E-step.

    Key Components

    • Transformation: The algorithm estimates a CombinedTransformation which includes rotation, translation, and scale.
    • Kernels: The algorithm uses kernels (like imq or rbf) to define the smoothness/coherence of the deformation.
    • Outlier Handling: The parameter w allows for a uniform distribution component, which helps the algorithm remain robust to outliers that do not have clear correspondences in the target cloud.
  9. Perform CPD registration with Open3D

    master

    Probreg provides a simple interface for registering point clouds using Open3D objects. The following workflow demonstrates loading PCD files, applying a manual transformation to create a target, downsampling, and then computing the Coherent Point Drift (CPD) registration.

    Note: The cpd.registration_cpd function returns a transformation parameter object (tf_param) which can be used to transform the points of the source cloud.

    import copy
    import numpy as np
    import open3d as o3
    from probreg import cpd
    
    # load source and target point cloud
    source = o3.io.read_point_cloud('bunny.pcd')
    source.remove_non_finite_points()
    target = copy.deepcopy(source)
    
    # transform target point cloud
    th = np.deg2rad(30.0)
    target.transform(np.array([[np.cos(th), -np.sin(th), 0.0, 0.0],
                               [np.sin(th), np.cos(th), 0.0, 0.0],
                               [0.0, 0.0, 1.0, 0.0],
                               [0.0, 0.0, 0.0, 1.0]]))
    source = source.voxel_down_sample(voxel_size=0.005)
    target = target.voxel_down_sample(voxel_size=0.005)
    
    # compute cpd registration
    tf_param, _, _ = cpd.registration_cpd(source, target)
    result = copy.deepcopy(source)
    result.points = tf_param.transform(result.points)
    
    # draw result
    source.paint_uniform_color([1, 0, 0])
    target.paint_uniform_color([0, 1, 0])
    result.paint_uniform_color([0, 0, 1])
    o3.visualization.draw_geometries([source, target, result])