Troubleshooting FLIRT Co-registration
Author: Michael Dwyer
Last updated: 2011-04-05
Overview
Most of the time, co-registration will work perfectly when you do it with the standard Bluesky
interface, and everything will be taken care of behind the scenes. However, for a small percentage of
cases, the standard approach will fail. When this happens, you'll need to take some extra steps to get a
good co-registration before simply giving up on it.
Document conventions and glossary
Conventions
Commands you should type will be written in bold fixed-point font like this.
Commands will be introduced with a > symbol indicating the command prompt. Do not type
this.
When something in a command should be replaced with your input, it will be placed in angle
brackets like .
◦ So if you see something like this:
▪ > get_info -t 10 -color
◦ You would replace it with this:
▪ > get_info -t 10 -color blue
◦ Do not actually type the angle brackets
For pipeline commands, it is presumed that you know how to first request a pipeline key.
For FSL commands, it is assumed that you have your environment set up for FSL (e.g., by
sourcing /shared/software/etc/use_fsl_current).
Glossary
Floating image – the image you are realigning to line up with another image; the image which
will actually be moved. Also called input image.
Reference image – the image that serves as the co-registration target. It does not move itself,
and the newly co-registered image will be in its voxel space (and most likely in its physical
space). Also called target image.
Troubleshooting steps
The steps below can often help fix a bad co-registration. They're given in the order they should be tried,
from least involved to most involved. Hopefully one of the early fixes will take care of your problem.
While working through this, bear in mind that most of the steps can be combined – for example, you
can still use modified search angles while simultaneously changing the cost function or using weighting
maps.
Most of the steps involve running a co-registration pipeline from the command-line. Pipeline keys
for should always be requested so that the owner is the floating/input image, not the target/reference
image.
Deny the old one
Before doing anything else, be sure to deny the bad co-registration if it is in Bluesky. Do not leave
unapproved or inappropriately approved analyses in the system.
Modify the search angles
The searchrx, searchry, and searchrz options for FLIRT control how far it will look for the right answer.
This behavior has two very different consequences, depending on the situation:
If the correct co-registration requires a rotation of more than the search angles (default 20
degrees each way), then FLIRT will never find it, even if it's just the smallest bit over.
If the correct co-registration requires a very small rotation, large search angles can make FLIRT
less accurate since it is concentrated on a wider range and might get “stuck” in a wrong answer.
So, if you look at the raw images and see that the floating image is more than 20 degrees rotated from
the reference image in any plane, then you should try to expand out the angles until you are sure the
correct angle is included in the range. If you can tell which plane is most rotated, it might help to just
expand that angle.
On the other hand, if the two images appear very close (just a tiny bit off), then it might work better to
decrease the search angles considerably (to 10 or even 5 degrees).
As a basis for comparison, consider that the angle between 12 and 1 on a clock is 30 degrees. In terms
of distance, 1 degree corresponds to about a millimeter offset at the ends of the brain; so a 5 degree
rotation would move the frontmost point of the skull about half a centimeter (5mm).
Regardless of whether you need to expand or restrict the search angles, you can do it as follows:
> coregistration_pipeline -i -k --floating-image-id
--target-image-id --flirt-options "-v -dof 6 -searchrx -
-searchry - -searchrz - "
The relevant parts here are the searchr_ terms in the --flirt-options entry. Each angle is given as a pair,
from negative to positive. Usually you will use the same number each time. For example:
> coregistration_pipeline -i BBS -k 2d359305f77c7059bdcc69418dff731f --floating-
image-id MR12345 --target-image-id MR12346 --flirt-options "-v -dof 6 -searchrx -
10 10 -searchry -10 10 -searchrz -10 10"
Change the cost function
If the search angles trick doesn't work, you can also try changing the cost function. The default is
correlation ratio (corratio), and it usually works very well. However, if you're having trouble you can
try switching to mutual information (mutualinfo) or normalized mutual information (normmi), which
may give FLIRT enough of a “kick” to get things working again.
> coregistration_pipeline -i -k --floating-image-id
--target-image-id --flirt-options "-v -dof 6 -searchrx -
-searchry - -searchrz - -searchcost -cost "
The relevant parts here are the the searchcost and cost terms in the --flirt-options entry. They should be
either mutualinfo or normmi (try mutualinfo first). For example:
> coregistration_pipeline -i BBS -k 2d359305f77c7059bdcc69418dff731f --floating-
image-id MR12345 --target-image-id MR12346 --flirt-options "-v -dof 6 -searchrx -
10 10 -searchry -10 10 -searchrz -10 10 -searchcost mutualinfo -cost mutualinfo"
Use weights
In some cases, artifacts, major anatomical changes, or things that only show up on one of the two
images involved (like extensive lesions) can have a negative effect on FLIRT's co-registration abilities.
To fix this, you can use cost function weighting to tell FLIRT not to consider those particular areas
when trying to match up the images. Consider using it if you are having a lot of trouble with a co-
registration and see any of the following:
Severe localized artifact. Whole brain motion can't be corrected, but a local susceptibility
artifact can be.
A localized area of major anatomical change. Examples include surgery, extreme focal atrophy,
and enlargement of cysts/tumors.
Extensive lesion burden that is visible on one of the images but not the other. For example, this
can happen when registering T2/PD/FLAIR images to a T1 target.
To use weighting, you create a weighting image with 1's for all the voxels you want to keep and 0's for
those you want to exclude. The easiest way to do this is as follows:
Use regular ROI tools and techniques in JIM to create a mask of the area you want to exclude.
Binarize and invert the mask using the following fslmaths command:
◦ fslmaths -bin -mul -1 -add 1
Once you have the weighting file in Nifti format, you can use it as follows:
> coregistration_pipeline -i -k --floating-image-id
--target-image-id --flirt-options "-v -dof 6 -searchrx -
-searchry - -searchrz - -inweight -refweight "
The relevant parts here are the inweight and refweight terms in the --flirt-options entry. You can include
either or both, depending on what you want to mask out. For example:
> coregistration_pipeline -i BBS -k 2d359305f77c7059bdcc69418dff731f --floating-
image-id MR12345 --target-image-id MR12346 --flirt-options "-v -dof 6 -searchrx -
10 10 -searchry -10 10 -searchrz -10 10 -inweight
/shared/scratch/input_weights.nii"
Notice here that the full path to the input_weights.nii was specified. This is necessary because the
pipelines run in a temporary directory, meaning that relative paths won’t be valid.
Use deskulled images
If none of the tricks above help to improve the co-registration, you may need to do some manual work
to get the input image properly aligned. The most straightforward way to do this is to use
Nudge. Nudge is an FSL tool
Last resort: use Nudge
If none of the tricks above help to improve the co-registration, you may need to do some manual work
to get the input image properly aligned. The most straightforward way to do this is to use Nudge.
Nudge is an FSL tool that allows you to manually create a co-registration matrix in order to align two
images. Start nudge by type Nudge, which will bring up a screen like the following:
Then, select the input (floating) image and the reference image. Leave initial transformation blank, and
start playing with the rotation, translation and scaling options. Whenever you change options, you can
click the “View” button at the bottom to check the co-registration – it'll come up overlaid in FSLview.
In the end, you'll just have to play with the parameters until you get it to look good. Here are some
basic guidelines to help, though:
If you are co-registering within the same subject (i.e. input and reference images are from the
same person), leave all the scalings at 1
Try to take care of the rotations first – even if the input image is offset, get it oriented the same
as the reference. For an axial image, changing X rotation is like nodding the head, Y is like
flopping the head back and forth between shoulders, and Z is like shaking the head “no”.
Once you get the orientations close enough, you can speed up figuring out the translations by
finding the coordinates of same structure (like the anterior or posterior commissure) in both
images and measuring how far apart they are. For example, if the AC for the reference image is
at 0.7,11.85,-19.09 and the AC for the input image is 0.91,12,-17.2, subtracting each coordinate
of the input from the reference gives (0.7 – 0.91),(11.85 – 12),(-19.09 - -17.2) = -0.21,-0.15,-
1.89. Use those last three coordinates as the translation X, Y, and Z fields. Remember when
reading co-ordinates from FSLview that the second column is the mm co-ordinates and the first
is voxel. You want mm (the second column).
Once you are satisfied with your manual coregistration, exit Nudge. It will print a line telling you
where the final coregistration is. For example:
final transform is in /tmp/nudge_JBBCgZ.xfm
At this point, you have two options. You can either use this as an initialization matrix to a more precise
co-registration, or you can use it itself as the final co-registration. It's best to try using it as an
initialization matrix first, since FLIRT can theoretically do a much more precise job than you can by
eye (FLIRT has sub-millimeter accuracy). When you specify an initialization matrix, FLIRT will start
with those parameters, making it much more likely to find the right answer in the end. To do that, use
the following command:
> coregistration_pipeline -i -k --floating-image-id
--target-image-id --flirt-options "-v -dof 6 -searchrx -5 5 -searchry
-5 5 -searchrz -5 5 -init "
The relevant part here is the init term in the --flirt-options entry. You specify the full path to the Nudge
output file as the option. Also note that we've dramatically reduced the search angles, since we're sure
that the initialization matrix is very close to the right answer. For example:
> coregistration_pipeline -i BBS -k 2d359305f77c7059bdcc69418dff731f --floating-
image-id MR12345 --target-image-id MR12346 --flirt-options "-v -dof 6 -searchrx -5
5 -searchry -5 5 -searchrz -5 5 -init /tmp/nudge_JBBCgZ.xfm"
If this last attempt still doesn't work, you can completely skip FLIRT and just use your output from
Nudge. In this case, though, you should go back and tweak your Nudge output even more to make it as
absolutely precise as you possibly can. Once you have it as good as you can make it, use the following
command:
> coregistration_pipeline -i -k --floating-image-id --target-image-id --flirt-options "-v -dof 6 -searchrx -5 5 -
searchry -5 5 -searchrz -5 5 -applyxfm -init "
The relevant part here is the applyxfm term in the --flirt-options entry. This tells FLIRT not to do any
optimization, but just to use your matrix as is. For example:
> coregistration_pipeline -i BBS -k 2d359305f77c7059bdcc69418dff731f --floating-
image-id MR12345 --target-image-id MR12346 --flirt-options "-v -dof 6 -searchrx -5
5 -searchry -5 5 -searchrz -5 5 -applyxfm -init /tmp/nudge_JBBCgZ.xfm"
Additional notes
Requesting keys, running the pipeline and checking the output in Bluesky can be relatively
tedious. If you are comfortable with it, you can run the flirt command directly on the file
system until you get a good result. Once that’s been done, you can then use the coregistraion
pipeline with the final –flirt-options option (specifying whatever ultimately worked on the file
system).