Transforming Images#
In the previous section, we discussed the principles of affine and rigid-body transformations and saw how converting between voxel-space and world-space can be conceptualised as an affine transformation of the image coordinates. However, the utility of these forms of transforms is not just moving between different spaces, but also in providing a framework for transforming the location of the brain within an image. Generally speaking, because we have a choice of two coordinate spaces, we also have a choice of performing a transformation in world-space or in voxel-space. As we will see, world-space transformations alter the rules for mapping voxels to millimetres, without changing the voxel values. In comparison, voxel-space transformations directly alter the voxels in the image. In this section, we will explore the principles and utility of each type of transformation.
Transforming an Image in World-space#
One of the main motivating factors behind a world-space representation of an image is so that we can create more intuitive transformations for moving the brain. Generally speaking, transformations in world-space make more sense because we can use real-world units. For instance, we can move the brain back by 3mm and up by 5mm. To do this, we have to combine the \(\mathbf{M}\) matrix from the header with another affine transform matrix \(\mathbf{T}\). If we use the following as our example \(\mathbf{M}\) matrix
we can see the original millimetre location of the voxel coordinates \(\mathbf{a} = [20, 20, 20, 1]'\) is given by
Focusing on the \(y\)-axis, the voxel index of 20 is mapped to -55mm from the origin in world-space. If we wanted to move the image 9mm backwards, we could combine \(\mathbf{M}\) with a transformation matrix \(\mathbf{T}\) that encodes a negative 9mm shift along the \(y\)-axis
Pre-multiplying \(\mathbf{M}\) by \(\mathbf{T}\) creates a new matrix that changes how the voxel coordinates are mapped into world-space. So, if we do the following
we can see that the voxel coordinate of \(y = 20\) is now mapped to -64mm from the origin, shifting it 9mm further backwards. If we want to make this shift permanent, we can create a new matrix \(\mathbf{M}^{\ast} = \mathbf{TM}\) and then replace the original \(\mathbf{M}\) matrix in the header with \(\mathbf{M}^{\ast}\). The image is then forever mapped 9mm further backwards in world-space.
Attention
The most important thing to remember about world-space transformations is that they do not alter the voxel data. All we have done is change how the voxels coordinates are mapped to millimetre coordinates. In effect, we have changed the rules, but have not done anything to the actual image. Because of this, the image will look no different in voxel-space, but will be moved back 9mm in world-space. This change is somewhat invisible because it will not look like the image has been altered. You would only notice a difference if you saw the image displayed in world-space and had some reference point to compare it with. Typically this reference point is another image, as the point of world-space transforms is often to bring multiple images into alignment without changing the voxel data. This will make more sense next week when we discuss image registration. For now, just try to grasp the idea of world-space transformations, knowing that this will be further contextualised later.
Transforming an Image in Voxel-space#
As highlighted above, transforming and replacing the header matrix will not alter the voxel data. If we wanted this transformation to change the actual image data, we would need to turn this into a voxel-space transformation. The motivation for this is usually in the context of image registration and so will become clearer next week. For the moment, you can simply think of a voxel-space transforming as applying the world-space transformation to the actual data.
Converting a world-space transformation into a voxel-space transformation can be achieved by defining the following mapping matrix
\(\mathbf{Q}\) can then be used to change any voxel coordinates in the original image into new voxel coordinates in the transformed image. For instance, using the \(\mathbf{a}\) defined earlier
So, the original voxel coordinate of \(y = 20\) has been transformed into a new voxel coordinate of \(y = 23\). This works by taking the original voxel coordinates, transforming them into millimetres, applying the transformation in world-space and then transforming the shifted world-space coordinates back into voxels.
In order to use \(\mathbf{Q}\) to actually change the voxel data, we would first create a blank image with the same dimensions as the original image. We would then work through each voxel in the new image and transform the corresponding voxel coordinates using \(\mathbf{Q}\). These transformed coordinates tell us the coordinates of the voxel we should copy from the original image. In the example above, when we get to voxel \([20, 20, 20]\) in the new image we would use \(\mathbf{Q}\) to transform these coordinates into \([20, 23, 20]\). This would tell us that we need to copy the value of voxel \([20, 23, 20]\) from the old image into voxel \([20, 20, 20]\) in the new image. This is conceptualised as a pulling operation, where the original data are pulled into their new locations.
This process is illustrated in the video below for a rotation operation. For each position in the new image on the left, we take the coordinates and transform them using \(\mathbf{Q}\). This gives the coordinates illustrated in the image on the right. The voxel value associated with this coordinate is copied from the old image into the new image. If the transformation results in coordinates that are out-of-bounds, a value of -1 is inserted into the new image instead.
Transforming Images in SPM#
To see how all this theory about affine transformations is put into practice, the video below will demonstrate the process of transforming an image in world-space using the SPM Display module, as well as demonstrating how to enact a transformation in voxel-space using the Coregister:Reslice module. Click here to download the example data so you can follow along.