Skip to content

cli femur model example

Hans Meine edited this page Jan 29, 2016 · 10 revisions

In the following we show how we can build a shape model from a number of given surface scans. The surfaces are assumed to be aligned (i.e. there is no global rotation/translation).

Download data

Download the example data and unzip the archive.

Build a Gaussian process model

The first step for model building is to establish correspondence between all the shapes. In Statismo this is achieved by fitting a Gaussian process model to each of the shapes. To build a Gaussian process model, use the following command

statismo-build-gp-model -r surfaces/VSD001_femur_r.vtk -k gaussian -s 50 -p 50 -n 200 gaussmodel.h5

This tells statismo to build a Gaussian processmodel using a gaussian kernel with standard deviation 50 (-p 50) as a covariance function, which is scaled by a factor of 50 (-s). The gaussian process is represented using the 200 basis functions of the Karhunen-Loeve representation (-n 200). As a reference shape, on which the model is defined, we use the shape VSD001_femur_r.vtk.

Sample example shapes from the model

In a next step we sample shapes from the model, in order to assess whether the model is a suitable prior for the registration.
This is done using the statismo-sample command. First we see how the mean shape looks like (-m option in the command). The shapes can be visualized using for example Paraview.

statismo-sample -i gaussmodel.h5 -m -o mean.vtk

The mean should in this case coincide with the reference. To assess the variation, it is useful to sample a few random instances. This is done by repeatedly calling

statismo-sample -i gaussmodel.h5 -o randomsample.vtk

We can also sample along a principal axis. For example, we visualize the shape change along the first principle axis using the following command

 statismo-sample -i gaussmodel.h5  -p 1:+3  -o pc1p3.vtk

which indicates that we are interested in the sample that differs in its first component 3 standarddeviation from the mean.

Do the registration

If we deem that the model is good enough, we are ready to do a model fitting in order to establish point-to-point correspondence. For this, we use the command

 statismo-fit-surface -i gaussmodel.h5 -t surfaces/VSD002_femur_r.vtk -w 0.1 -p -o fit.vtk -j fit-projected.vtk

We will get two outputs: A fitting result and a projection of this mesh to the target surface. The projection will always perfectly coincide with the target. However, if the fit does not explain the target well enough, we will have bad correspondences. Hence we should look at the fitting result and not the projection to assess the fitting quality. For the fitting result we see that there are still some differences. We have now two options: Either we improve the model and see if this leads to better result (we could, for example allow for less smooth deformations by changing the parameter of the gaussian kernel), or we assist the algorithm by adding some known correspondences as landmarks. Here we choose the second option.

statismo-fit-surface -v 2.0 -f landmarks/VSD001-lm.csv -m landmarks/VSD003-lm.csv -i gaussmodel.h5 -t surfaces/VSD003_femur_r.vtk -w 0.0001 -p -o fit-VSD003.vtk -j fit-VSD003-projected.vtk

This procedure build internally a posterior model, i.e. a shape model which is constrained to pass through the landmark points. We can also construct this model explicitly using

statismo-posterior -i gaussmodel.h5 -f VSD001-lm.csv -m VSD002-lm.csv -v 2.0 -o gpposterior.h5

This allows us to explore the posterior model by e.g. sampling from it using statismo-sample. This model can also be used as an input for the fitting procedure

 statismo-fit-surface -i gpposterior.h5 -t surfaces/VSD002_femur_r.vtk -w 0.1 -p -o fit.vtk -j fit-projected.vtk

Note that since this posterior model can only explain instances that pass through the landmark points, the fitting result will also match these landmark points.

Build the PCA Model

The surfaces that result from the registrations are now all in correspondence (i.e. have the same number of points as the reference, and denote the "same" anatomical point on the surface). We are now in the position to build a PCA model.

statismo-build-shape-model  -p GPA -l datalist.txt -o pcamodel.h5

The file datalist.txt is a text file that contains the filenames of all the examples used for model building (one filename per line). Using the option (-p GPA) indicates that we use generalized procrustes analysis to align the data.

Using the same commands as for the Gaussian process models, we can now visualize or fit the PCA model to a new dataset.

Enlarge the flexibility of the model

As we have only used very few datasets to build our model, the model will not be sufficiently expressive to explain all possible shape variations that occur in practice. Statismo provides the possibility to enlarge the variation, by combining the learned shape variations with deformations that are modelled by the user, by means of a Gaussian process. We can build this new model using again the command statismo-build-gp-model.

statismo-build-gp-model -m pcamodel.h5 -k gaussian -s 5 -p 200 -n 50 -o augmentedpcamodel.h5

In this case we specified that we would like to add smooth deformations, modelled by a Gaussian kernel with standard deviation 200 and average scale of 5mm, to our model. This corresponds to the assumption that the bias of the PCA model (i.e. the shape variations that could not be explained by the training data) can be modelled by small and very smoothly varying deformations. We choose to represent the final model using 50 basis functions (-n 50). This parameter should be chosen such that it is larger than the number of principal components of the original model.