PyCPD

PyCPD: Pure NumPy Implementation of the Coherent Point Drift Algorithm - Published in JOSS (2022)

https://github.com/siavashk/pycpd

Science Score: 95.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 4 DOI reference(s) in README and JOSS metadata
  • Academic publication links
    Links to: arxiv.org, joss.theoj.org
  • Committers with academic emails
    4 of 17 committers (23.5%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
    Published in Journal of Open Source Software

Keywords

expectation-maximization point-cloud python registration

Scientific Fields

Earth and Environmental Sciences Physical Sciences - 40% confidence
Last synced: 4 months ago · JSON representation

Repository

Pure Numpy Implementation of the Coherent Point Drift Algorithm

Basic Info
  • Host: GitHub
  • Owner: siavashk
  • License: mit
  • Language: Python
  • Default Branch: master
  • Size: 14.4 MB
Statistics
  • Stars: 568
  • Watchers: 14
  • Forks: 124
  • Open Issues: 6
  • Releases: 2
Topics
expectation-maximization point-cloud python registration
Created about 9 years ago · Last pushed over 2 years ago
Metadata Files
Readme Changelog Contributing License Code of conduct

README.rst

#############
Python-CPD
#############

.. |master_badge| image:: https://github.com/siavashk/pycpd/actions/workflows/build-test.yml/badge.svg?branch=master
.. |development_badge| image:: https://github.com/siavashk/pycpd/actions/workflows/build-test.yml/badge.svg?branch=development
.. |joss_paper_badge| image:: https://joss.theoj.org/papers/10.21105/joss.04681/status.svg
   :target: https://doi.org/10.21105/joss.04681

+-----------------+---------------------+
| Paper Citation  | |joss_paper_badge|  |
+-----------------+---------------------+

+-----------------+---------------------+
|            Build Status               |
+-----------------+---------------------+
| master          | |master_badge|      |
+-----------------+---------------------+
| development     | |development_badge| |
+-----------------+---------------------+



`Documentation `_

Pure Numpy Implementation of the Coherent Point Drift Algorithm.

MIT License.

*************
Introduction
*************

This is a pure numpy implementation of the coherent point drift `CPD `_ algorithm by Myronenko and Song for use by the python community. It provides three registration methods for point clouds: 1) Scale and rigid registration; 2) Affine registration; and 3) Gaussian regularized non-rigid registration.

The CPD algorithm is a registration method for aligning two point clouds. In this method, the moving point cloud is modelled as a Gaussian Mixture Model (GMM) and the fixed point cloud are treated as observations from the GMM. The optimal transformation parameters maximze the Maximum A Posteriori (MAP) estimation that the observed point cloud is drawn from the GMM.

The registration methods work for arbitrary MxN 2D arrays where M is the number of "points" and N is the number of dimensions. A typical point cloud would be Mx2 or Mx3 for 2D and 3D points clouds respectively. For more information, please refer to my `blog `_.

*************
Installation
*************

Install from PyPI
#################

.. code-block:: bash

  pip install pycpd

Installation from Source
########################

Clone the repository to a location, referred to as the ``root`` folder. For example:

.. code-block:: bash

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

Install the package:

.. code-block:: bash

  pip install .

or 

.. code-block:: bash

  make requirements
  make build

Install Matplotlib for Visualization
####################################

For running sample registration examples under ``/examples``, you will need ``Matplotlib`` to visualize the registration. This can be downloaded by running:

.. code-block:: bash

 pip install matplotlib

or 

.. code-block:: bash

  make visualize
  
*****
Usage
*****

Each registration method is contained within a single class inside the ``pycpd`` subfolder. To try out the registration, you can simply run:

.. code-block:: bash

python examples/fish_{Transform}_{Dimension}.py

where ``Transform`` is either ``rigid``, ``affine`` or ``deformable`` and ``Dimension`` is either ``2D`` or ``3D``. Note that examples are meant to be run from the ``root`` folder.

********
Example
********

Basic Usage
###########

Basic usage includes providing any of the registration methods with 2 arrays that are MxN & BxN. E.g., they can have different numbers of points (M & B) but must have the same number of dimensions per point (N).

.. code-block:: python

  from pycpd import RigidRegistration
  import numpy as np

  # create 2D target points (you can get these from any source you desire)
  # creating a square w/ 2 additional points. 
  target = np.array([[0, 0], [0, 1], [1, 0], [1, 1], [0.5, 0], [0, 0.5]])
  print('Target Points: \n', target)

  # create a translation to apply to the target for testing the registration
  translation = [1, 0]

  # create a fake source by adding a translation to the target.
  # in a real use, you would load the source points from a file or other source. 
  # the only requirement is that this array also be 2-dimensional and that the 
  # second dimension be the same length as the second dimension of the target array.
  source = target + translation
  print('Source Points: \n', source)

  # create a RigidRegistration object
  reg = RigidRegistration(X=target, Y=source)
  # run the registration & collect the results
  TY, (s_reg, R_reg, t_reg) = reg.register()

  # TY is the transformed source points
  # the values in () are the registration parameters.
  # In this case of rigid registration they are:
  #     s_reg the scale of the registration
  #     R_reg the rotation matrix of the registration
  #     t_reg the translation of the registration


The affine and deformable registration methods are used in the same way, but provide their respective transformation parameters.

Apply Transform to Another Point Cloud
#######################################
Sometimes you may want to apply the transformation parameters to another point cloud. For example, if you have a very large point cloud
it is sometimes appropriate to randomly sample some of the points for registration and then apply the transformation to the entire point cloud. 

To do this, after fitting the above registration, you would run `reg.transform_point_cloud(Y=points_to_transform)`. This will apply the learned 
registration parameters to the point cloud `points_to_transform` and return the transformed point cloud.

Tuning Registration parameters
##############################

For rigid and affine registrations the main parameter you can tweak is `w`. The `w` parameter is an indication of the amount of noise in the 
point clouds `[0,1]`, by default it is set to `0` assuming no noise, but can be set at any value `0 <= w <1` with higher values indicating more noise. 

For deformable registration, you can also tune `alpha`, `beta`, and use `low_rank`. 

The `alpha` parameter (`lambda` in the original paper) identifies a tradeoff between making points align & regularization of the deformation. 
A higher value makes the deformation more rigid, a lower value makes the deformation more flexible. 

The `beta` is the width of the Gaussian kernel used to regularize the deformation and thus identifies how far apart points should be
to move them together (coherently). `beta` depends on the scale/size of your points cloud. Tuning `beta` can be simplified by normalizing 
the point cloud to a unit sphere distance.

The `low_rank` parameter is a boolean that indicates whether to use a regularized form of the deformation field. This further
constrains the deformation, while vastly speeding up the optimization. `num_eig` is the number of eigenvalues to use in the low rank 
approximation. `num_eig` should be less than the number of points in the point cloud, the lower the smoother the deformation and the
faster the optimization.



*******
Testing
*******

Tests can be run using pytest:

.. code-block:: bash

 pip install pytest
 pytest

or 

.. code-block:: bash
  
  make dev
  make test

*************
Documentation
*************

The documentation can be built using pydoc3

.. code-block:: bash
  
  make dev
  make doc

************
Contributing
************

Contributions are welcome. Please see the guidelines outlined in the document: `CONTRIBUTING `_.

***************
Code of Conduct
***************
We have adopted the code of conduct defined by the `Contributor Covenant `_ to clarify expected behavior in our community. For more information see the `Code of Conduct `_.

Owner

  • Name: Siavash Khallaghi
  • Login: siavashk
  • Kind: user
  • Location: Vancouver, Canada
  • Company: Unraveled AI

The work is mysterious and important.

JOSS Publication

PyCPD: Pure NumPy Implementation of the Coherent Point Drift Algorithm
Published
December 15, 2022
Volume 7, Issue 80, Page 4681
Authors
Anthony A. Gatti ORCID
Stanford University, USA, NeuralSeg Ltd., Canada
Siavash Khallaghi
Independent Researcher, Canada
Editor
Hugo Ledoux ORCID
Tags
Point-cloud Registration Expectation-Maximization

GitHub Events

Total
  • Watch event: 42
  • Pull request event: 3
  • Fork event: 7
Last Year
  • Watch event: 42
  • Pull request event: 3
  • Fork event: 7

Committers

Last synced: 5 months ago

All Time
  • Total Commits: 165
  • Total Committers: 17
  • Avg Commits per committer: 9.706
  • Development Distribution Score (DDS): 0.612
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Anthony Gatt a****y@n****m 64
Siavash Khallaghi s****k@e****a 40
Siavash Khallaghi s****h@S****l 12
Siavash Khallaghi s****i@c****e 9
mhr m****r 9
Siavash Khallaghi s****h@S****e 8
Arthur Porto a****o@g****m 7
Siavash Khallaghi s****h@d****a 3
Siavash Khallaghi s****h@d****a 3
Matthew DiFranco m****c@g****m 2
Hugo Ledoux h****x@t****l 2
Mariem Khlifi m****6@g****m 1
Johan Forslund j****5@g****m 1
Chaitanya k****a@g****m 1
Brandon Dube b****e@g****m 1
WEI-CHUN KAO w****n@o****m 1
vincentme 1****e 1

Issues and Pull Requests

Last synced: 4 months ago

All Time
  • Total issues: 56
  • Total pull requests: 41
  • Average time to close issues: 2 months
  • Average time to close pull requests: about 1 month
  • Total issue authors: 44
  • Total pull request authors: 18
  • Average comments per issue: 3.63
  • Average comments per pull request: 1.22
  • Merged pull requests: 30
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 3
  • Pull requests: 5
  • Average time to close issues: 2 days
  • Average time to close pull requests: about 1 hour
  • Issue authors: 1
  • Pull request authors: 4
  • Average comments per issue: 3.0
  • Average comments per pull request: 0.2
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • siavashk (5)
  • rejuce (4)
  • gattia (3)
  • BramshQamar (2)
  • stevenagl12 (2)
  • sandyhsia (2)
  • agporto (2)
  • Harry710887048 (1)
  • wbensvage (1)
  • ka-petrov (1)
  • Theophile88 (1)
  • tlambert03 (1)
  • necoxt (1)
  • mingweiY (1)
  • Reno989 (1)
Pull Request Authors
  • gattia (20)
  • rejuce (3)
  • mdifranc (2)
  • wckao (2)
  • Nikitos1865 (2)
  • hugoledoux (2)
  • omarhmoursy (2)
  • mhr (1)
  • vincentme (1)
  • sandyhsia (1)
  • ckolluru (1)
  • STForyoung (1)
  • ghost (1)
  • brandondube (1)
  • khmariem (1)
Top Labels
Issue Labels
bug (6) stat:awaiting response (4) help wanted (4) question (4) documentation (1) enhancement (1)
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 2,819 last-month
  • Total docker downloads: 8
  • Total dependent packages: 4
  • Total dependent repositories: 9
  • Total versions: 12
  • Total maintainers: 1
pypi.org: pycpd

Pure Numpy Implementation of the Coherent Point Drift Algorithm

  • Versions: 12
  • Dependent Packages: 4
  • Dependent Repositories: 9
  • Downloads: 2,819 Last month
  • Docker Downloads: 8
Rankings
Stargazers count: 2.9%
Dependent packages count: 3.2%
Docker downloads count: 4.1%
Average: 4.2%
Forks count: 4.4%
Dependent repos count: 4.8%
Downloads: 5.6%
Maintainers (1)
Last synced: 4 months ago

Dependencies

.github/workflows/build-test.yml actions
  • actions/checkout v2 composite
  • actions/setup-python v2 composite
.github/workflows/docs.yml actions
  • actions/checkout v3 composite
  • actions/deploy-pages v1 composite
  • actions/setup-python v3 composite
  • actions/upload-artifact v3 composite
.github/workflows/draft-pdf.yml actions
  • actions/checkout v2 composite
  • actions/upload-artifact v1 composite
  • openjournals/openjournals-draft-action master composite
requirements.txt pypi
  • numpy *
setup.py pypi
  • future *
  • numpy *