# Affine Registration¶

The affine transform allows for shearing and scaling in addition to the rotation and translation we saw in the previous section. 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.

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

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


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

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.