Skip to content

Tips for improving registration results

Philip Cook edited this page Dec 17, 2024 · 9 revisions

FAQs about registrations that run without error, but produce poor results

General advice

  • Formulate a registration problem that ANTs can solve (at least to a good approximation). More theory here but basically there needs to be a sensible mapping between points in the moving and the fixed image. This requirement is violated when the same anatomy doesn't exist in both images, for example if you register a brain-extracted image to another image including the whole head.

  • Use an appropriate similarity metric. This is also part of defining a solvable problem. Mattes Mutual Information is the most general and works within or across modalities. It's not very good with binary images (use mean squares). Cross correlation (CC) can work better (especially for deformable registration) but it assumes a correlation between image intensities when the images are aligned. Thus it is often not suitable to align images from different modalities, though it works quite well if there's a good correlation (even if negative). Several metrics are available; but Mattes and CC will cover many common use cases.

  • Check the images have the same basic orientation. The exact position and orientation will vary (eg, due to head position) but they should not be upside down or back to front, and both the fixed and moving images should agree on left-right orientation. You can check this with ITK-SNAP, which uses the same ITK I/O as ANTs. Load the fixed image first, then drop the moving image as an overlay. On the command line, itksnap -g fixed.nii.gz -o moving.nii.gz. Move the cursor about and see where it is in relation to the anatomy of both images.

  • Provide a good initialization for affine registration with -r, if that is insufficient use antsAI. If the images are already aligned in physical space (test by loading both into ITK-SNAP and look at the cursor positions), use -r Identity.

  • Ensure you are not downsampling and / or smoothing the images too much, especially if the FOV or resolution of the fixed and moving image differ (eg, BOLD slab registered to whole-brain T1w). You can preview the effects of smoothing and downsampling by first running SmoothImage and then ResampleImageBySpacing. Note that images can look uninformative to a human eye and still provide useful registration by the algorithm - but at the large shrink factors, good initialization and consistent resolution / FOV between the two images becomes more important. If you are having trouble, try reducing the largest shrink factor.

  • Provide a good initialization for deformable registration by running rigid and affine stages first.

  • Pad the fixed image with empty space, if necessary. If the fixed image foreground extends all the way to the boundary of the image volume, the image similarity at the edge becomes unstable because points outside the image volume are ignored, and there is a hard constraint that the deformation field is zero at the edge of the image domain. Adding extra space allows the edges of the images to be aligned better. You can also pad the moving images if necessary, but in many cases it's sufficient to have at least 10 voxels of background on all sides of the fixed image.

  • A registration mask can help with some problems such as structured background noise or anatomy of no interest, or inconsistent anatomical fields of view. Masks can also reduce registration quality as only the voxels inside the mask are considered by the registration. If possible, there should be some background voxels in the mask so that edges can be properly aligned. You may also apply masks at each stage of registration, using a wider mask (or none at all) for the rigid or affine stages, and a more restrictive mask for deformable stages. If you have brain or other foreground masks for both fixed and moving images, aligning the COM of the masks is often helpful. You can do this with antsAI and pass the result to antsRegistration with -r.

Debugging registration failures

The first priority is to isolate the problem. Many failures result from bad initialization or problems with the affine registration.

If you've already run a deformable registration, try applying only the affine part of the transform with antsApplyTransforms, this will tell you if there is a problem somewhere during the affine stage. If the affine transform looks good, you can initialize the registration with that transform and experiment with the deformable part, by passing -r myAffine0GenericAffine.mat to antsRegistration.

Writing intermediate output

Use the --write-interval-volumes option to antsRegistration. This will write the deformed moving image as StageN_levelM_IterO.nii.gz for stage N, level M, iteration O. Stages here mean different transforms, eg Rigid, Affine, SyN. Levels are different reoslutions, eg -f 4x2x1 has three levels.

With --write-interval-volumes X, where X is a positive integer, the registration will write the current deformed image at the beginning of each level, then at regular intervals, then sometimes again at the end of the stage - the end one is only written if we reach the maximum number of iterations before convergence.

With something like --write-interval-volumes 50000, you can get just volumes at the beginning of each level. These can be combined with

ImageMath 4 reg_timeseries.nii.gz TimeSeriesAssemble 1 0 Stage* 

then the progress of the registration can be viewed in ITK-SNAP with itksnap -g reg_timeseries.nii.gz -o fixed.nii.gz.

If the first volume is poorly aligned, it means the initialization (-r) failed. Otherwise, keep scrolling through the levels to see how and where the solution becomes worse.

Clone this wiki locally