[FieldTrip] reverse source interpolate?
Cornelius Abel
cornabel at googlemail.com
Mon Jul 2 14:52:58 CEST 2012
Hi mailing list,
I'm still struggling with the conversion of coordinates between source and
interpolated source space.
For example, if i have the position of a single grid point how do i get the
corresponding voxel in the interpolated source structure. Or the other way
around, how to get the grid point which corresponds to a voxel (e.g the max
voxel) in the interpolated source structure.
I think this should be a common problem when working with virtual
electrodes, shouldn't it?
To make things easier i put together a example with the data from the
source tutorial where i tried to calculated the grid pos of the max voxel
in the interpolated source.
clear all;
load sourcePost_nocon; % source structure from tutorial
mri = ft_read_mri('Subject01.mri'); % mri of subject01 from tutorial
sourceNAI = sourcePost_nocon;
sourceNAI.avg.pow = sourcePost_nocon.avg.pow ./ sourcePost_nocon.avg.noise;
sourceNAI=rmfield(sourceNAI,'freq'); % had to remove that to let
cfg = [];
cfg.downsample = 2;
cfg.parameter = 'avg.pow';
sourceNAIInt = ft_sourceinterpolate(cfg, sourceNAI , mri);
% Find position of max activity
[dum, maxindx] = max(sourceNAIInt.avg.pow(:));
[xi, yi, zi] = ind2sub(sourceNAIInt.dim, maxindx);
posInt=[xi, yi, zi];
% Plot interpolated source with position of max activity
cfg = [];
cfg.method = 'ortho';
cfg.funparameter = 'avg.pow';
cfg.locationcoordinates = 'voxel';
cfg.location = posInt; % location of max activity is marked
correctly.
figure;
ft_sourceplot(cfg,sourceNAIInt);
% Transform coordinate back to uninterpolated source???
dpos = warp_apply(inv(mri.transform), posInt, 'homogeneous');
% Plot uninterpolated source with position aquired from interpolated source
cfg = [];
cfg.method = 'ortho';
cfg.funparameter = 'avg.pow';
cfg.locationcoordinates = 'voxel';
cfg.location = dpos; % unfortunately this coordinate is
obviously wrong!!! WHY?
figure;
ft_sourceplot(cfg,sourceNAI);
Unfortunately the solution of Jan Mathijs did not work, nor did mine :(
Any ideas???
Cornelius
2012/6/28 jan-mathijs schoffelen <jan.schoffelen at donders.ru.nl>
> Hi Cornelius,
>
> Probably you should use: cfg.locationcoordinates to be 'head'.
>
> Best,
>
> JM
>
> On Jun 28, 2012, at 11:19 AM, Cornelius Abel wrote:
>
> Hi jan mathijs, hello mailing list,
>
> thanks for your answer. I think i got your idea with finding the minimum
> in this squared differences. This should the work with positions of any
> scaling, right?
> However it gives me strange results when trying to get voxel indices in
> the "raw" source using voxel indices aquired from interpolated source.
> But even using the ctf coordinates in mm doesn't work.
>
> Here is a short script showing what i did, i also attached the necessary
> mat files.
>
> greetings, Cornelius
>
>
> clear all;
> load testdata.mat;
>
> % Interpolate source on anatomy
> cfg = [];
> cfg.parameter = 'avg.itc';
> cfg.interpmethod = 'linear';
> sourceInt = ft_sourceinterpolate(cfg, source,mri);
>
> % Find position of max voxel in interpolated source
> [maxval, maxindx] = max(sourceInt.avg.itc(:));
> [x,y,z]=ind2sub(size(sourceInt.avg.itc),maxindx);
> pos=[x y z];
>
> % plot this position in interpolated source
> figure;
> cfg = [];
> cfg.method = 'ortho';
> cfg.funparameter = 'avg.itc';
> cfg.locationcoordinates = 'voxel';
> cfg.location = pos;
> ft_sourceplot(cfg, sourceInt);
>
> % Calculate respective position in 'raw' source struct
> dpos = source.pos - repmat(pos, size(source.pos,1),1);
> [m,ind] = min(sum(dpos.^2,2));
> spos=source.pos(ind,:);
>
> % Plot position in 'raw' source.
> % This gives not the position of max activity!!!
> figure;
> cfg = [];
> cfg.method = 'ortho';
> cfg.funparameter = 'avg.itc';
> cfg.locationcoordinates = 'voxel';
> cfg.location = spos;
> ft_sourceplot(cfg, source);
>
>
>
> 2012/6/27 jan-mathijs schoffelen <jan.schoffelen at donders.ru.nl>
>
>> Hi Cornelius,
>>
>> There is no need to 'uninterpolate' because the coordinates are already
>> expressed in the correct coordinate system. What you probably want is to
>> find the index to the voxel in the original source-structure closest to
>> your 'hotspot' in the interpolated image.
>> This can be achieved by something like this:
>>
>> write down the coordinates of your favourite position in the interpolated
>> image (in world coordinates, here I assume that you are still in MEG
>> coordinate system and have not normalized to MNI space), call this pos
>>
>> pos = pos./10 (from mm to cm)
>>
>> dpos = source.pos - repmat(pos, size(source.pos,1),1);
>> [m,ind] = min(sum(dpos.^2,2));
>>
>> source is the original source structure.
>> ind is the index you are looking for.
>>
>> If you have interpolate to the MNI-template grid you need to replace the
>> source.pos with the set of grid positions from your template grid (i.e.
>> expressed in MNI coordinates).
>>
>>
>> Cheers,
>>
>> JM
>>
>>
>> On Jun 27, 2012, at 5:26 PM, cornelius abel wrote:
>>
>> Hello,
>>
>> does anybody know how to get the uninterpolated source position giving
>> the coordinates aquired after interpolation with an anatomy.
>> In principle i want to get an individual source time course at the
>> position i picked from the interpolated grand average source plot. Therfore
>> i need the corresponding filter and its position in the source structure.
>>
>> I tried to get the position by applying the inverse transformation matrix
>> of the used anatomy like:
>> pos_before_interpolation=warp_apply(inv(anatomy.transform),
>> position_after_interpolation);
>>
>> but that did not give usefull results :(
>>
>> Any ideas how it could be done?
>>
>> Greetings, Cornelius
>>
>> _______________________________________________
>> fieldtrip mailing list
>> fieldtrip at donders.ru.nl
>> http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>>
>>
>> Jan-Mathijs Schoffelen, MD PhD
>>
>> Donders Institute for Brain, Cognition and Behaviour,
>> Centre for Cognitive Neuroimaging,
>> Radboud University Nijmegen, The Netherlands
>>
>> Max Planck Institute for Psycholinguistics,
>> Nijmegen, The Netherlands
>>
>> J.Schoffelen at donders.ru.nl
>> Telephone: +31-24-3614793
>>
>>
>> _______________________________________________
>> fieldtrip mailing list
>> fieldtrip at donders.ru.nl
>> http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>>
>
> _______________________________________________
> fieldtrip mailing list
> fieldtrip at donders.ru.nl
> http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>
>
> Jan-Mathijs Schoffelen, MD PhD
>
> Donders Institute for Brain, Cognition and Behaviour,
> Centre for Cognitive Neuroimaging,
> Radboud University Nijmegen, The Netherlands
>
> Max Planck Institute for Psycholinguistics,
> Nijmegen, The Netherlands
>
> J.Schoffelen at donders.ru.nl
> Telephone: +31-24-3614793
>
>
> _______________________________________________
> fieldtrip mailing list
> fieldtrip at donders.ru.nl
> http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20120702/0ec3b9cf/attachment-0001.html>
More information about the fieldtrip
mailing list