<div dir="ltr"><div><div><div>Thanks for shedding light on the issue, JM: I tested your suggestion and it worked brilliantly, far faster and more elegant than the script I wrote years ago. (in my defense, it was only run a couple of times, to label our standard grids...)<br>

<br></div>The old mni2tal question creeps again into the discussion. I would like to use the AFNI atlas, but the conversion introduces too much distortion. For the others (AAL, SPM17/18, Brainweb), all is fine. See attached figure comparing AFNI (blue) with Brainweb grey_matter (red).<br>
<br></div><div>I might get around to add this to the FAQ next week. :-)<br></div><div>
<br></div>Vitória, there is a number of other atlases you can use instead of AFNI then. Either from the link below or any MNI-aligned template, using JM's procedure now it takes 3 seconds to re-label your grid.<br><a href="http://fieldtrip.fcdonders.nl/template/atlas">http://fieldtrip.fcdonders.nl/template/atlas</a><br>
<br></div>Best,<br>Erick<br><div><div><br></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Mar 13, 2014 at 1:00 PM, jan-mathijs schoffelen <span dir="ltr"><<a href="mailto:jan.schoffelen@donders.ru.nl" target="_blank">jan.schoffelen@donders.ru.nl</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Hi Vitória, Erick, Cornelius et al,<div><br></div><div>Allow me to chime in to this Brazilio-German interaction ;-). </div>
<div>It seems to me that the discussion consists of a few separable elements.</div><div><br></div><div>-The first one pertains to the specific question how to map source locations between two different representations (source with pos versus volumetric MRI-type image with a transform). </div>
<div>-The other one relates to some atlas related business, i.e. mapping locations that have a specific anatomical label to specific MEG source space locations.</div><div>-And then there's a third one, which is important for 2, and pertains to the usual complicated stuff of mapping between different coordinate systems.</div>
<div><br></div><div>There are several ways to achieve what Vitória is looking for, and I think that Erick already solved it, but recent changes in FieldTrip make it quite straightforward.</div><div><br></div><div>So here goes my recipe:</div>
<div>1 I would go along with Erick to do my beamformer source reconstruction on a subject-specific grid, which is inverse-warped from a regular grid defined on the MNI-template.</div><div>2 If we take this template grid, which can be found in ~/fieldtrip/template/sourcemodel, you can interpolate the atlas of your choice onto this sourcemodel, using ft_sourceinterpolate. Reading in of the atlas nowadays indeed should be done with ft_read_atlas (ft_prepare_atlas will be deprecated soon), and my personal taste would be NOT to use the afni atlas, because this one is defined in Talairach space, which is slightly different from MNI-space, and although FT accounts for the differences I am not sure how accurate this is. Anyway, one could do something like atlas = ft_read_atlas('~/fieldtrip/template/atlas/....'), load the template sourcemodel with the resolution you need (i.e. the resolution you used in your beamformer grid), and call ft_sourceinterpolate: cfg = []; cfg.interpmethod = 'nearest'; cfg.parameter = 'tissue'; sourcemodel2 = ft_sourceinterpolate(cfg,atlas,sourcemodel); % NOTE: ensure that the units are consistent in atlas and sourcemodel, if not use ft_convert_units</div>
<div>3 Step 2 should have given you sourcemodel2 with a field 'tissue', that represents the anatomical labels, according to the corresponding atlas. Atlas.tissuelabel gives the labels that correspond to the numbers in the tissue field.</div>
<div>4 Then, without the need to call ft_sourceinterpolate, nor ft_volumenormalise on your source-reconstructed data, you can do indx = find(sourcemodel2.tissue==x), where x is the number of your choice, and you directly get the indices of the source positions in your 'source' variable, that have this particular anatomical label.</div>
<div>5 Then, you can do whatever you like with it, e.g. take a max or mean or whatever...</div><div><br></div><div>I hope I was clear enough, and that someone feels inclined to make this into a FAQ on the FieldTrip wiki ;-).</div>
<div><br></div><div>Best wishes,</div><div>Jan-Mathijs</div><div><br></div><div><br></div><div><div><div class="h5"><br><div><div>On Mar 12, 2014, at 5:50 PM, Vitoria Piai wrote:</div><br><blockquote type="cite">
  
    
  
  <div bgcolor="#FFFFFF" text="#000000">
    <div>Dear Erick, <br>
      <br>
      "simply label and/or define my ROI in the MNI grid. When I warp to
      the individuals, everything is in place without a hitch" ->
      that sounds like a good thing to do. <br>
      Is this a very complicated thing to do? Would you mind sharing a
      piece of code or some tips for how I could achieve it?<br>
      <br>
      Thanks once more, Vitória<br>
      <br>
      On 3/12/2014 11:37 AM, Erick Ortiz wrote:<br>
    </div>
    <blockquote type="cite">
      <div dir="ltr">
        <div>
          <div>
            <div>Dear Vitoria,<br>
              <br>
            </div>
            <div>What I do usually, is to simply label and/or define my
              ROI in the MNI grid. When I warp to the individuals,
              everything is in place without a hitch.<br>
            </div>
            <div>
              <br>
            </div>
            About the interpolation, I cannot help much more. I have
            been using my own tools for years, and I was not following
            the support of atlases in Fieldtrip.I tried it today, but
            had issues with coordinate system labeling when defining a
            ROI (I updated to the latest version by SVN):<br>
            <br>
            afni =
            ft_read_atlas('template/atlas/afni/TTatlas+tlrc.HEAD');<br>
            cfg              = [];<br>
            cfg.method       = 'ortho';<br>
            cfg.interactive  = 'yes';<br>
            cfg.funparameter = 'coh';<br>
            cfg.atlas        = afni;<br>
            cfg.coordsys     = 'mni';<br>
            % cfg.roi          = 'Middle Temporal Gyrus';<br>
            % cfg.inputcoord   = 'tal';<br>
            ft_sourceplot(cfg, interp);<br>
            <br>
            Also note that I had to use ft_read_atlas, because
            ft_prepare_atlas does not generate the
            brick0label/brick1label fields.<br>
            <br>
          </div>
          It works well, but if I try to define a ROI (uncommenting the
          two lines), I get the error "The field cfg.inputcoord is
          required". There seems to be some confusion between inputcoord
          and coordsys.<br>
          <br>
          It can be because I was doing something wrong: maybe a
          Fieldtrip developer could comment on that?<br>
          <br>
        </div>
        <div>Best,<br>
          Erick<br>
        </div>
        <div>
          <div><br>
          </div>
        </div>
      </div>
      <div class="gmail_extra"><br>
        <br>
        <div class="gmail_quote">
          On Wed, Mar 12, 2014 at 9:24 AM, Vitoria Piai <span dir="ltr"><<a href="mailto:v.piai.research@gmail.com" target="_blank">v.piai.research@gmail.com</a>></span>
          wrote:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div bgcolor="#FFFFFF" text="#000000">
              <div>Dear Erick, <br>
                <br>
                Thanks for your detailed reply.<br>
                I've been using individual MNI-warped grids (point 4
                below) and I'm always using ft_convert_unit so those
                points are alright in my data.<br>
                <br>
                The reason why I do need to interpolate (at least, I
                think I need), is because I'm looking for max 'pow' in
                anatomically defined regions given the afni atlas. I
                managed to get it to work by interpolating to the mri
                and looking for max 'pow' given a label (e.g., 'Middle
                Temporal Gyrus') using ft_volumelookup. <br>
                Do you have any experience with this approach (searching
                within anatomical labels) without having to interpolate?<br>
                <br>
                Thanks once more, Vitória
                <div>
                  <div><br>
                    <br>
                    <br>
                    <br>
                    On 3/11/2014 6:35 PM, Erick Ortiz wrote:<br>
                  </div>
                </div>
              </div>
              <div>
                <div>
                  <blockquote type="cite">
                    <div dir="ltr">Dear Vitória and Cornelius,<br>
                      <br>
                      this is a common problem, and maybe it would be
                      good to clarify the strategies that can be used
                      here. I hope this can help others in a similar
                      situation, which I have found many times.<br>
                      <br>
                      1) You are trying to convert voxel indexes to head
                      (CTF) coordinates. In this case, there are two
                      mistakes in the code:<br>
                      1a) pos = warp_apply( pinv( sourceNAIInt.transform
                      ), posInt, 'homogeneous' );<br>
                      ... should be done with sourceNAIInt, not mri. The
                      transforms are different, in general; e.g. note
                      the downsample=2.<br>
                      1b) use cfg.locationcoordinates = 'head', as
                      commented by JM in a previous post. Or remove this
                      line, since 'head' is the default.<br>
                      <br>
                      2) But if you are working with the same
                      subject/grid, there is no need for interpolation
                      at all. Simply find the grid position with highest
                      'pow' and take its position.<br>
                          [dummy,ind] = max(source.avg.pow);<br>
                          pos = source.pos(ind,:);<br>
                      <br>
                      3) However, this is not possible when using
                      different grids, e.g. in a grand average in MNI
                      coordinates. Find the peak ('pos') in the
                      interpolated volume, as in Cornelius' code, then
                      find the index of the nearest grid position for a
                      common (again, MNI) grid. This is also in JM's
                      message.<br>
                      <br>
                      dpos = source.pos - repmat( pos,
                      size(source.pos,1), 1 );<br>
                      [dummy,ind] = min(sum(dpos.^2,2));<br>
                      <br>
                      4) What I have been using, and strongly recommend,
                      is an MNI grid warped to the subject's anatomy,
                      according to this procedure:<br>
                      <a href="http://fieldtrip.fcdonders.nl/example/create_single-subject_grids_in_individual_head_space_that_are_all_aligned_in_mni_space" target="_blank">http://fieldtrip.fcdonders.nl/example/create_single-subject_grids_in_individual_head_space_that_are_all_aligned_in_mni_space</a><br>

                      <br>
                      This would give you both the benefits of working
                      in MNI coordinates, and the ease of having a
                      common grid across subjects (for instance,
                      enabling solution #2). Still, some projects do
                      call for one of the other options.<br>
                      <br>
                      Just a couple of details:<br>
                      - Pay utmost attention to coordinate systems and
                      units. For instance, it is common to confuse
                      unlabeled cm for mm, and either of these with
                      voxels. Try to also label all structures as CTF or
                      SPM (MNI).<br>
                      - Using pinv instead of inv is usually a good
                      idea. Here, it is a not an issue, but matrix
                      inversion in MATLAB can lead to a world of hurt to
                      the unwary.<br>
                      <br>
                      Best,<br>
                      Erick<br>
                      <br>
                    </div>
                    <div class="gmail_extra"><br>
                      <br>
                      <div class="gmail_quote">On Tue, Mar 11, 2014 at
                        4:04 PM, Vitoria Piai <span dir="ltr"><<a href="mailto:v.piai.research@gmail.com" target="_blank">v.piai.research@gmail.com</a>></span>
                        wrote:<br>
                        <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
                          <div bgcolor="#FFFFFF" text="#000000"> Dear
                            FT-ers, <br>
                            <br>
                            I found an old posting to the mailing list
                            (see below) that never got answered so my
                            question still holds: given a location I
                            found in the interpolated source, how do I
                            find back the same location in .pos of the
                            non-interpolated data?<br>
                            I can try and go around it by finding the
                            corresponding MNI coordinates in the
                            interpolated data (which by now I have to do
                            by hand, so not optimal anyways), and then
                            look for those coordinates in .pos. But I
                            was wondering, like Cornelius was in his
                            post, whether there is a neater way to get
                            this information.<br>
                            <br>
                            Thanks a lot for the help, <br>
                            Vitória<br>
                            <br>
                            <br>
                            <div>
                              <div class="gmail_extra">
                                <div class="gmail_quote">
                                  <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
                                    <div>
                                      <div>
                                        >>>>>>>>>>>>>><br>
                                        <br>
                                        Hi mailing list,<br>
                                        <br>
                                        I'm still struggling with the
                                        conversion of coordinates
                                        between source and<br>
                                        interpolated source space.<br>
                                        For example, if i have the
                                        position of a single grid point
                                        how do i get the<br>
                                        corresponding voxel  in the
                                        interpolated source structure.
                                        Or the other way<br>
                                        around, how to get the grid
                                        point which corresponds to a
                                        voxel (e.g the max<br>
                                        voxel) in the interpolated
                                        source structure.<br>
                                        <br>
                                        I think this should be a common
                                        problem when working with
                                        virtual<br>
                                        electrodes, shouldn't it?<br>
                                        <br>
                                        To make things easier i put
                                        together a example with the data
                                        from the<br>
                                        source tutorial where i tried to
                                        calculated the grid pos of the
                                        max voxel<br>
                                        in the interpolated source.<br>
                                        <br>
                                        clear all;<br>
                                        load sourcePost_nocon;          
                                            % source structure from
                                        tutorial<br>
                                        mri =
                                        ft_read_mri('Subject01.mri');  %
                                        mri of subject01 from tutorial<br>
                                        <br>
                                        sourceNAI = sourcePost_nocon;<br>
                                        sourceNAI.avg.pow =
                                        sourcePost_nocon.avg.pow ./
                                        sourcePost_nocon.avg.noise;<br>
                                        sourceNAI=rmfield(sourceNAI,'freq');
                                        % had to remove that to let<br>
                                        <br>
                                        cfg = [];<br>
                                        cfg.downsample = 2;<br>
                                        cfg.parameter = 'avg.pow';<br>
                                        sourceNAIInt =
                                        ft_sourceinterpolate(cfg,
                                        sourceNAI , mri);<br>
                                        <br>
                                        % Find position of max activity<br>
                                        [dum, maxindx] =
                                        max(sourceNAIInt.avg.pow(:));<br>
                                        [xi, yi, zi] =
                                        ind2sub(sourceNAIInt.dim,
                                        maxindx);<br>
                                        posInt=[xi, yi, zi];<br>
                                        <br>
                                        % Plot interpolated source with
                                        position of max activity<br>
                                        cfg              = [];<br>
                                        cfg.method       = 'ortho';<br>
                                        cfg.funparameter = 'avg.pow';<br>
                                        cfg.locationcoordinates =
                                        'voxel';<br>
                                        cfg.location      = posInt;    
                                             % location of max activity
                                        is marked<br>
                                        correctly.<br>
                                        figure;<br>
                                        ft_sourceplot(cfg,sourceNAIInt);<br>
                                        <br>
                                        % Transform coordinate back to
                                        uninterpolated source???<br>
                                        dpos =
                                        warp_apply(inv(mri.transform),
                                        posInt, 'homogeneous');<br>
                                        <br>
                                        <br>
                                        % Plot uninterpolated source
                                        with position aquired from
                                        interpolated source<br>
                                        cfg              = [];<br>
                                        cfg.method       = 'ortho';<br>
                                        cfg.funparameter = 'avg.pow';<br>
                                        cfg.locationcoordinates =
                                        'voxel';<br>
                                        cfg.location      = dpos;      
                                                % unfortunately this
                                        coordinate is<br>
                                        obviously wrong!!! WHY?<br>
                                        figure;<br>
                                        ft_sourceplot(cfg,sourceNAI);<br>
                                        <br>
                                        <br>
                                        Unfortunately the solution of
                                        Jan Mathijs did not work, nor
                                        did mine :(<br>
                                        <br>
                                        Any ideas???<br>
                                        <br>
                                        Cornelius<br>
                                        <br>
                                        <br>
                                      </div>
                                    </div>
                                  </blockquote>
                                </div>
                                <br>
                              </div>
                              <br>
                            </div>
                            <br>
                          </div>
                          <br>
_______________________________________________<br>
                          fieldtrip mailing list<br>
                          <a href="mailto:fieldtrip@donders.ru.nl" target="_blank">fieldtrip@donders.ru.nl</a><br>
                          <a href="http://mailman.science.ru.nl/mailman/listinfo/fieldtrip" target="_blank">http://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br>
                        </blockquote>
                      </div>
                      <br>
                    </div>
                    <br>
                    <fieldset></fieldset>
                    <br>
                    <pre>_______________________________________________
fieldtrip mailing list
<a href="mailto:fieldtrip@donders.ru.nl" target="_blank">fieldtrip@donders.ru.nl</a>
<a href="http://mailman.science.ru.nl/mailman/listinfo/fieldtrip" target="_blank">http://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a></pre>
                  </blockquote>
                  <br>
                </div>
              </div>
            </div>
            <br>
            _______________________________________________<br>
            fieldtrip mailing list<br>
            <a href="mailto:fieldtrip@donders.ru.nl" target="_blank">fieldtrip@donders.ru.nl</a><br>
            <a href="http://mailman.science.ru.nl/mailman/listinfo/fieldtrip" target="_blank">http://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br>
          </blockquote>
        </div>
        <br>
      </div>
      <br>
      <fieldset></fieldset>
      <br>
      <pre>_______________________________________________
fieldtrip mailing list
<a href="mailto:fieldtrip@donders.ru.nl" target="_blank">fieldtrip@donders.ru.nl</a>
<a href="http://mailman.science.ru.nl/mailman/listinfo/fieldtrip" target="_blank">http://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a></pre>
    </blockquote>
    <br>
  </div>

_______________________________________________<br>fieldtrip mailing list<br><a href="mailto:fieldtrip@donders.ru.nl" target="_blank">fieldtrip@donders.ru.nl</a><br><a href="http://mailman.science.ru.nl/mailman/listinfo/fieldtrip" target="_blank">http://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a></blockquote>
</div><br></div></div><div>
<span style="text-indent:0px;letter-spacing:normal;font-variant:normal;text-align:-webkit-auto;font-style:normal;font-weight:normal;line-height:normal;border-collapse:separate;text-transform:none;font-size:medium;white-space:normal;font-family:Helvetica;word-spacing:0px"><span style="text-indent:0px;letter-spacing:normal;font-variant:normal;text-align:-webkit-auto;font-style:normal;font-weight:normal;line-height:normal;border-collapse:separate;text-transform:none;font-size:medium;white-space:normal;font-family:Helvetica;word-spacing:0px"><div style="word-wrap:break-word">
<span style="text-indent:0px;letter-spacing:normal;font-variant:normal;text-align:-webkit-auto;font-style:normal;font-weight:normal;line-height:normal;border-collapse:separate;text-transform:none;font-size:medium;white-space:normal;font-family:Helvetica;word-spacing:0px"><div style="word-wrap:break-word">
<span style="text-indent:0px;letter-spacing:normal;font-variant:normal;text-align:-webkit-auto;font-style:normal;font-weight:normal;line-height:normal;border-collapse:separate;text-transform:none;font-size:medium;white-space:normal;font-family:Helvetica;word-spacing:0px"><div style="word-wrap:break-word">
<span style="text-indent:0px;letter-spacing:normal;font-variant:normal;text-align:-webkit-auto;font-style:normal;font-weight:normal;line-height:normal;border-collapse:separate;text-transform:none;font-size:medium;white-space:normal;font-family:Helvetica;word-spacing:0px"><div style="word-wrap:break-word">
<span style="text-indent:0px;letter-spacing:normal;font-variant:normal;text-align:-webkit-auto;font-style:normal;font-weight:normal;line-height:normal;border-collapse:separate;text-transform:none;font-size:medium;white-space:normal;font-family:Helvetica;word-spacing:0px"><div style="word-wrap:break-word">
<span style="text-indent:0px;letter-spacing:normal;font-variant:normal;font-style:normal;font-weight:normal;line-height:normal;border-collapse:separate;text-transform:none;font-size:medium;white-space:normal;font-family:Helvetica;word-spacing:0px"><div style="word-wrap:break-word">
<span style="text-indent:0px;letter-spacing:normal;font-variant:normal;font-style:normal;font-weight:normal;line-height:normal;border-collapse:separate;text-transform:none;font-size:medium;white-space:normal;font-family:Helvetica;word-spacing:0px"><div style="word-wrap:break-word">
<span style="text-indent:0px;letter-spacing:normal;font-variant:normal;font-style:normal;font-weight:normal;line-height:normal;border-collapse:separate;text-transform:none;font-size:medium;white-space:normal;font-family:Helvetica;word-spacing:0px"><div style="word-wrap:break-word">
<div>Jan-Mathijs Schoffelen, MD PhD </div><div><br></div><div>Donders Institute for Brain, Cognition and Behaviour, <br>Centre for Cognitive Neuroimaging,<br>Radboud University Nijmegen, The Netherlands</div><div><br></div>
<div>Max Planck Institute for Psycholinguistics,</div><div>Nijmegen, The Netherlands</div><div><br></div><div><a href="mailto:J.Schoffelen@donders.ru.nl" target="_blank">J.Schoffelen@donders.ru.nl</a></div><div>Telephone: <a href="tel:%2B31-24-3614793" value="+31243614793" target="_blank">+31-24-3614793</a></div>
<div><br></div><div><a href="http://www.hettaligebrein.nl" target="_blank">http://www.hettaligebrein.nl</a></div></div></span></div></span></div></span></div></span></div></span></div></span></div></span></div></span></span>
</div>
<br></div></div><br>_______________________________________________<br>
fieldtrip mailing list<br>
<a href="mailto:fieldtrip@donders.ru.nl">fieldtrip@donders.ru.nl</a><br>
<a href="http://mailman.science.ru.nl/mailman/listinfo/fieldtrip" target="_blank">http://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br></blockquote></div><br></div>