Linear Algebra. Points matching with SVD in 3D space

Andrey Nikishaev
Machine Learning World
3 min readJun 30, 2019

Want become an expert in Computer Vision & Object Detection?

Subscribe on New Practical Course

Problem

We need to find best rotation & translation params between two sets of points in 3D space. This type of transformation called Euclidean as it preserves sizes.

Our task to solve equation R*A + t = B

Solution

There are many ways of getting things done almost in any case, but currently we will use SVD for this. You ask why? — Because matrix is basically a transformation and with SVD can be decomposed on Rotation(U), Scaling(Σ), Rotation(V) (in special case when A is mxm matrix, but this gives us a clue. deeper explanation you can find in paper Least-Squares Rigid Motion Using SVD)

Rotation

To get rotation first we need to find out center of it. So we will find centroids of two datasets.

centroid_p = mean([{xi,yi,xi} in X])

First we will re-center our datasets and create covariance matrix H of two them, where Pa, Pb are points in datasets.

Now we use SVD to find out U and V matrices

And out rotation matrix are equal R = V*U.T

Problem with SVD
Because solving SVD implies some sort of randomness(there can be different number of correct solutions) it sometimes make rotation matrix to be sign reflected.
We can fix this by checking determinant of R matrix and if it negative. If so then multiply 3rd column of R by -1

Translation

This is very simple.
1) recenter with -centroid_A
2) Rotate and move to center of dataset B

Code

Example of code you can check here on my google colab
Also you can checkout example on affine transformation

Sources

Support

Become a Patron and support our community to make more interesting articles & tutorials

More cool things about Linear Algebra

--

--