[FieldTrip] Inverse-warping a template of MNI coordinates

Kenneth Shinozuka kennethshinozuka at gmail.com
Mon Oct 21 18:58:32 CEST 2024


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*

[image: Screenshot 2024-10-21 at 20.56.51.png]

*Figure 2*

[image: 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)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20241021/81a363f6/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screenshot 2024-10-21 at 20.41.13.png
Type: image/png
Size: 266627 bytes
Desc: not available
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20241021/81a363f6/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screenshot 2024-10-21 at 20.56.51.png
Type: image/png
Size: 163005 bytes
Desc: not available
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20241021/81a363f6/attachment-0003.png>


More information about the fieldtrip mailing list