Here is a description of the coordinates sytems used in Aims and Anatomist, and what I have understood of how SPM handles its referentials.
Anatomist uses AIMS to handle its referentials so behaves exactly the same way.
Aims tries to work internally in an image-specific referential, but with always the same orientation. This orientation is axial with the following coordinates system:
Once loaded in memory, all voxels should be organized in this order. As a consequence, images in Anatomist are always displayed in radiological mode, whatever the actual orientation of data on disk.
Images on disk, depending on their format and acquisition modes, are not necessarily in this orientation. When a different orientation is detected, images are flipped in memory at load-time to fit the standard AIMS orientation. And when images are written back to disk, they may also be flipped back according to the specific format needs.
By default, AIMS doesn't apply any transformation other than flipping images at load time as described just before.
But transformations can be provided in some Aims commands or loaded in Anatomist to apply coordinates changes. Then coords transformations are applied on the fly when processing or displaying data which are not in the same referential.
There is no special referential (such as a common central working referential).
Transformation files used by AIMS (.trm files) are ASCII files looking like this:
Tx Ty Tz R11 R12 R13 R21 R22 R23 R31 R32 R33Tx, Ty, Tz are the translation components while the Rij coefficients are the linear matrix part. When used, these coefficients are applied as a "standard" 4x4 transformation matrix:
[ R11 R12 R13 Tx ]
M = [ R21 R22 R23 Ty ]
[ R31 R32 R33 Tz ]
[ 0 0 0 1 ]
Internally, SPM thinks things is always in the same orientation, which is also axial but with different axes:
Working on the coordinate transformations for years and regularly getting headaches from it, I am still not 100% sure of what I say here, so if I'm wrong, please correct me by sending a message on BrainVisa forum (http://brainvisa.info/forum/). Especially, I'm not sure that SPM99 and SPM2 really use the same referentials.
SPM handles input images in two different orientations: axial radiological and axial neurological orientations. This orientation is not specified in SPM format image files, so you have to tell how they are oriented. This is done in SPM by a flipping flag set somewhere in SPM defaults configuration (default.analyze.flip in SPM2).
This flipping flag has changed in form and meaning between SPM99 and SPM2.
As I have understood:
SPM uses a common central referential to work in. Every image can provide a transformation matrix to this referential. Such a transformation is specified in an optional .mat file with the same name as the SPM format image. If this transformation is not provided, then the origin translation is considered to be the only transformation needed to reach the central referential. If the .mat file is specified, information contained in it overrides some of the header information (including the origin).
Normalization files (*_sn3d.mat for SPM99, *_sn.mat for SPM2) contain transformations to the referential of a normalization template (either a standard one provided with the SPM software distribution, or a custom user-made one). This transformation contains an affine part (matrix), and optionally, depending on the normalization type, a non-linear part (coefficients on a functions base as far as I know but I don't know much about this part). Information about the input and template images are also included (dimensions, voxel sizes and origins).
Normalized images are in the referential of the normalization template used, but not necessarily with the same bounding box, resolution and field of view.
SPM99 and SPM2 use normalization files with different names and different contents. They are not compatible, even if there is some common and similar information in them.
Due to the different internal orientations of the coordinate systems, going from SPM to AIMS and vice versa causes some serious problems.
SPM normalization files are in matlab (.mat) format. AIMS cannot read the proprietary matlab format, so such files cannot be directly imported in AIMS.
However, BrainVisa can use Matlab (if Matlab is installed) and convert SPM matrices to AIMS .trm format. Only the affine part can be converted, because AIMS only use matrices for transformations, and non-linear information cannot fit into a matrix.
As the orientation is different in SPM and AIMS, a transformation to a template image is not the same as a transformation to a normalized image with a different field of view. So, when converting SPM normalization matrices, the normalized image must be also provided, otherwise BrainVisa can only give the transformation to the normalization template. Note the difference.
It is impossible to guess the orientation of such images if you don't know how they were acquired. This means you have to manually specify their orientation, either for all images in SPM, or in BrainVisa when importing them into a database. BrainVisa tags them so it knows everything afterwards and avoids mistakes. SPM does not.
Normalizing the same image in radiological orientation with SPM99 and SPM2 results in normalized images in different orientations. When you import normalized images coming from another site, you have to know whether they have been normalized by SPM99 or by SPM2, and if the original image was in radiological or neurological orientation.
I think the normalization file (*_sn3d.mat for SPM99, or *_sn.mat for SPM2) contains enough information to retreive the orientation of input and template images, so can disambiguate the situation.
The origin field of SPM format is the position of the referential origin, in voxels and starting from 1 (not from 0). In fact it's a matlab array index. So it is given in the orientation of the image on disk. AIMS flips SPM images on several axes when loading them, so the origin information also has to be flipped. Flipping it needs to know the image dimensions.
AIMS referentials have their origin in the first voxel, (almost) in the corner of the image, and normally don't use the SPM origin. But the origin information is read and maintained. Anatomist can, if asked for, make a transformation going from AIMS origin (corner) to the SPM origin. This allows to display several aligned SPM images in Anatomist with the correct correspondance. However after this translation, the coordinates are still in AIMS orientation (radiological and indirect), not in SPM, so the coordinates do not correspond to what they are in SPM.
To compare coordinates of SPM images in Anatomist and SPM, another transformation has to be applied in Anatomist, with all the flips included. But this would result to a change in the referential orientation (it would become direct) and would produce some strange 3D rendering problems so it is not recommended to do so it you are not forced to.
Up to now, GIS images are considered being always in AIMS orientation. No flips are applied. Future releases may take orientation information into account.
The new Minc IO plugin takes orientation into account and flips data accordingly when reading / writing files.
I am not sure if other formats (Dicom, Ecat...) can specify an image orientation or not. If they do, the current release of AIMS will probably not take it into account.
SPM99 and SPM2 don't use the same format of normalization files, but both provide more or less the following information:
We want to calculate AIMS, provided Affine, MA and MT
Directly:
RSA = Affine * RST, or RST = Affine^-1 * RSA RAN = AIMS * RAA RSCA = MA * RSA RSCT = MT * RST RSCA = ASA * RAA RSCN = ASN * RAN RSCN = TN * RSCT
Combining them:
RSCN = ASN * AIMS * RAA
AIMS * RAA = ASN^-1 * RSCN
= ASN^-1 * TN * RSCT
= ASN^-1 * TN * MT * RST
= ASN^-1 * TN * MT * Affine^-1 * RSA
= ASN^-1 * TN * MT * Affine^-1 * MA^-1 * RSCA
= ASN^-1 * TN * MT * Affine^-1 * MA^-1 * ASA * RAA
AIMS = ASN^-1 * TN * MT * Affine^-1 * MA^-1 * ASA
ASA is a combination of an origin translation OA, and axes flips FA from AIMS standard ref to SPM standard ref:
[ 1 0 0 -Ox ]
OA = [ 0 1 0 -Oy ]
[ 0 0 1 -Oz ]
[ 0 0 0 1 ]
O = ( orgA - 1 ) .* vsA
[ -1 0 0 Tx ]
FA = [ 0 -1 0 Ty ]
[ 0 0 -1 Tz ]
[ 0 0 0 1 ]
T = ( dimA - 1 ) .* vsA
ASA = OA * FA
Similarly, for the normalized image:
ASN = ON * TNusing the normalized image sizes. To get the transformation to the template image only, use the sizes of the template image instead.