FSL

# Registration & Unwarping Registration of EPI and Structural Images (with undistortion) |

## INTRODUCTION

This page aims to explain how to get a good registration between EPI and structural images using FLIRT, PRELUDE and FUGUE. It covers both the acquisitions and the analysis steps required and also includes details on how to deal with partial brain (partial field of view) acquisitions.

It is important to understand that EPI registration is difficult because of signal loss and geometric distortion in the images. In addition, partial brain registration is difficult not only for EPI but for any images, and so is particularly difficult in the case of EPI.

## ACQUISITION

Case 1: Whole brain imaging

In this kind of experiment the following should be collected:

- Structural image (T1-weighted, MP-RAGE, T2-weighted, etc)
- Functional series (EPI)
- One single fieldmap image - with same slices as the EPI images (easiest to have the same field of view and voxel sizes as the EPI)

Note that at FMRIB we normally acquire spin-echo fieldmaps, although a good gradient-echo sequence can produce good fieldmaps as well. However, EPI-based fieldmaps are quite poor and should not be used.

Case 2: Partial brain imaging

In this kind of experiment the following should be collected:

- Structural image (T1-weighted, MP-RAGE, T2-weighted, etc)
- Functional series (EPI - partial brain)
- One single whole brain EPI image (must include the same slices as the partial brain EPIs, in addition to extra slices that enlarge the coverage to the whole brain)
- One single whole brain fieldmap - with same slices as the whole brain EPI image (easiest to have the same field of view and voxel sizes as the EPI)
- Optional: one single partial brain fieldmap (same imaging slices and dimensions as the partial brain EPIs)

## Analysis Sequence

There are several analysis stages required to get the best registration results with linear registration plus undistortion. The key stages undistort the EPI and then register the undistorted EPI with the structural image. However, before this can be done the fieldmap and EPI must also be registered.

Case 1: Whole brain imaging

Initial processing of the fieldmap acquisition
1 - generate the magnitude (absolute) fieldmap image - which is undistorted (using FSLCOMPLEX).
2 - remove non-brain structures from the magnitude fieldmap image (using BET) and save the mask used
3 - run PRELUDE on the initial fieldmap acquisition
4 - save a (true) fieldmap using FUGUE

Register the fieldmap to the EPI (i.e. `example_func`)
5 - distort the magnitude fieldmap image to match the EPI (using FUGUE).
6 - register the distorted magnitude fieldmap image to the EPI (using FLIRT with 6 dof).
7 - resample the fieldmap to the EPI (using ApplyXFM or FLIRT)

Undistort the EPI
8 - use the registered fieldmap to undistort the EPI (using FUGUE)

Register the EPI and structural
9 - register the undistorted EPI to the structural image (using FLIRT with 6 or 7 dof)
NB: make sure the transformation matrix is saved

Apply the registration and undistortion to any stats images
10 - undistort each statistical image as was done for the EPI (using FUGUE)
11 - apply the transformation from above to the undistorted statistical images to get them in structural space (using FLIRT or ApplyXFM)

Case 2: Partial brain imaging

Most of the steps above still need to be done, where the EPI refers to the whole brain EPI. However, some modifications are necessary.

Additional steps required:

Register the partial brain EPI to the whole brain EPI
7a - register the distorted partial brain EPI to the distorted whole brain EPI using a translation-only registration (via a FLIRT schedule file)
7b - combine the registration with the whole brain EPI to fieldmap registration to get the partial brain EPI registered with the fieldmap (via ConcatXFM or convert_xfm)
7c - resample the fieldmap to generate an appropriate partial brain fieldmap (FLIRT)
7d - undistort the partial brain EPI using the fieldmap from 7c (FUGUE)

And in replacement of the above:

Apply registration and undistortion to any stats images
10 - combine the registration from the partial EPI to the whole EPI with that from the whole EPI to the structural (ConcatXFM or convert_xfm)
11 - apply the transformation to the partial EPI, producing a resulting image of it in structural space (and check this visually)
12 - undistort each statistical image using the partial brain fieldmap (generated in step 7c) with FUGUE
13 - apply the combined transformation to the undistorted statistical images to get them in structural space (using FLIRT or ApplyXFM)

Notes for using FEAT

It is suggested that the following procedure be used when modifying FEAT directories to take account of undistortion:
A - in your .feat/stats directory, make a new subdirectory called "distorted" and copy all the files into that subdirectory.
B - undistort all the files in the `.feat/stats` directory (do not touch the ones in `.feat/stats/distorted` as these are your originals).
C - in the `.feat/reg` directory, replace the `example_func2highres.mat` and `example_func2initial_highres.mat` (if it exists).
D - Also replace the `example_func` and `initial_highres` images with the undistorted EPIs.
E - Then regenerate all the appropriate matrices and images for the FEAT report page. This can be done using the script `updatefeatreg`

Note that the coordinates in the first level FEAT report are not corrected using this method. However, all images will be corrected, as will subsequent higher level analyses.

## Checking the Results

It is very important to check that the individual analysis stages are working well. Since undistortion is most important in cases where images are significantly distorted then it is easy for some of the registration stages to have problems and so careful monitoring is essential.

Here is a checklist of some things to examine (in fslview):

- undistorted EPI (fugue output) vs magnitude (absolute) fieldmap image
  these images should be well registered (although some signal loss will be present in the EPI)
- undistorted EPI vs distorted (original) EPI
  check that the undistorted EPI really does look less distorted and that there are not large amounts of artifactual non-brain structures
- undistorted EPI vs structural image
  these images should be well registered (although some signal loss and possible extra-brain structures will appear in the EPI)
- undistorted partial brain EPI vs undistorted whole brain EPI
  although these images are not registered it should be possible to find corresponding slices in separate FSLView windows and visually compare that the undistortion is equivalent

## Troubleshooting

Some common problems that occur are:

- Extraneous non-brain material generated

  Solution: try using a different mask in the PRELUDE stages (a default one is always used but it can be poor sometimes, and the BET mask used in the examples below might also be suboptimal).

- "Undistorted" image is worse than original

  Solution: try changing the unwarping direction in FUGUE as the default is sometimes wrong. Firstly, try `--unwarpdir=y-` which uses the same axis but applies the correction in the opposite sense. If this is still wrong, or the axis of the distortion is clearly different then try the `--unwarpdir=` option with either `x, x-, z, z-`.

## Examples

Case 1: Whole brain imaging

Let the acquired images be: `b0map, epi_series, t1struct`
The required steps are as follows:

Preliminary Steps

- `extractfidparams epi_series.fid > dwell_time.txt`
  to see the dwell time do `cat dwell_time.txt`
  from here on I will use the value of 0.000737 but you should use the value stored here instead
- `extractfidparams b0map.fid > asym_time.txt`
  to see the asym time do `cat dwell_time.txt`
  from here on I will use the value of 0.0025 but you should use the value stored here instead
- Run LoadVarian on all images
- `fslroi epi_series example_func 90 1`
  NB: the 90 here is only an example, it should be half the number of timepoints in the epi_series

Main Steps
1. `fslcomplex -realabs b0map b0map_abs`
2. `bet b0map_abs b0map_abs -m`
3. `prelude -c b0map -u phase_unw -m b0map_abs_mask`
4. `fugue -s 0.5 -p phase_unw --dwell=0.000737 --asym=0.0025 --savefmap=fmap`
5. `fugue --loadfmap=fmap --dwell=0.000737 --asym=0.0025 -i b0map_abs -w b0map_abs_distorted`
6. `flirt -in b0map_abs_distorted -ref example_func -dof 6 -omat b0map2epi.mat -out b0map2epi`
7. `flirt -in fmap -ref example_func -init b0map2epi.mat -applyxfm -out fmap2epi`
8. `fugue --loadfmap=fmap2epi --dwell=0.000737 --asym=0.0025 -i example_func -u example_func_undist`
9. `flirt -in example_func_undist -ref t1struct -dof 7 -omat epi2struct.mat -out epi2struct`
10. `fugue --loadfmap=fmap2epi --dwell=0.000737 --asym=0.0025 -i thresh_zstat1 -u thresh_zstat1_undist`
11. `flirt -in thresh_zstat1 -ref t1struct -init epi2struct.mat -applyxfm -out thresh_zstat12struct`

Case 2: Partial brain imaging

Let the acquired images be: `b0map, epi_series, t1struct, whole_brain_epi`
The required steps are as follows:

Preliminary Steps

- `extractfidparams epi_series.fid > dwell_time.txt`
- to see the dwell time do `cat dwell_time.txt`
- from here on I will use the value of 0.000737 but you should use the value stored here instead
- `extractfidparams b0map.fid > asym_time.txt`
- to see the asym time do `cat dwell_time.txt`
- from here on I will use the value of 0.0025 but you should use the value stored here instead
- Run LoadVarian on all images
- `fslroi epi_series example_func 90 1`
- NB: the 90 here is only an example, it should be half the number of timepoints in the epi_series

Main Steps
1. `fslcomplex -realabs b0map b0map_abs`
2. `bet b0map_abs b0map_abs -m`
3. `prelude -c b0map -u phase_unw -m b0map_abs_mask`
4. `fugue -s 0.5 -p phase_unw --dwell=0.000737 --asym=0.0025 --savefmap=fmap`
5. `fugue --loadfmap=fmap --dwell=0.000737 --asym=0.0025 -i b0map_abs -w b0map_abs_distorted`
6. `flirt -in b0map_abs_distorted -ref whole_brain_epi -dof 6 -omat b0map2epi.mat -out b0map2epi`
7. `flirt -in fmap -ref whole_brain_epi -init b0map2epi.mat -applyxfm -out fmap2epi`
7a. `flirt -in example_func -ref whole_brain_epi -schedule $FSLDIR/etc/flirtsch/sch3Dtrans_3dof -omat example_func2whole_brain_epi.mat -out example_func2whole_brain_epi`
7b. `convert_xfm -omat example_func2b0map.mat -concat b0map2epi.mat example_func2whole_brain_epi.mat`
7b. `convert_xfm -omat b0map2example_func.mat -inverse example_func2b0map.mat`
7c. `flirt -in fmap -ref example_func -init b0map2example_func.mat -applyxfm -out fmap2example_func`
7d. `fugue --loadfmap=fmap2example_func --dwell=0.000737 --asym=0.0025 -i example_func -u example_func_undist`
8. `fugue --loadfmap=fmap2epi --dwell=0.000737 --asym=0.0025 -i whole_brain_epi -u whole_brain_epi_undist`
9. `flirt -in whole_brain_epi_undist -ref t1struct -dof 7 -omat epi2struct.mat -out epi2struct`
10. `convert_xfm -omat example_func2struct.mat -concat epi2struct.mat example_func2whole_brain_epi.mat`
11. `flirt -in example_func -ref t1struct -init example_func2struct.mat -applyxfm -out example_func2struct`
12. `fugue --loadfmap=fmap2example_func --dwell=0.000737 --asym=0.0025 -i thresh_zstat1 -u thresh_zstat1_undist`
13. `flirt -in thresh_zstat1 -ref t1struct -init example_func2struct.mat -applyxfm -out thresh_zstat12struct`

#### Mark Jenkinson
Copyright © 2001-2004, University of Oxford