[FieldTrip] Registration of neuromag data

Schoffelen, J.M. (Jan Mathijs) janmathijs.schoffelen at donders.ru.nl
Fri Nov 15 17:32:04 CET 2024


Hi Alex,

Now I must confess that I am confused. Also, Konstantinos actually has pointed out - I think - the answer that you are looking for.

Let’s step away from the figures in your e-mail, and the code that you pasted in, and the mapping between executed steps and the exact figures.

if you read in an MRI file into FieldTrip, the code typically cannot determine what world coordinate system is attached to the MRI image. This is something that requires user input (e.g. by using ft_determine_coordsys, or by explicitly adding a field mri.coordsys to the structure, provided that you know what it is). The mri.transform matrix maps from voxel space to world space, and the inverse of this matrix clearly goes into the opposite direction.

Now, if your headshape is defined in the way I think it has been defined, i.e. the coordinates are in ’neuromag’ space, which means that the 3D coordinates of the fiducials are already in the neuromag coordinate system.

The MRI image - on the other hand - can be in any coordinate system, which is either 1) in neuromag coordinates, or 2) not. Note that we - the readers of the list - don’t necessarily know this.

If 1), then the MRI image is already in register with the headshape, so no ft_volumerealign will be needed

if 2), then a procedure that maps the headshape’s fiducials back into voxel space, using a totally wrong matrix (i.e. the inverse of matrix that goes from the MRI’s voxels to (another than neuromag) coordinate system) will yield voxel coordinates for the fiducials that don’t make sense.

This is exactly what Konstantinos wrote earlier today.

The solution for situation 2) is indeed to ‘manually’ define the locations of the fiducials in the mri image (using ft_volumerealign with the method ‘interactive’). This step will bring the mri in register with the coordinate system of the MEG data. Optionally, you can try to refine the coregistration after this step by using the ‘headshape’ method.

I hope this helps,
Jan-Mathijs



On 15 Nov 2024, at 15:48, Alex Williams via fieldtrip <fieldtrip at science.ru.nl> wrote:

Oh I see! I truly apologize for that. I didn't catch that you were referring to the figure name in the image. Thanks so much again for clarifying again. So figure 3 (i.e. the model with the sagittal tilt) uses the inverted transform and then uses the resulting transformed fiducial coordinates with volumerealign's fiducial method to obtain the coregistered model within a neuromag coordinate system (mrialign). But then, it takes that obtained mrialign variable and applies the volumerealign function once more using the headshape method to obtain the model in figure 3. Due to using volumerealign a second time using the headshape method after the model is brought into neuromag space using the first volumerealign, would the use of the second volumerealign in figure 3 be necessary? I only ask because figure 4 (i.e. the model with a larger axial distance from the sensor array) also uses the inverted transform but only uses the volumerealign function once to apply the fiducials, completely eschewing the use of the second volumerealign that applies a headshape method.

On Fri, Nov 15, 2024, 07:31 Schoffelen, J.M. (Jan Mathijs) via fieldtrip <fieldtrip at science.ru.nl<mailto:fieldtrip at science.ru.nl>> wrote:
Sorry if I was unclear Alex, with ‘figure 3’ I meant the first figure in your e-mail, i.e. the one which correctly uses the inverse of the transformation matrix, to express the fiducials in voxel coordinates, and then correctly updates the mri’s transformation matrix.

Best wishes,
Jan-Mathijs


On 15 Nov 2024, at 13:13, Alex Williams <alexanderwil2024 at my.fit.edu<mailto:alexanderwil2024 at my.fit.edu>> wrote:

You don't often get email from alexanderwil2024 at my.fit.edu<mailto:alexanderwil2024 at my.fit.edu>. Learn why this is important<https://aka.ms/LearnAboutSenderIdentification>
Hi Jan-Mathijs,


   Thanks so much for your response! So the third image uses both volumerealigns but uses a non-inverted transform from mriread. The only image that uses only one call to volumerealign applying the fiducial method is image two, but it applies an inverted transform from mriread. But was hoping to confirm that the third image would be the best for coregistration in this case.

-Alex



On Fri, Nov 15, 2024, 05:32 Schoffelen, J.M. (Jan Mathijs) via fieldtrip <fieldtrip at science.ru.nl<mailto:fieldtrip at science.ru.nl>> wrote:
Hi Alex,

To be honest, I have the impression that what you plotted in ‘figure 3’ makes sense.

The other ones don’t make sense, because the sensors are expressed in neuromag space (I assume) so the ‘brain’ needs to be brought into neuromag space as well, which is what you do with your first call to ft_volumerealign. Unless I am missing something.


Best wishes,
Jan-Mathijs

On 14 Nov 2024, at 19:26, Alex Williams via fieldtrip <fieldtrip at science.ru.nl<mailto:fieldtrip at science.ru.nl>> wrote:

Hi there FieldTrip community,

  I was curious if anyone would be familiar with an issue I came across within my study. I'm currently using an lcmv beamformer for source reconstruction of several subjects within the CamCan data set using their MEEG data. Right now, I'm currently looking back into the process of coregistration once more. The meeg data and headshape data I have use neuromag coordinates and I believe the coordinates of the fiducials are in voxel-coordinates. For all of the subjects, I get a coregistered orientation that seems to be tilted relative to the sensor array.

 I'm unsure if this would be the correct orientation based on what I've seen from previous head model orientations. However, since I'm unfamiliar with how the head would be oriented within a neuromag system, I was wondering if there was any way to confirm that this orientation would be correct or if there may be something that needs to be rectified in the code for proper orientation.

Here is the code I used for coregistration to acquire the image above:

%% Realign Coord Sys.
function mrialign=coregistration(Path1,Path2,mriread,S,job)
addpath /Users/alexanderwil2024/MATLAB-Drive/Research/MATLAB code/Beamformer Pipeline
cfg=[];
headshape=ft_read_headshape([Path1 Path2]);
headshape=ft_convert_coordsys(headshape,'neuromag');
vox2vox = inv(mriread.transform);
nas_voxel_mriread = ft_warp_apply(vox2vox, headshape.fid.pos(2,:), 'homogenous'); % nasion
lpa_voxel_mriread = ft_warp_apply(vox2vox, headshape.fid.pos(1,:), 'homogenous'); % Left preauricular
rpa_voxel_mriread = ft_warp_apply(vox2vox, headshape.fid.pos(3,:), 'homogenous'); % Right preauricular

cfg=[];
nas1=nas_voxel_mriread;
lpa1=lpa_voxel_mriread;
rpa1=rpa_voxel_mriread;
cfg.fiducial.nas=nas1;
cfg.fiducial.lpa=lpa1;
cfg.fiducial.rpa=rpa1;
cfg.coordsys='neuromag';
cfg.method='fiducial';
mrialign = ft_volumerealign(cfg, mriread);
ft_sourceplot([],mrialign);

cfg=[];
cfg.method='headshape';
cfg.spmversion='spm12';
cfg.headshape.headshape=headshape;
cfg.headshape.interactive = 'no';
mrialign=ft_volumerealign(cfg, mrialign);

% ********FOR VISUALIZING CO-REGISTRATION: IMPORTANT FOR FIDUCIALS!!!
% cfg=[];
% cfg.method='headshape';
% cfg.spmversion='spm12';
% cfg.headshape.headshape=headshape;
% cfg.headshape.interactive = 'yes';
% ft_volumerealign(cfg, mrialign);

cfg=[];
cfg.parameter='anatomy';
cfg.filename=['/Volumes/My Book/coreg_mri_niftis/mrialign ',S,' for job ',job];
cfg.filetype='nifti';
ft_volumewrite(cfg,mrialign);
close all
o=1;
end
  In this code, mriread refers to the subject's raw MRI nifti data after being read in. tably, after the first use of volumerealign within the code to apply the fiducials from the mri nifti (mrialign = ft_volumerealign(cfg, mriread)), I use it again to apply a headshape-based method. I obtain this sagitally tilted positioning when using this setup:

<Both volumerealigns.png>

  For additional reference, if I were to only use the first instance of the volumerealign function to apply the fiducials to mriread without using the second instance to apply the headshape method, I would obtain this coregistered model, which seem properly oriented but slightly removed from the sensor array:

<Only fiducial volumerealign.png>


Additionally, the vox2vox transform matrix inverts mriread's transform matrix to create the following coregistered positions. However, when the vox2vox transform doesn't use the inverted transform (vox2vox =mriread.transform) and applies the full code with both volumerealign methods, it leads to a coronally tilted positioning:

<image.png>



-Alex

_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmailman.science.ru.nl%2Fmailman%2Flistinfo%2Ffieldtrip&data=05%7C02%7Cfieldtrip%40science.ru.nl%7Cc48db74617f141790fb808dd05930a0b%7C084578d9400d4a5aa7c7e76ca47af400%7C1%7C0%7C638672851280232142%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=7JZEWoba6HU53P9Qv5Eis6i8bzon3ZU0zXKv5JGfj6U%3D&reserved=0>
https://doi.org/10.1371/journal.pcbi.1002202<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdoi.org%2F10.1371%2Fjournal.pcbi.1002202&data=05%7C02%7Cfieldtrip%40science.ru.nl%7Cc48db74617f141790fb808dd05930a0b%7C084578d9400d4a5aa7c7e76ca47af400%7C1%7C0%7C638672851280388392%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=5y3gsNkFbGjylm%2BiGdiqXmE9%2FV0WAmHcXdm8ye6fxgk%3D&reserved=0>

_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmailman.science.ru.nl%2Fmailman%2Flistinfo%2Ffieldtrip&data=05%7C02%7Cfieldtrip%40science.ru.nl%7Cc48db74617f141790fb808dd05930a0b%7C084578d9400d4a5aa7c7e76ca47af400%7C1%7C0%7C638672851280388392%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=r26oN6RwTYy7jVCmlJyMdw%2BfWh%2B%2FrvqvnV%2BfUebdXHM%3D&reserved=0>
https://doi.org/10.1371/journal.pcbi.1002202<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdoi.org%2F10.1371%2Fjournal.pcbi.1002202&data=05%7C02%7Cfieldtrip%40science.ru.nl%7Cc48db74617f141790fb808dd05930a0b%7C084578d9400d4a5aa7c7e76ca47af400%7C1%7C0%7C638672851280388392%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=5y3gsNkFbGjylm%2BiGdiqXmE9%2FV0WAmHcXdm8ye6fxgk%3D&reserved=0>

_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmailman.science.ru.nl%2Fmailman%2Flistinfo%2Ffieldtrip&data=05%7C02%7Cfieldtrip%40science.ru.nl%7Cc48db74617f141790fb808dd05930a0b%7C084578d9400d4a5aa7c7e76ca47af400%7C1%7C0%7C638672851280544705%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=5liniOtS%2FIcG4LuzAegGQrFZfTN9F0ygeyS%2BPIuBpgY%3D&reserved=0>
https://doi.org/10.1371/journal.pcbi.1002202<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdoi.org%2F10.1371%2Fjournal.pcbi.1002202&data=05%7C02%7Cfieldtrip%40science.ru.nl%7Cc48db74617f141790fb808dd05930a0b%7C084578d9400d4a5aa7c7e76ca47af400%7C1%7C0%7C638672851280544705%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=Rrr%2FFHuMRlYrrRfSkZ9nOVxiXZ9zLrM7JXmKqkskw7w%3D&reserved=0>
_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
https://doi.org/10.1371/journal.pcbi.1002202

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20241115/bf771037/attachment.htm>


More information about the fieldtrip mailing list