In this tutorial we show how rigid alignment of shapes can be performed in Scalismo.
The following resources from our online course may provide some helpful context for this tutorial:
As in the previous tutorials, we start by importing some commonly used objects and initializing the system.
Quick view on Transformations
Let's start by loading and showing Paola's mesh again:
Scalismo allows us to perform geometric transformations on meshes.
Transformations are functions that map a given point, into a new transformed point.
We find the transformations in the package
Let's import the classes in this package
The most general way to define a transformation is by specifying the transformation function explicitly. The following example illustrates this by defining a transformation, which flips the point along the x axis.
When given a point as an argument, the defined transform will then simply return a new point:
An important class of transformations are the rigid transformation, i.e. a rotation followed by a translation. Due to their importance, these transformations are readily defined in scalismo.
A translation can be defined by specifying the translation vector, which is added to every point:
For defining a rotation, we define the 3 Euler angles , as well as the center of rotation.
This transformation rotates every point with approximately 180 degrees around the Y axis (centered at the origin of the space).
In Scalismo, such transformations can be applied not only to single points, but most collections of points such as triangle meshes, can be
transformed by invoking the method
transform on the respective object.
Simple transformations can be composed to more complicated ones using the
compose method. For example, we can define a rigid
tranformation as a composition of translation and rotation:
In Scalismo, rigid transformations are also already predefined. We could have written instead:
Exercise: Apply the rotation transform to the original mesh of Paola and show the result
Note: since the rotation is around the origin, you might have to zoom out (hold right click and drag down) to see the result.
A task that we need to perform in any shape modelling pipeline, is the rigid alignment of objects; I.e. normalizing the pose of an object with respect to some reference.
To illustrate this procedure, we transform the mesh of Paola rigidly using the rigid transformation defined above.
The task is now to retrieve the transformation, which best aligns the transformed mesh with the original mesh, from the meshes alone.
Rigid alignment is easiest if we already know some corresponding points in both shapes. Assume for the moment, that we have identified a few corresponding points and marked them using landmarks. We can then apply Procrustes Analysis. Usually, these landmarks would need to be clicked manually in a GUI framework. To simplify this tutorial, we exploit that the two meshes are the same and hence have the same point ids. We can thus define landmarks programmatically:
Given this lists of landmarks, we can use the method
to retrieve the best rigid transformation from the original set of landmarks:
The resulting transformation is the best possible rigid transformation (with rotation center
Best here means, that it minimizes the mean squared error over the landmark points.
Let's now apply it to the original set of landmarks, to see how well they are transformed :
And finally, we apply the transformation to the entire mesh: