Skip to main content

Bayesian inference for 3D-2D rigid registration written in JAX.

Project description

Bayalign

Python 3.10+

🛠️ work-in-progress 🛠️

Bayalign is a lightweight JAX-based library for rigid point cloud registration using efficient Bayesian inference via geodesic slice sampling on the sphere (GeoSSS) for inference. See the package geosss for details.

The package is tailored for any rigid registration problem and has mainly been motivated from a scientific application such as Cryo-EM where the goal is to estimate the rotation of a 3D structure that best aligns with noisy or partial 2D projections.

Features

  • Supports 3D-2D and 3D-3D rigid registration
  • GPU acceleration, Automatic differentiation via JAX
  • Fast inference via GeoSSS
  • Uses Gaussian Mixture Models (GMM) for scoring the rigid poses

Installation

pip install git+https://github.com/ShantanuKodgirwar/bayalign.git

Quickstart

A basic example of 3D-to-2D registration:

from bayalign.pointcloud import PointCloud, RotationProjection
from bayalign.score import GaussianMixtureModel
from bayalign.inference import ShrinkageSphericalSliceSampler
from bayalign.sphere_utils import sample_sphere

# Define 2D target and 3D source point clouds
target_2d = PointCloud(positions, weights)               # shape (N, 2)
source_3d = RotationProjection(positions, weights)       # shape (M, 3)

# Define a target probability model using GMM
target_pdf = GaussianMixtureModel(target_2d, source_3d, sigma=1.0, k=20)

# Sample from the posterior over 3D rotations (quaternions)
init_q = sample_sphere(random.key(645), d=3)             # initial quaternion (4,)
sampler = ShrinkageSphericalSliceSampler(target_pdf, init_q, seed=123)
samples = sampler.sample(n_samples=100, burnin=0.2)

# Find the best rotation
log_probs = np.array([target_pdf.log_prob(q) for q in samples])
best_rot = samples[np.argmax(log_probs)]
transformed_source = source.transform_positions(best_rot)

For 3D-3D registration, use PointCloud for both target and source. Check out the examples directory for detailed use cases using synthetic and cryo-EM data.

To run the examples, you need to install some optional dependencies. Follow one of the methods below to set up your environment.

Development

Clone the repository and navigate to the root.

git clone https://github.com/ShantanuKodgirwar/bayalign.git
cd bayalign

Option 1: Using uv (recommended!)

The package bayalign and all its locked dependencies are maintained by uv and can be installed within a virtual environment as:

uv sync --extra all

Export pip-compatible dependencies:

uv export --extra all --no-emit-project --no-hashes -o requirements.txt

Option 2: Using pip

python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
pip install -e . --no-deps

Issues

If you encounter any problems, have questions, please feel free to open an issue.

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

bayalign-0.1.0.tar.gz (21.7 kB view details)

Uploaded Source

Built Distribution

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

bayalign-0.1.0-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

Details for the file bayalign-0.1.0.tar.gz.

File metadata

  • Download URL: bayalign-0.1.0.tar.gz
  • Upload date:
  • Size: 21.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.2

File hashes

Hashes for bayalign-0.1.0.tar.gz
Algorithm Hash digest
SHA256 842333652344380406af9137b57f38c89540381b44de912c9fea97d643defa6b
MD5 90839d38ca1a88838d775dd0705572b0
BLAKE2b-256 0563c0b51d76aa3a9d61ba3c3e1e6a547ffca6827ed611e96e326063777a2532

See more details on using hashes here.

File details

Details for the file bayalign-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: bayalign-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 20.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.2

File hashes

Hashes for bayalign-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c8b5406eb0be8750dcce44e3d36a5d8504de97e413398eafd46767446cdb273d
MD5 f9d14265209004cd84fdda8030497ff6
BLAKE2b-256 87b6cb88de157c054fda0a4765630305c5c89fe119169a5b2e5dc6af53779f5c

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