Iterative Closest Point (ICP) Algorithm

Point Cloud Registration

Point cloud registration is the process of aligning two or more 3D point clouds of the same scene that have been captured from different viewpoints. Given a source point cloud, which we can call Ps, and a target point cloud, Ps, the goal is to find the optimal rigid body transformation that best aligns Ps with Ps. This transformation consists of a rotation matrix, R, and a translation vector, t.

The ICP Algorithm

We don't know which point in the source cloud corresponds to which point in the target cloud. ICP algorithm provides an elegant solution to this by a simple heuristic: it assumes that, for a given point in the source cloud, its nearest neighbor in the target cloud is its correct correspondence. While this assumption is not always true, especially at the beginning, it becomes increasingly accurate as the clouds get closer to alignment.

The algorithm is an iterative process that can be broken down into four steps:

  1. Initial Guess: The process begins with an initial estimate for the transformation, {R,t}. This initial guess can come from other sensors, like an Inertial Measurement Unit (IMU), or from the result of the previous alignment between a different pair of scans. A good initial guess is very crucial for convergence.
  2. Data Association: For each point in the source cloud, its nearest point in the target cloud is found. This establishes a set of tentative correspondences.
  3. Optimize Transformation: With these correspondences established, the algorithm then computes the optimal transformation {R,t} that minimizes a cost function, which typically is the sum of squared distances between these associated pairs.
  4. Iterate: The newly computed transformation is applied to the source point cloud. Steps 2 and 3 are then repeated with this updated point cloud. This loop continues until the algorithm converges, which is usually checked by checking if the change in the error between iterations falls below decided threshold.

The Optimization Step: A Closed-Form Solution

For a given set of point correspondences, step 3 of the ICP algorithm has a closed-form analytical solution. This method, often called the Kabsch algorithm, finds the optimal rotation and translation by minimizing the following least-squares cost function:

minR,tj=1nRpj+tqj2

Here, pj represents the points in the source cloud and qj represents their corresponding points in the target cloud. The solution is in two parts:

  1. Solving for Translation: First, the optimal translation is found by recognizing that it must align the centroids (or geometric means) of the two point sets.

Derivation for optimal translation, t

We start with the cost function, L(R,t):

L(R,t)=j=1nRpj+tqj2=j=1n(Rpj+tqj)T(Rpj+tqj)

Find minimum wrt t, we take the partial derivative of L with respect to t and set it to zero:

Lt=j=1n2(Rpj+tqj)=0

We can then solve for t:

j=1nRpj+j=1ntj=1nqj=0R(j=1npj)+ntj=1nqj=0nt=j=1nqjR(j=1npj)

Dividing by n gives the optimal translation in terms of the centroids, μp and μq:

t=1nj=1nqjR(1nj=1npj)=μqRμp

The optimal translation, t, is given by:

t=μqRμp

where μp and μq are the centroids of the source and target point clouds, respectively.

This is also pretty intuitive as uq being points from target point cloud, when we would have a perfect ICP we would ideally rotate the perfect amount for source point cloud making the difference only the translation, also when rotation is identity , the translation would simply be the difference between the centroids of the two point clouds.

  1. Solving for Rotation: By substituting this expression for t back into the original cost function, the problem simplifies to finding the optimal rotation for the centered point clouds.( Think how PCA works here , PC1 is calculated by first centering the data, then finding the direction of maximum variance, just a random thought can be ignored for reading the proof)

Derivation for optimal rotation, R

Substitute t=μqRμp into the cost function:

L(R)=j=1nRpj+(μqRμp)qj2=j=1nR(pjμp)(qjμq)2

Let pj=pjμp and qj=qjμq be the centered points. The problem is now to find the rotation that minimizes the sum of squared distances between these centered points:

minRj=1nRpjqj2

Expanding the squared norm:

Rpj22(Rpj)Tqj+qj2

Since rotation preserves length, Rpj2=pj2. The expression becomes:

pj22(Rpj)Tqj+qj2

The terms pj2 and qj2 are constant with respect to R. Therefore, minimizing the entire expression is equivalent to maximizing the term (Rpj)Tqj. This sum of dot products can be written using the trace operator:

maxRqjTRpj=maxRTr(QTRP)

where P and Q are 3×n matrices whose columns are the centered points. Using the cyclic property of the trace, Tr(ABC)=Tr(CAB), we can rewrite this as:

maxRTr(RPQT)

The term PQT is the transpose of the covariance matrix W we defined earlier. So the problem is to find the rotation R that maximizes Tr(RWT). It is a standard result from linear algebra (the Orthogonal Procrustes problem) that this trace is maximized when R=VUT, where U and V come from the SVD of W=USVT.

This is solved using Singular Value Decomposition (SVD). We first construct a 3×3 covariance matrix, W:

W=j=1n(pjμp)(qjμq)T

Next, we compute the SVD of this matrix:

W=USVT

The optimal rotation matrix, R, is then given by:

R=VUT

It is important to ensure that the resulting matrix is a proper rotation and not a reflection, which can happen in noisy or degenerate cases. This is checked by ensuring its determinant is +1. A correction can be applied if necessary:

Rcorrected=V(10001000det(VUT))UT

Wrapping Up

At this point, we’ve got everything we need ladies and gentleman.
The ICP loop boils down to finding correspondences, then solving for the rigid transform using the closed-form Kabsch solution:

R=VUT,t=μqRμp

where U,S,V come from the SVD of the covariance matrix W=(pjμp)(qjμq)T.

Applications

fir kabhi 🙏🏻🙏🏻🙏🏻🙏🏻

ICP-SLAM

ICP-SLAM

**