Affine RegistrationΒΆ

The affine transform allows for shearing and scaling in addition to the rotation and translation. This is usually a good choice of transform for initialization of non-rigid transforms like the B-Spline transform. The affine transform is selected using sitk.GetDefaultParameterMap("affine").

Consider the images in Figure 10.

_images/BrainProtonDensity.png _images/BrainProtonDensityTranslatedR1013x17yS12.png

Figure 10. The original image fixedImage.nii (left) and translated and rotated image movingImage.nii (right).

The image on the right has been sheared, scaled 1.2x, rotated 10 degrees and translated 13 pixels in the x-direction and 17 pixels in the y-direction. Using the AdvancedAffineTransform we may correct for this misalignment.

import SimpleITK as sitk

elastixImageFilter = sitk.ElastixImageFilter()
elastixImageFilter.SetFixedImage(sitk.ReadImage("fixedImage.nii")
elastixImageFilter.SetMovingImage(sitk.ReadImage("movingImage.nii")
elastixImageFilter.SetParameterMap(sitk.GetDefaultParameterMap("affine"))
elastixImageFilter.Execute()
sitk.WriteImage(elastixImageFilter.GetResultImage())

It is clear from the result mean image on right in Fig. 11 that registration was successful.

_images/PreAffine.jpeg _images/PostAffine.jpeg

Figure 11. Mean image before registration (left) and mean image after registration (right).

Notice that the only difference from the previous example is the requested parameter map. In fact, only the Transform parameter seperates the two parameter maps. The following parameter map is equivalent to the one used above:

import SimpleITK as sitk

parameterMap = sitk.GetDefaultParameterMap("rigid")
parameterMap["Transform"] = ["AffineTransform"]

You can inspect the default parameter maps in the elastix repository to convince yourself.

This demonstrates how easy it is to try out different registration components with SimpleElastix. In the next example we will introduce non-rigid registration and initialize the moving image with an affine transform.