Hi Vladimir thanks a lot for your elaborated and detailed response... to quickly summarize and check that I have understood you correctly: forward.datareg.fid_mri.fid.pnt - "sensor coordinate" based positions of the fiducials. 'sensor based' meaning here that they are in the same coordinate system as the D.sensors (or in fieldtrip the 'grad' definition) - but does not (necessarily) mean that they are "locked" to the actual sensor positions. those can vary between datasets (esp for MEG) D.inv{...}.mesh.Affine - is the transformation matrix between the coordinate system inherent to the individual MRI (i.e usually the analyze file *.hdr/*.img) and the MNI the transformation matrix (in the code represented by 'M1') that rotates the 'sensor-based' (in the case of CTF: head-based) coordinate system onto the native individual's MRI (as in the analyze file) - is not directly stored but can be obtained by: inv(D.inv{val}.mesh.Affine) * D.inv{val}.datareg(ind).toMNI Thanks a lot again. I guess that should be correct and seems quite clear. Markus > Hi Markus, > > On Mon, Apr 26, 2010 at 5:51 PM, Markus Bauer<[log in to unmask]> wrote: > >> Are the fiducial positions after manual coregistration (using >> spm_eeg_inv_datareg_ui) stored anywhere in MRI-coordinates? >> I looked into the code and from what I see there, the manually entered >> fiducials (by clicking in the interactive window) are stored in the >> following field: >> >> forward.datareg.fid_mri.fid.pnt >> >> >> But that seems to be in (CTF ?) headcoordinates. >> I also found >> >> forward.mesh.fid.fid.pnt >> >> >> which seem to be the standard (MNI based) fiducial positions. >> I also found >> >> forward.datareg.fid_eeg.fid.pnt >> >> >> which could be the fiducials measured by the system, but I neither found the >> fiducials in MRI coordinates nor the transformation matrix to go from MRI to >> headcoordinates. >> Do you know where that is? >> > > I'll try to give a detailed answer this time to explain the logic > behind the code. SPM needs to take into account 4 coordinate systems > that might or might not be different. > > 1) The coordinate system in which sensor locations were provided. > That's what you get from D.sensors and D.fiducials. > 2) MNI coordinates corresponding to the template brain . > 3) Native coordinates corresponding to the subject's structural. They > might be the same as MNI coordinates of the structural was > coregistered to the template, but might also be different. > 4) The coordinate system in which MRI and sensors are coregistered. In > the case of EEG these are 'native coordinates' (3) and in the case of > MEG these are sensor coordinates (1). Usually for MEG these are so > called head coordinates, but they are defined in different way for > different MEG systems. > > The reason for the difference between EEG and MEG is that for EEG the > coordinate system where sensor locations are measured is usually not > very meaningful so it is convenient to express everything in > MRI-linked coordinates. In MEG, however, it is convenient to use head > coordinates because then the same coregistration can be used for > different runs (the location of the head in head coordinates is fixed > and only the sensor locations change). > > Now, the canonical meshes that can be found in the .gii files under > spm/canonical are in MNI coordinates. There is also a set of standard > fiducials defined in MNI coordinates on the template brain. When you > use individual structural, nonlinear transformation is computed from > the template image to your individual image. The meshes and the > standard fiducials are then warped to correspond to the individual > image. These new meshes are stored in gii files in the directory where > that structural is. The names of these files appear in > D.inv{...}.mesh. There is also a copy of the unwarped canonical mesh > stored there (mesh.tess_mni). This is useful for producing output when > you move your datasets with inversions somewhere where the links to > individual meshes no longer work. Under D.inv{...}.mesh.fid you can > find the standard fiducials transformed to the 'native' coordinates. > If you use the template rather than individual image, these fiducials > will be in MNI coordinates. Under D.inv{...}.mesh.Affine you can find > a transformation matrix from native to MNI coordinates. Note that this > is just approximation to the nonlinear transform that is actually > applied to the meshes. > > Now, when you do coregistration you define some corresponding points > in the native coordinates to at least 3 fiducials from those available > in sensor coordinates. These are used to compute the transformation > matrix between sensor and native coordinates (called M1 in the code of > spm_eeg_inv_datareg_ui). In the MEG case everything is then stored in > sensor coordinates, including the MRI fiducials. The function also > computes transformation matrices between the coregistration > coordinates (head coordinates) and MNI coordinates, since these are > the most useful to know in practice. If you look at lines 174-175 in > the latest version, you'll see: > > D.inv{val}.datareg(ind).toMNI = D.inv{val}.mesh.Affine*M1; > D.inv{val}.datareg(ind).fromMNI = inv(D.inv{val}.datareg(ind).toMNI); > > > Now I can finally answer your question. You have MRI fiducials in head > coordinates stored under D.inv{...}.datareg.fid_mri . You can use the > function forwinv_transform_headshape (in the latest in-house SPM it's > called ft_transform_headshape) to transform these fiducials to another > coordinate system. All you need to provide is a 4x4 transformation > matrix. All you need for that is also provided. To go from head to MNI > coordinates you can use D.inv{...}.datareg.toMNI . To go to native > coordinates you can use > inv(D.inv{...}.mesh.Affine)*D.inv{...}.datareg.toMNI. So let's say > that you have a unimodal MEG dataset with a single inversion and want > to get MRI fiducials in MNI coordinates. Then you do: > > mnifid = ft_transform_headshape(D.inv{1}.datareg.toMNI, > D.inv{1}.datareg.fid_mri ); > > > I hope that was clear. If not, keep asking. > > Best, > > Vladimir >