Examples
Under the sample/ subdirectory, you can find an example script to demonstrate how to use metch toolbox to register a point cloud to a triangular surface mesh. There are extensive comments in the scripts and you should be able to understand the workflow by reading the full script.
Example 1
The first example, demo_registration_ex1, is a demonstration of calling separate metch subroutines to perform a registration task. The surface mesh was extracted and resampled from a head MRI scan using iso2mesh toolbox. The point cloud was obtained with a polhemus tracking system from a MEG scan at Martinos Center. The point cloud contains a few standard landmarks of the head, also known as the 10-20 points for EEG/MEG experiments, and a contour scan of the head surface. The task is to register this point cloud based on the surface mesh of the head, and move the points right onto the surface at the registered position to set up the geometries for the subsequent modeling.
The first step of the registration is to create a rough initial mapping. The point cloud and the head MRI surface can be defined in different coordinate systems, as well as units and orientations. This step is to create a good initial mapping by selecting a number of point pairs (the landmarks, or 10-20 points) from both the point cloud and the surface. The specific landmarks we used here include the nasion, CZ, T3 (left ear) and T4 (right ear) positions. By solving a linear equation in form of
A0*p_cloud+b0=p_mesh
we can get the mapping matrix A0 and vector b0. This transformation gives the users a rough mapping of the points to the surface.
Figure 1. The rough initial mapping using 4 landmark point pairs
The second step of the registration is to create a better mapping transformation by
fitting the surface by the point cloud using an optimization procedure. In this optimization, the sum of the distances from the points to the surface is minimized by tuning the parameters in A matrix and b vector. A Gauss-Newton method is used to solve this optimization problem efficiently. In this example, we set to run 10 iterations, but you can find after 5 iterations, the residual (sum of the distances) dose not change much.
Figure 2. The improved registration (green plus) using fit-point-to-surface optimization
After the optimization, the transformation matrix A and b will provide an "optimal" linear mapping in the sense of least-square. However, this only means the points are getting as close as possible under a linear transform, they do not have to on the surface (actually, in most cases in reality, they are not). Unfortunately, for many modeling problems, one expect to treat the point cloud as either source or detectors, and they are required to be located inside the mesh or right on the surface. Therefore, this toolbox also provide a tool to project the registered point cloud onto the surface mesh (so that they locate exactly on the surface). This is done by calculating the closest surface patches to each point and project the point along the averaged norm of the patch. This is the last step of the registration.
Figure 3. The final registration (cyan stars) after projecting the points to the surface
Example 2
Example 2 is exactly the same as the first example, except that it runs in a graphical interface mode and requires interactive operations from the user. All the functionalities described above can be done with this GUI tool by simply clicking buttons or the graph. A operation instruction for the GUI tools can be found
here.
Figure 4. GUI tool for registering the point to a surface mesh