|
SPM99b B. Source code: spm_realign.m C. Notes
•number of subjects: 1 • num sessions for subject 1: 2- scans for sunject1, secc1: afmri_r10010.img~afmri_r10011.img (done) - scans for sunject1, secc2: afmri_r10012.img~afmri_r10013.img (done) • Which option?...- Coregister only - Reslice only - *Coregister & reslice <x> • Reslice interpolation method?...- Trilinear Interpolation - *Sinc Interpolation <x> - Fourier space interpolation • Create what?...- All images (1..n) - Images 2..n - * All Images + Mean Image <x> - Mean Image Only • Adjust sampling errors? yes <x> noRealign: working on subject
B.1 function spm_realign(arg1,arg2,arg3,arg4,arg5,arg6)
3. Uses : 4. Inputs: 5. Outputs: The parameter estimation part writes out ".mat" files for each of the input images. The part of the routine that writes the resliced images uses information in these ".mat" files and writes the realigned *.img files to the same subdirectory prefixed with an 'r' (i.e. r*.img). The details of the transformation are displayed in the results window as plots of translation and rotation. A set of realignment parameters are saved for each session, named: realignment_params_*.txt. 6. The Prompts Explained --- % 'number of subjects' Enter the number of subjects you wish to realign. For fMRI, it will ask you the % 'select scans for subject ..' Select the scans you wish to realign. All operations are relative to the first image ==== Note that not all of the following prompts may be used ==== % 'Which option?' - 'Coregister only' Only determine the parameters required to transform each of the images 2..n to - 'Reslice Only' Reslice the specified images according to the contents of the previously - ‘Coregister & Reslice' Combine the above two steps together. Options for reslicing: % 'Create what?' - 'All Images (1..n)' This reslices all the images - including the first image selected- which will - 'Images 2..n' Reslices images 2..n only. Useful for if you wish to reslice (for example) a - 'All Images + Mean Image' In addition to reslicing the images, it also creates a mean of the resliced image. - 'Mean Image Only' Creates the mean image only. % 'Mask the images?' To avoid artifactual movement-related variance. Because of subject motion, different images are likely to have different patterns of zeros from where it was not possible to sample data. With masking enabled, the program searches through the whole time series looking for voxels which need to be sampled from outside the original images. Where this occurs, that voxel is set to zero for the whole set of images (unless the image format can represent NaN, in which case NaNs are used where possible). % 'Adjust sampling errors?' (fMRI only) Adjust the data (fMRI) to remove interpolation errors arising from the reslicing of the data. The adjustment for each fMRI session is performed independantly of any other session. Bayesian statistics are used to attempt to regularize the adjustment in order to prevent an excessive amount of signal from being removed. A priori variances for coefficients are assumed to be stationary and are estimated by translating the first image by a number of different distances using both Fourier and sinc interpolation. This gives a ball park figure on how much error is likely to arise because of the approximations in the sinc interpolation. The certainty of the solution is obtained from the residuals after fitting the optimum linear combination of the basis functions through the data. Estimates of certainty based on the residuals are unfortunately just an approximation. We still don't fully understand the nature of the movement artifacts that arise using fMRI. The current model is simply attempting to remove interpolation errors. There are many other sources of error that the model does not attempt to remove. It is possible that adjusting the data without taking into account the design matrix for the statistics may be problematic when there are stimulous correlated movements, since adjusting seperately requires the assumption that the movements are independant from the paradigm. It MAY BE BE BETTER TO INCLUDE THE ESTIMATED MOTION PARAMETERS AS CONFOUNDS WHEN THE STATISTICS ARE RUN. The motion parameters are saved for each session, so this should be easily possible.
% 'Reslice Interpolation Method?' - 'Trilinear Interpolation'Use trilinear interpolation (first-order hold) to sample the images during the writing of realigned images. - 'Sinc Interpolation' Use a sinc interpolation to sample the images during the writing of realigned - 'Fourier space Interpolation' (fMRI only) Rigid body rotations are executed as a series of shears, which are performed in 7. The `.mat' files. This simply contains a 4x4 affine transformation matrix in a variable `M'. These files are normally generated by the `realignment' and `coregistration' modules. What these matrixes contain is a mapping from the voxel coordinates (x0,y0,z0) (where the first voxel is at coordinate (1,1,1)), to coordinates in millimeters (x1,y1,z1). By default, the the new coordinate system is derived from the `origin' and `vox' fields of the image header. x1 = M(1,1)*x0 + M(1,2)*y0 + M(1,3)*z0 + M(1,4) y1 = M(2,1)*x0 + M(2,2)*y0 + M(2,3)*z0 + M(2,4) z1 = M(3,1)*x0 + M(3,2)*y0 + M(3,3)*z0 + M(3,4) Assuming that image1 has a transformation matrix M1, and image2 has a transformation matrix M2, the mapping from image1 to image2 is: M2\M1 (ie. from the coordinate system of image1 into millimeters, followed by a mapping from millimeters into the space of image2). These `.mat' files allow several realignment or coregistration steps to be combined into a single operation (without the necessity of resampling the images several times). The `.mat' files are also used by the spatial normalisation module. B.2 function reslice_images(P,Flags,sessions) % FORMAT reslice_images(P,Flags,sessions) P - matrix of filenames {one string per row} All operations are performed relative to the first image. ie. Coregistration is to the first image, and resampling of images is into the space of the first image. sessions - the last scan in each of the sessions. For example, the images in the second session would be P((sessions(2-1)+1):sessions(2),:). Flags - options flags c - adjust the data (fMRI) to remove movement-related components. k - mask output images To avoid artifactual movement-related variance the realigned set of images can be internally masked, within the set (i.e. if any image has a zero value at a voxel than all images have zero values at that voxel). Zero values occur when regions 'outside' the image are moved 'inside' the image during realignment. i - write mean image The average of all the realigned scans is written to mean*.img. S - use sinc interpolation for reslicing (9x9x9). n - don't reslice the first image The first image is not actually moved, so it may not be necessary to resample it. N - don't reslice any of the images - except possibly create a mean image. a - write absolute values in images - more appropriate for fMRI. The spatially realigned and adjusted images are written to the orginal subdirectory with the same filename but prefixed
B.3 function realign_images(P,Q,sessions) %FORMAT realign_images(P,Q,sessions) P - matrix of filenames {one string per row} All operations are performed relative to the first image. ie. Coregistration is to the first image, and resampling of images is into the space of the first image. sessions - the last scan in each of the sessions. For example, the images in the second session would be P((sessions(2-1)+1):sessions(2),:). Q - an optional matrix of filenames. These are used for masking out regions which are (roughly) considered to be outside the brain. The last filename is an image containing values between zero and one, where each value is a weight. The other images are template images. The way that this works is that the first image in the series is matched (using an affine transformation) to a linear combinantion of the template images. This affine mapping can then be used to overlay the weight image over the first image of the series.
B.4 function reslice_images_volbyvol(P,Flags,sessions) % Reslices images volume by volume % FORMAT reslice_images_volbyvol(P,Flags,sessions) P - matrix of filenames {one string per row} All operations are performed relative to the first image. ie. Coregistration is to the first image, and resampling of images is into the space of the first image. sessions - the last scan in each of the sessions. For example, the images in the second session would be P((sessions(2-1)+1):sessions(2),:). Flags - options flags k - mask output images To avoid artifactual movement-related variance the realigned set of images can be internally masked, within the set (i.e. if any image has a zero value at a voxel than all images have zero values at that voxel). Zero values occur when regions 'outside' the image are moved 'inside' the image during realignment. i - write mean image The average of all the realigned scans is written to mean*.img. S - use sinc interpolation for reslicing (9x9x9). n - don't reslice the first image The first image is not actually moved, so it may not be necessary to resample it. N - don't reslice any of the images - except possibly create a mean image. The spatially realigned images are written to the orginal subdirectory with the same filename but prefixed with an 'r'. They are all aligned with the first. The only reason for reslicing a series plane by plane is to do the adjustment.
1. New features of Realign in SPM99 - handles multiple fMRI sessions - two pass procedure for PET realignment (images registered to mean) - checks for stopping criterion - Fourier interpolation (for data with isotropic voxels) - algorithm generally improved
H(a|b) = H(b|a) +
H(a) + c distributions for H(a) are estimated by translating the first image of the series by different amounts, using the windowed sinc function, and Fourier interpolation. This allows an estimate to be made for the a priori distribution of the errors.
|
|