[FieldTrip] Interpolation Error with Custom Lead Field
Nakhnikian, Alexander
Alexander_Nakhnikian at hms.harvard.edu
Thu May 4 20:39:24 CEST 2017
Dear All,
I'm trying to fine tune a forward model by first constraining the dipoles to the gray matter and then selecting only a subset of structures. It looks as though I need to write a custom script for this, which I have and the commented code is included below. Once I generate the lead field with this code I add it to the cfg structure for ft_sourceanalysis and proceed as usual.
The error occurs when I attempt to interpolate the power to a structural MRI. ft_sourceinterpolate(cfg,sources,mri) - cfg.downsample=10; cfg.parameter='pow' - and 'mri' is FT's template structural scan. Calling ft_sourceinterpolate with sources generated using my custom forward model produces this error:
Error using interpn (line 153)
Wrong number of input arguments.
Error in ft_sourceinterpolate>my_interpn (line 693)
av(sel) = interpn(fv, ax(sel), ay(sel), az(sel), interpmethod);
Error in ft_sourceinterpolate (line 535)
interp.inside( sel) = my_interpn(double(functional.inside), ax(sel), ay(sel), az(sel), 'nearest',
cfg.feedback);
The only hint I've found is that for some reason the source structure returns for this analysis doesn't contain the field '.dim' but I added it manually. Once that's done, the setup looks identical to data returned using a automatically generated grid so I must be missing something.
Thanks in advance if anyone can suggest where to look for the bug.
Alexander
Code:
function [lf] = fT_constrainFM(cfg)
%Creates a constrained forward model for source analysis in field trip. The
%grid is constrained to a surface defined by two maps. One
%restrains the dipoles to gray matter and the second is a list of labels corresponding to
%ROIs within the GM.
%Example: Constrain grey matter to cortical sites of interest.
%cfg.roi = labelsNDL; %A cell array of strings with the name of each ROI
%cfg.atlas = aal; %aal is a variable returned by ft_readatlas
%cfg.inputcoord = 'mni'; %Choose coordinates
%cfg.mri = mri; %A template MRI or subject sMRI
%cfg.thres = 0.95; %Threshold for probabilistic masks
%cfg.lf = C; %C is a structure with fields *.elec and *.headmodel. See
%ft_prepareleadfield
%[lf] = fT_contrainFM(cfg)
mri = cfg.mri;
cfgLF = cfg.lf;
thres = cfg.thres;
cfg = rmfield(cfg,{'mri','thres','lf'});
%Get the masks
seg = ft_volumesegment([],mri);
tissue = logical(seg.gray>=thres);
roiMask = logical(ft_volumelookup(cfg,mri));
voxInds = tissue&roiMask; %dipole placement locations
[rows,cols,pages] = ind2sub(size(roiMask),find(voxInds));
cfgLF.pos = zeros(length(rows),3);
%adjustment vaues to move the origin
rowAd = (size(roiMask,1)-1)/2;
colAd = (size(roiMask,2)-1)/2;
pageAd = (size(roiMask,3)-1)/2;
%collect dipole positions into an Nx3 matrix
for posInd = 1:length(rows)
cfgLF.pos(posInd,:) = [rows(posInd)-rowAd,cols(posInd)-colAd,pages(posInd)-pageAd]';
end
lf = ft_prepare_leadfield(cfgLF);
Alexander Nakhnikian, Ph.D.
Research Investigator
VA Boston Healthcare System
Instructor in Psychiatry, Harvard Medical School
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20170504/1ea1c449/attachment-0001.html>
More information about the fieldtrip
mailing list