pycpd Documentation

repository·master·Indexed 20 days ago

https://github.com/siavashk/pycpd

A pure NumPy implementation of the Coherent Point Drift (CPD) algorithm for registering point clouds. It supports rigid, affine, and deformable (non-rigid) transformations using an Expectation Maximization (EM) approach. The library provides classes such as RigidRegistration, AffineRegistration, and DeformableRegistration to align source point clouds to target observations.

Tokens
1.2K
Snippets
5
Records
8
Agent score
20%

What's inside pycpd

  1. Overview of PyCPD registration methods

    master

    PyCPD is a pure NumPy implementation of the Coherent Point Drift (CPD) algorithm. It provides three main types of point cloud registration by inheriting from an Expectation Maximization (EM) module:

    1. Rigid Registration: Finds transformations involving only rotations and translations.
    2. Affine Registration: Finds transformations including rigid movements plus shearing and scaling.
    3. Deformable (Non-rigid) Registration: Finds non-linear deformations. This implementation includes a low-rank approximation of the Gaussian kernel to reduce computation time and provide regularization for the deformation.

    In all methods, the 'moving' (source) point cloud is modeled as a Gaussian Mixture Model (GMM), and the 'fixed' (target) point cloud is treated as observations. The algorithm iterates between an Expectation (E) step and a Maximization (M) step to find the optimal transformation parameters.

  2. Optimize registration performance using point subsets

    master
    To reduce computation time, you can perform CPD registration on a subset of points rather than the entire point cloud. Because the learned transformation can be applied to any point cloud, you can use a smaller subset to find the optimal parameters and then apply that transformation to the full dataset.
  3. Tune registration parameters

    master

    Rigid and Affine Registration

    • w: Indicates the amount of noise in the point clouds. A value in the range $[0, 1)$. Default is 0 (no noise). Higher values indicate more noise.

    Deformable Registration

    • alpha: Tradeoff between point alignment and regularization. Higher values make the deformation more rigid; lower values make it more flexible.
    • beta: Width of the Gaussian kernel used to regularize deformation. It determines how far apart points must be to move them together coherently. Tuning is often simplified by normalizing the point cloud to a unit sphere distance.
    • low_rank: A boolean indicating whether to use a regularized form of the deformation field. This constrains deformation and speeds up optimization.
    • num_eig: Used with low_rank. The number of eigenvalues for the low rank approximation. Should be less than the number of points. Lower values result in smoother deformation and faster optimization.
  4. Install pycpd from source

    master

    To install from source, clone the repository and install the package using pip or the provided Makefile.

    git clone https://github.com/siavashk/pycpd.git $HOME/pycpd
    cd $HOME/pycpd
    pip install .

    Alternatively, you can use:

    make requirements
    make build
    git clone https://github.com/siavashk/pycpd.git $HOME/pycpd
    pip install .
  5. Perform point cloud registration with pycpd

    master

    The library provides three registration methods for aligning two point clouds (moving and fixed). The input arrays must be $M \times N$ and $B \times N$, where $M$ and $B$ are the number of points and $N$ is the number of dimensions (e.g., 2 for 2D, 3 for 3D). The number of dimensions $N$ must match for both arrays.

    Available registration classes:

    1. RigidRegistration: Scale and rigid registration.
    2. AffineRegistration: Affine registration.
    3. DeformableRegistration: Gaussian regularized non-rigid registration.

    To register, instantiate the class with X (target/fixed points) and Y (source/moving points), then call .register().

    from pycpd import RigidRegistration
    import numpy as np
    
    # target (fixed) points
    target = np.array([[0, 0], [0, 1], [1, 0], [1, 1], [0.5, 0], [0, 0.5]])
    # source (moving) points
    source = target + np.array([1, 0])
    
    # Create registration object
    reg = RigidRegistration(X=target, Y=source)
    
    # Run registration
    # TY is the transformed source points
    # The second return value contains the registration parameters
    TY, (s_reg, R_reg, t_reg) = reg.register()
  6. Install Matplotlib for visualization

    master

    To run the sample registration examples located in the /examples directory, you must have matplotlib installed.

    pip install matplotlib

    Or use the Makefile:

    make visualize
  7. Apply learned transformation to a new point cloud

    master

    If you have a large point cloud and want to apply a transformation learned from a smaller sample, use the transform_point_cloud method after running the registration.

    # After running reg.register()...
    # points_to_transform is a new MxN array
    transformed_points = reg.transform_point_cloud(Y=points_to_transform)