Realignment HOWTO

How-Tos - Realignment

How do I...

Do realignment in SPM

Realignment works in two stages. First, the first files from each session are realigned to the the first file of the first session. Second, within each session, the second, third, etc... (2..n) images are realigned to the first image of the session. Thus, after realignment, all files are effectively realigned to the first file of the first session.

The process produces text files with the estimated realignment (or motion) parameters for each session. These are the rp_V001.txt (or realignment_params_V001.txt) stored in each session's directory. They contain 6 columns and one row for each V-file.

The columns are the estimated translations in mm ("right", "forward", "up") and the estimated rotations in rad ("pitch", "roll", "yaw") that are needed to shift each V-file.

These text files can be used later at the statistics stages to enter the estimated motion parameters as user-specified regressors in the design matrix. If you choose 'all images' in 'Create What?', realignment will create r*.img files. The process usually takes several hours, depending on the total number of V-files and the computer you're using.

Number of subjects: You'd most likely enter 1 here.

Num sessions for subject 1: Enter the number of sessions for the entire experiment.

Select SCAN1/V*.img , then click DONE.

scans for subj 1, sess2: Select SCAN2/V*.img, then click DONE.

Repeat the same until all sessions (and subjects) are done.

Select the default, coregister & reslice.

  • Selecting coregister only will realign by creating .mat files containing realignment transformations to be applied to the corresponding V-files (i.e no new *V.img file will be produced -- the image files will not be resliced).
  • Selecting reslice only will produce new rV*.img files. The V*.img files you import will be transformed accoring to their corresponding V*.mat files (given that they exist) and the resulting images will be written out as rV*.img files with the usual corresponding rV*.hdr files. No rV*.mat files will be created.
  • Selecting coregister & reslice will both realign the selected files and produce new *.mat files. The files produced will depend on what is entered in response to the "Create what?" prompt below.

Select the default, Sinc Interpolation.

Select mean image only.

  • All images (1..n) will produce as many rV*.img files as V*.img files are selected. If normalization will not be performed, the images should probably be resliced as this stage.
  • Images 2..n will produce a new rV*.img for each V*.img file loaded, except the first V*.img from the first session. Since every file in the sequence is being aligned to this first file, strictly speaking, it does not need to be transformed or resliced. For practical reasons, however, it is better if all files have the same prefix (which won't be the case if you choose this option).
  • All images + mean image will produce as many rV*.img files as V*.img files are selected, and in addition, a new mean_V001.img file will be produced in the first session's directory. The mean_V001.img file is the mean image of all files selected for realignment and it can be used with subsequent coregistration and normalization steps. Although the mean_V001.img is stored in the directory of the first session, it is actually the mean of all of the sessions together. The mean image is created after realignment and has the realignment transformations already applied to it.
  • Mean image only will produce only one new mean_V001.img file, without reslicing the selected V*.img files. If normalization will be performed next, there is no need to reslice the aV*.img files at this stage. The transformation parameters saved in the aV*.mat file to each image will be applied to the images during the normalization stages. This way, the images will be resliced only once. In general, unnecessary reslicing should be avoided, because the images lose some spatial resolution every time it's performed.

Adjust sampling errors? No. (See RealignmentFaq for why.)

Realignment will produce the following chart of the corrections made and save it to the file:

Include my motion parameters in my design matrix

SPM: You'll include your motion parameters as user-specified regressors in your design matrix (see BasicStatisticalModelingFaq for more on user-specified regressors). In order to include them, you'll need to have already run realignment, and you'll need to know where your realignment parameters file are (rp_V001.txt, or realignment_parameters_V001.txt). Usually they can be located in each session's functional image directory - one parameter file for each session.

Begin setting up your design matrix as usual (see BasicStatisticalModelingHowTos for step-by-step instructions). When asked if your conditions are replicated between sessions, say "no."

You'll be asked about your onset vectors and parametric modulations for each condition. After you've entered in your conditions for the first session, you'll be asked how many user-specified regressors you want. Enter "6."

When you're prompted to enter the regressor, type spm_load. This will bring up a file menu. Choose the realignment parameters file for the first session.

You'll then be asked to enter the names for each regressor. You can leave them as default, but if you'd like to label them in the design matrix, you should enter, in order, "x," "y," "z," "pitch," "roll," and "yaw."

Repeat the same steps for each session in your experiment. Your design matrix should then contain the motion parameters as separate columns in your design matrix. You should leave them out of most contrasts, but you can make contrasts with them to see motion-related activity in your experiment.

If you want to enter some derivation of your motion parameters - like the sine or cosine, or temporal derivative of them - you can embed the spm_load command into a Matlab function, like sin or abs. In this case, instead of typing simply spm_load at the prompt, you'll enter sin(spm_load), for example. If the derivation you want isn't a simple Matlab function which operates on every element of a matrix, you'll need to construct it in the Matlab workspace before you start entering your model, and refer to it by variable name instead.