[FieldTrip] Inverse-warping a template of MNI coordinates

Kenneth Shinozuka kennethshinozuka at gmail.com
Fri Oct 25 16:21:02 CEST 2024


Dear Jan-Mathijs,

I just wanted to follow up on my previous message. I have revised my
pipeline to the following:

After reading in the MRI, I am running ft_determine_coordsys, which
identifies the coordinate system as 'ras'. I then run ft_volumerealign to
align the MRI with the CTF coordinate system (the MEG data was collected
with a CTF machine). The rest of the pipeline is unchanged; I inverse-warp
the template of MNI coordinates to the subject's anatomical MRI, which is
now already in the CTF coordinate system.

Is this pipeline correct?

Thank you so much, and we look forward to hearing from you soon.

Best regards,
Kenneth


On Mon, Oct 21, 2024 at 11:45 PM Kenneth Shinozuka <
kennethshinozuka at gmail.com> wrote:

> Dear Jan-Mathijs,
>
> Many thanks for your quick reply!
>
> There is no 'coordsys' field in mri when I read it in with ft_read_mri.
> When I run ft_determine_coordsys, the output coordsys is 'ras'. However,
> the origin of the coordinate system of the MRI is not a landmark. As you
> can see in Figure 1 in the previous email that I sent, it appears to be
> shifted downward in the Z-axis relative to the anterior commissure. My
> reason for running ft_volumerealign was to re-center the origin of the MRI
> coordinate system at the anterior commissure.
>
> However, if I just set mri.coordsys = 'ras', delete the ft_volumerealign
> step, and then run the rest of my pipeline unchanged, my visualization of
> the source activity changes slightly, but it is still very misaligned to
> the subject's MRI; please see below.
>
> sourcemodel and headmodel are both in units of 'mm'. tlock.grad is in
> units of 'cm', but it appears that FieldTrip converts these 'cm' units to
> 'mm' units during ft_prepare_leadfield (according to the output in the
> command window).
>
> 'positions' is a 591x3 matrix consisting of the MNI coordinates of 591
> voxels of interest. These generally fall into four regions of interest,
> which were defined in a previous study: fusiform face area, thalamus, left
> dorsolateral prefrontal cortex, and right dorsolateral prefrontal cortex. I
> have attached the positions as a .mat file below.
>
> Please let me know if you would like any further information!
>
> Best regards,
> Kenneth
>
> [image: Screenshot 2024-10-21 at 22.36.37.png]
>
> On Mon, Oct 21, 2024 at 10:04 PM Schoffelen, J.M. (Jan Mathijs) via
> fieldtrip <fieldtrip at science.ru.nl> wrote:
>
>> Hi Kenneth,
>>
>> Assuming that the ‘source_placebo’ variable you refer to in the second
>> part of your message has been obtained in a similar way as the ‘source’
>> variable in the first part of your message, to me it looks that there’s
>> something off with the ‘positions’ that you start out with. Without
>> additional information about those it is difficult to comment.
>>
>> Besides this, I suggest that you go through your pipeline step-by-step
>> and visualize in more detail the objects that go in and out of the
>> individual function calls.
>> Specificallly you should pay attention to whether the coordinate systems
>> and geometric units are aligned (FieldTrip might be forgiving with respect
>> to units, but it never hurts to explicitly equalize them across data
>> objects (volume conductor model, source grid, sensor defintion). It goes
>> without saying that FieldTrip is not forgiving with respect to differences
>> in coordinate systems. Those should match across input objects. It’s not
>> often that I have seen an MEG system with the sensors defined in ‘acpc’
>> coordinates, so I doubt whether the first alignment step to obtain
>> mri_realigned from the original mri image is correct.
>>
>> Good luck
>> Jan-Mathijs
>>
>>
>> On 21 Oct 2024, at 18:58, Kenneth Shinozuka via fieldtrip <
>> fieldtrip at science.ru.nl> wrote:
>>
>> Hello,
>>
>> I am currently source-localizing some MEG data in such a way that I am
>> inverse-warping a template of MNI coordinates to each individual's
>> anatomical MRI. I am running the following code:
>> mri = ft_read_mri(mri_filename);
>>
>> cfg = []; cfg.method = 'interactive'; cfg.coordsys = 'acpc'; % the
>> desired coordinate systemmri_realigned = ft_volumerealign(cfg, mri); cfg
>> = []; cfg.sourcemodel.pos = positions; template =
>> ft_prepare_sourcemodel(cfg); cfg = []; cfg.method = 'basedonmni'; cfg.template
>> = ft_convert_units(template.sourcemodel, 'mm');cfg.nonlinear = 'yes'; %
>> use non-linear normalizationcfg.mri = mri_realigned;sourcemodel =
>> ft_prepare_sourcemodel(cfg); % Prepare head model using single-shell
>> method cfg = []; cfg.output = 'brain'; segmentedmri =
>> ft_volumesegment(cfg, mri_realigned); cfg = []; cfg.method =
>> 'singleshell';headmodel = ft_prepare_headmodel(cfg, segmentedmri); %
>> Calculate means and covariances for source analysiscfg = []; cfg.covariance
>> = 'yes'; cfg.covariancewindow = 'all'; cfg.channel = 'MEG'; cfg.keeptrial
>> = 'yes'; tlock = ft_timelockanalysis(cfg, data); % data is preprocessed
>> MEG data % Prepare leadfield model cfg = []; cfg.grad = tlock.grad; cfg.headmodel
>> = headmodel; cfg.reducerank = 2; cfg.channel = {'MEG'}; cfg.sourcemodel
>> = sourcemodel; % Inverse-warped templatecfg.normalize = 'yes'; cfg.normalizeparam
>> = 1;[lf] = ft_prepare_leadfield(cfg); % Run source analysis on the
>> subject-specific inverse-warped template positionscfg = []; cfg.method =
>> 'lcmv'; cfg.sourcemodel = lf; cfg.headmodel = headmodel; cfg.lcmv.keepfilter
>> = 'yes'; cfg.lcmv.lambda = '5%'; cfg.lcmv.fixedori = 'yes';source =
>> ft_sourceanalysis(cfg, tlock);
>> nb_sources = length(source.avg.filter); nb_trials = length(data.trial); nb_samples
>> = size(data.trial{1}, 2);vs = zeros(nb_sources,nb_trials,nb_samples); for
>> i=1:nb_sources flt = source.avg.filter{i}; if isempty(flt) vs(i,:,:) =
>> NaN(nb_trials,nb_samples); % source-reconstructed timeseries else for t=1:nb_trials
>> v = flt*data.trial{t}; vs(i,t,:) = v; end end end vs = squeeze(vs);
>> *I have three questions: *
>>
>>    1. *Is it necessary to run ft_volumerealign before running
>>    ft_prepare_sourcemodel? The origin of the anatomical MRI does not appear to
>>    be the anterior commissure; see figure 1 below, which was produced through
>>    ft_determine_coordsys.*
>>    2. *source.avg.pow contains very small values, on the order of
>>    10^-47, even though the MEG data is on the order of 10^-14.*
>>    3. *When I try to visualize the source activity, it seems totally
>>    misaligned with the anatomical MRI. See figure 2 and the code that was used
>>    to produce it below.*
>>
>> *Figure 1*
>>
>> <Screenshot 2024-10-21 at 20.56.51.png>
>>
>> *Figure 2*
>>
>> <Screenshot 2024-10-21 at 20.41.13.png>
>>
>> % Interpolate the source onto the MRI for visualization
>> cfg = [];
>> cfg.parameter = 'pow';  % Or 'avg.pow' depending on your data
>> cfg.interpmethod = 'nearest';
>> source_interp = ft_sourceinterpolate(cfg, source_placebo, mri_realigned);
>> % Plot the source on the MRI
>> cfg = [];
>> cfg.method = 'ortho';
>> cfg.funparameter = 'pow';
>> ft_sourceplot(cfg, source_interp);
>>
>> Many thanks for reading this long email! I look forward to hearing from
>> you.
>>
>> Best regards,
>> Kenneth Shinozuka
>>
>> --
>> Kenneth Shinozuka
>> Harvard College '20 | BA in Neuroscience
>> Oxford University '24 | PhD Candidate in Psychiatry
>> +1 9493028589 (US, WhatsApp)
>> +44 07572876618 (UK)
>> _______________________________________________
>> fieldtrip mailing list
>> https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>> https://doi.org/10.1371/journal.pcbi.1002202
>>
>>
>> _______________________________________________
>> fieldtrip mailing list
>> https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>> https://doi.org/10.1371/journal.pcbi.1002202
>>
>
>
> --
> Kenneth Shinozuka
> Harvard College '20 | BA in Neuroscience
> Oxford University '24 | PhD Candidate in Psychiatry
> +1 9493028589 (US, WhatsApp)
> +44 07572876618 (UK)
>


-- 
Kenneth Shinozuka
Harvard College '20 | BA in Neuroscience
Oxford University '24 | PhD Candidate in Psychiatry
+1 9493028589 (US, WhatsApp)
+44 07572876618 (UK)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20241025/e9b669e6/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screenshot 2024-10-21 at 22.36.37.png
Type: image/png
Size: 185675 bytes
Desc: not available
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20241025/e9b669e6/attachment-0001.png>


More information about the fieldtrip mailing list