ICP Point Cloud Alignment
Implement Iterative Closest Point (ICP) for 3D scan alignment, a 3D registration technique used to find the best alignment between two point clouds. ICP is crucial in 3D reconstruction as it enables the combination of multiple scans into a single, cohesive model.
The ICP process involves iteratively finding the closest points between the source and target point clouds, estimating the rigid transformation (, ) that best aligns the two clouds, and applying this transformation to the source cloud. This process is repeated until convergence, at which point the source and target clouds are optimally aligned.
To achieve this, the following steps are taken:
- Find closest points between source and target point clouds
- Estimate rigid transformation (, ) using the Procrustes method
- Apply transformation to source point cloud
- Repeat until convergence
Implement icp(source, target, max_iter), running at most max_iter iterations, and return a tuple (aligned, R, t): the aligned source cloud of shape , plus the rotation and length-3 translation estimated in the final iteration.
This technique is widely used in computer vision and robotics for tasks such as 3D mapping and object recognition.
Example
Two point clouds
Aligned source cloud
- Inputs:
sourceandtargetare arrays of points, andmax_itercaps the number of match → align rounds. Example:sourceis the triangle andtargetis the same triangle shifted by . - Matching: each source point's closest target point is its own shifted copy (distance , closer than any other target point).
- Centroids: the source centroid is and the matched centroid is . After subtracting them, both triangles are identical, so the best rotation is and .
- Output: applying gives the Aligned source cloud (exactly the target) after one round. It is returned with the and length-3 of the last round.
- Notice: every later round finds zero residual, so the last round's step is , , not the total shift.
Constraints
- Input point clouds: 3D numpy arrays of shape (n, 3) where n is the number of points in the cloud
- Valid ranges: Point cloud coordinates are floating-point numbers in the range [-100, 100]
- Output format: Return the aligned source point cloud as a 3D numpy array of shape (n, 3) with floating-point precision
- Special conditions: The input point clouds are not empty and contain at least 3 points, and the target point cloud is not identical to the source point cloud
- Convergence criteria: The iteration stops when the difference between the current and previous transformations is less than a threshold of 1e-6 or when a maximum of 100 iterations is reached