einit: Fast and Robust Ellipsoid ICP Initialization

PyPI version License: MIT

einit is a Python library that provides fast and robust initialization for Iterative Closest Point (ICP) algorithms using ellipsoid analysis. It computes optimal initial transformations between 3D point clouds by analyzing their ellipsoids of inertia.

Features

  • Fast Initialization: Compute initial transformations in milliseconds

  • Robust Algorithm: Handles various point cloud shapes (spheres, ellipsoids, general shapes)

  • OpenCV Integration: Returns standard 4×4 homogeneous transformation matrices

  • Noise Tolerance: Maintains performance even with significant noise

  • Partial Overlap: Works with incomplete point cloud correspondences

Quick Start

import numpy as np
from einit import register_ellipsoid

# Create source and destination point clouds
src_points = np.random.randn(100, 3)
dst_points = src_points @ R + t  # Apply some transformation

# Compute initial transformation
T_init = register_ellipsoid(src_points, dst_points)

# T_init is a 4×4 homogeneous transformation matrix
# Compatible with OpenCV and other computer vision libraries

Installation

Install directly from GitHub:

pip install git+https://github.com/sashakolpakov/einit.git

For development or testing:

pip install "git+https://github.com/sashakolpakov/einit.git[test]"  # Includes matplotlib, pytest
pip install "git+https://github.com/sashakolpakov/einit.git[all]"   # Everything including docs

Or clone and install locally:

git clone https://github.com/sashakolpakov/einit.git
cd einit
pip install -e .[test]  # Editable install with test dependencies

Requirements: - Python ≥ 3.6 - NumPy ≥ 1.15 - SciPy ≥ 1.0

Contents

Algorithm Overview

The ellipsoid initialization algorithm works by:

  1. Centering: Both point clouds are centered at their respective centroids

  2. Ellipsoids of Inertia: Computes ellipsoid matrices and their eigendecompositions

  3. Axis Alignment: Searches through all 8 possible axis orientations (±1 reflections)

  4. Optimization: Selects the transformation that minimizes alignment error

  5. Output: Returns a 4×4 homogeneous transformation matrix

Mathematical Foundation

Given source points \(P = \{p_1, p_2, \ldots, p_n\}\) and destination points \(Q = \{q_1, q_2, \ldots, q_m\}\), the algorithm:

  1. Centers the point clouds:

    \[\bar{p} = \frac{1}{n}\sum_{i=1}^n p_i, \quad \bar{q} = \frac{1}{m}\sum_{j=1}^m q_j\]
    \[P_c = P - \bar{p}, \quad Q_c = Q - \bar{q}\]
  2. Computes covariance matrices:

    \[E_P = P_c^T P_c, \quad E_Q = Q_c^T Q_c\]
  3. Performs eigendecomposition:

    \[E_P = U_P \Lambda_P U_P^T, \quad E_Q = U_Q \Lambda_Q U_Q^T\]
  4. Finds optimal rotation through reflection search:

    \[R^* = \arg\min_{D \in \{\pm 1\}^{3 \times 3}} \|Q_c - R P_c\|_F\]

where \(R = U_Q D U_P^T\) and \(D\) is a diagonal matrix with ±1 entries.

Performance Characteristics

  • Time Complexity: O(n) where n is the number of points

  • Space Complexity: O(1) additional memory

  • Typical Runtime: < 1ms for 1000 points

  • Convergence: Non-iterative, deterministic result

Benchmark Results

Real-world performance with 2% noise and 80% overlap:

  • Sphere (500 points): RMSE 0.017 ± 0.014

  • Cube (1728 points): RMSE 0.002 ± 0.001

  • Stanford Bunny (1000 points): RMSE 0.004 ± 0.001

The algorithm often outperforms traditional ICP refinement, providing excellent results without iteration.

Use Cases

Computer Vision - Point cloud registration - 3D object alignment - Structure from motion - SLAM applications

Robotics - Sensor fusion - Object pose estimation - Navigation and mapping

Scientific Computing - Molecular alignment - Geometric analysis - Shape matching

Indices and Tables