Skip to main content

Non-rigid EM-ICP surface registration with symmetric correspondences, TGD prior and RKHS M-step

Project description

clarcs

Python toolkit for the automated analysis of 3-D surfaces, with a focus on endocranial and bilateral anatomical structures.

clarcs is an extensible command-line tool built around a symmetry plane estimation algorithm described in:

Combès B., Hennessy R., Waddington J., Roberts N., Prima S.
Automatic symmetry plane estimation of bilateral objects in point clouds.
IEEE Conference on Computer Vision and Pattern Recognition (CVPR 2008). Anchorage, United States.

and used in the CLARCS research framework, presented in:

Abadie A., Combès B., Haegelen C., Prima S.
CLARCS, a C++ Library for Automated Registration and Comparison of Surfaces: Medical Applications.
MICCAI Workshop on Mesh Processing in Medical Image Analysis (MeshMed'2011). Toronto, Canada, pp. 117–126.


Installation

pip install clarcs

Or from source:

git clone <repo>
cd pyclarcs
pip install -e ".[dev]"

Dependencies (installed automatically):

Package Role
numpy ≥ 1.21 Linear algebra
scipy ≥ 1.7 KD-tree neighbour search
vtk ≥ 9.0 Surface I/O
numba ≥ 0.57 JIT-compiled kernels (4× speedup on EM stage)

Supported formats

Both reading and writing support the following formats (format inferred from file extension):

Extension Format
.vtk VTK legacy PolyData (ASCII or binary)
.vtp VTK XML PolyData
.vtu VTK XML UnstructuredGrid (read → converted to PolyData)
.ply Stanford PLY
.stl STereoLithography
.obj Wavefront OBJ

Commands

Command Description Documentation
clarcs reorient Permute the coordinate axes of a surface docs/reorient.md
clarcs symplane Estimate the best bilateral symmetry plane docs/symplane.md
clarcs recenter Rigidly align a surface to the canonical symmetry plane docs/recenter.md
clarcs centerofmass Translate a surface to match a reference's centre of mass docs/centerofmass.md
clarcs normalize Translate and uniformly scale a surface to match a reference docs/normalize.md
clarcs nlregister Non-rigidly register a surface onto a reference (EM-ICP) docs/nlregister.md

Typical pipeline

The commands are designed to be chained. A complete registration workflow (symmetry-plane alignment → scale normalisation → non-rigid registration):

# 1. Align target's symmetry plane to x = 0
clarcs recenter   target.vtk  target-recentered.vtk  --save-plane

# 2. Match size and centre of mass to the reference
clarcs normalize  target-recentered.vtk  target-normalized.vtk  --target ref.vtk

# 3. Non-rigid EM-ICP onto the reference
clarcs nlregister target-normalized.vtk  ref.vtk  target-nlregistered.vtk \
                  --deformation target-deformation.vtk

data/run_pipeline.py automates this sequence on the test surfaces bundled in data/ and writes all intermediate results to a directory of your choice:

python data/generate_samples.py          # create test surfaces (once)
python data/run_pipeline.py  results/    # run full pipeline, save to results/

Python API

from pyclarcs.io import load_surface, load_surface_with_normals, save_surface
from pyclarcs.symmetry import SymmetryPlane
from pyclarcs.principal_axes import best_principal_axis_plane
from pyclarcs.coarse import coarse_symmetry
from pyclarcs.fine import em_icp_sym, em_icp_sym_corres
from pyclarcs.alignment import align_to_symmetry_plane, align_rescale
from pyclarcs.mesh import adjacency_csr
from pyclarcs.nonrigid import nonrigid_icp, apply_deformation

# --- Symmetry plane ---
points, polygons = load_surface("surface.vtk")
plane = best_principal_axis_plane(points)
plane = coarse_symmetry(points, plane)
plane = em_icp_sym(points, plane)
plane = em_icp_sym_corres(points, plane)
plane.save("plane.pl")

# --- Non-rigid registration ---
from pyclarcs.nonrigid import nonrigid_icp, apply_deformation, estimate_registration_params

mov_pts, mov_poly, mov_n = load_surface_with_normals("target-normalized.vtk")
ref_pts, _,        ref_n = load_surface_with_normals("ref.vtk")
adj = adjacency_csr(mov_poly, len(mov_pts))

# Auto-estimate sigma, dist_cutoff and period_sigma from the surfaces.
# These three parameters are derived from the nearest-neighbour distance
# distribution between a 2 000-point subsample of the moving surface and
# the reference:
#   sigma        = 50th percentile of NN distances (median gap)
#   dist_cutoff  = max(99th percentile × 1.5,  sigma × 3)
#   period_sigma = max_iter // ceil(log2(sigma / sigma_min))
# Pass explicit values to override any of them.
params = estimate_registration_params(mov_pts, ref_pts)

def_field = nonrigid_icp(mov_pts, mov_n, ref_pts, ref_n, adj, **params)
warped    = apply_deformation(mov_pts, def_field)

Running the tests

pip install -e ".[dev]"
pytest tests/

Repository structure

pyclarcs/
├── pyproject.toml              ← packaging (PyPI-ready, installs as clarcs)
├── README.md
├── docs/                       ← per-command documentation
│   ├── reorient.md
│   ├── symplane.md
│   ├── recenter.md
│   ├── centerofmass.md
│   ├── normalize.md
│   └── nlregister.md
├── data/                       ← test surfaces and pipeline scripts
│   ├── generate_samples.py     ← generate synthetic + MNI surfaces and test pairs
│   └── run_pipeline.py         ← run recenter → rescale → register end-to-end
├── src/
│   └── pyclarcs/
│       ├── __init__.py
│       ├── __main__.py         ← python -m pyclarcs
│       ├── _cli.py             ← clarcs command + sub-commands (internal)
│       ├── symmetry.py         ← SymmetryPlane class
│       ├── principal_axes.py   ← inertia tensor, PA initialisation
│       ├── io.py               ← multi-format surface I/O via VTK 9+
│       ├── coarse.py           ← ICP + trimmed estimator, multi-resolution
│       ├── fine.py             ← EM-ICP (annealing + doubly-stochastic)
│       ├── alignment.py        ← centerofmass, rescale, recenter, orient
│       ├── mesh.py             ← mesh adjacency utilities
│       ├── nonrigid.py         ← non-rigid EM-ICP registration
│       └── _numba_kernels.py   ← JIT-compiled kernels (Numba, internal)
└── tests/
    ├── test_symmetry.py
    └── test_alignment.py

Licence

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyclarcs-0.2.0.tar.gz (44.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyclarcs-0.2.0-py3-none-any.whl (47.1 kB view details)

Uploaded Python 3

File details

Details for the file pyclarcs-0.2.0.tar.gz.

File metadata

  • Download URL: pyclarcs-0.2.0.tar.gz
  • Upload date:
  • Size: 44.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for pyclarcs-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e9c30f72a320f553246b6acdefe7dce73d2dddd416b3f69784b2ff137fb31e03
MD5 260689ed80dd104047fe798d4444a8bb
BLAKE2b-256 bc8b3e1a6585c2f331af0ec844ec01cc9af71d521ee413675556b116f7821757

See more details on using hashes here.

File details

Details for the file pyclarcs-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pyclarcs-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 47.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for pyclarcs-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f1177bbc4ed27ebab143b9d96c208b2255e643d3d1d5ef5be687eafff1300833
MD5 2a29a3c98e9363b0587eb9b01356ef3b
BLAKE2b-256 9ca3e4baabb1c6e9c615ac8a0292d7e310311243ef5ab4823c280eefa02998fd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page