aparc+aseg to MNI

We are trying to transform aparc+aseg+orig to MNI space, and for some reason nothing is working well.
We tried 3dAllineate, 3dNwarpApply, 3dQwarp, adwarp and with freesurfer - mri_label2vol.
Nothing worked and when looking on the volumes in MNI it is just not aligned to the anat volumes.

Are we missing something?
What is the correct way to do this?

Thank you!

Hi Maya-

I generally haven’t had any trouble getting it into MNI space. Can you post what commands you’ve tried (the actual syntax)? That’ll help us debug here.


Hi, Maya-

You would create the transformation from subject anatomical (what you input to FreeSurfer, or the SurfVol.nii* dset in the output SUMA/ directory after running recon-all and @SUMA_Make_Spec_FS) to your template dataset, and then you can apply that transform to the aparc+aseg or any other dataset that in the subject anatomical space. For nonlinear warping of human T1w anatomical volumes to a template, we would generally recommend using @SSwarper for both skullstripping (SS) and nonlinear warp estimation—there is a specific version of hte MNI 2009c template that is a reference base for @SSwarper: MNI152_2009_template_SSW.nii.gz.

If you are using afni_proc.py, this is even easier, because you can include any of hte recon-all output atlases as “follower ROI” dsets, and those will end up in your final space, either on the same grid with your final anatomical dset or with your final EPI dset. This is demo’ed in this afni_proc.py example:
… with these options specifically, where the first one puts the aparc*nii file on the final “anat” grid, and the second puts the same dset on the final “epi” grid:

-anat_follower_ROI aaseg anat aparc.a2009s+aseg.nii       \
-anat_follower_ROI aeseg epi aparc.a2009s+aseg.nii        \

That example also shows how to include FS output volumes (ventricles and WM) that might be of interest for, say, ANATICOR, even with erosion of them (so they are muuuuch less likely to overlap GM, which would be bad)

-anat_follower_ROI FSvent epi fs_ap_latvent.nii.gz        \
        -anat_follower_ROI FSWe epi fs_ap_wm.nii.gz               \
        -anat_follower_erode FSvent FSWe                          \

We also have FreeSurfer output from running on the MNI template itself, so the ROIs are all there in MNI space, and would just have to be regridded to your final “applied” dataset, if that is your goal:


… though I notice this is a wee bit old from @SUMA_Make_Spec_FS output, and some of the extra-convenient files from @SUMA_Make_Spec_FS might not be present (like the specifically ROI-like GM and the FS* tissue maps), though most of the nicer "REN* versions of the aparc* and aseg* files are there.


Thank you for your answer.
I am using

@SSwarper -input $subject.$session.anat+orig.BRIK -base /Users/ramotlab/abin/MNI152_2009_template_SSW.nii.gz -subid $subject.$session.$scan.SE

and afterward the proc.py commands including anat_follower_ROI.
The problem is that I am trying to get a gray matter mask in MNI (cortex+subregions) extracted from freesurfer parcellation aparc+aseg and the transformation is not going well.
I tried:
to create the gray matter mask:

mri_binarize --i aparc+aseg.s1.mgz --gm --o GMmask.s1.mgz

to convert the mgz file to nii:

mri_convert GMmask.s1.mgz GMmask.s1.nii

to transform grom nii to afni format:

3dcopy GMmask.s1.nii GMmask.s1.use

to use the transformation matrix from @SSwarper conducted for proc.py to transform the mask to MNI:

3dNwarpApply -nwarp 'anatQQ.sub1.s1.movie1.SE_WARP.nii anatQQ.sub1.s1.movie1.SE.aff12.1D' -source GMmask.s1.use+orig

It comes out in orig and with no alignment to the anat data.

Hi, Maya-

After running FreeSurfer’s recon-all, do you run AFNI’s @SUMA_Make_Spec_FS? That should provide most of the dsets you would want in NIFTI (and/or GIFTI) format, with some nice properties, too. Some description of running @SUMA_Make_Spec_FS after recon-all is given here:

Some of the convenient outputs are provided here:
The REN files are particularly nice: they are renumbered+labeltabled FreeSurfer segmentation maps (both the aparc+aseg and aparc2009 varieties). When opened in AFNI, they have ROI-like colorbars. There are several useful ones, including all the FS ROIs in one dset, but “families” that are convenient. Myself, I really like having the “ROI-like” GM as a single file, REN_gmrois (FS has both GM ROIs and GM “dots” that are left over in the GM map). I recently had some afni_proc.py commands and I defined the following dsets of interest (the full parcellation and GM-ROI-like parcellation subset, for both of FS’s output atlases):

set roi_all_2000 = ${sdir_suma}/aparc+aseg_REN_all.nii.gz
set roi_gmr_2000 = ${sdir_suma}/aparc+aseg_REN_gmrois.nii.gz
set roi_all_2009 = ${sdir_suma}/aparc.a2009s+aseg_REN_all.nii.gz
set roi_gmr_2009 = ${sdir_suma}/aparc.a2009s+aseg_REN_gmrois.nii.gz

… and then included the following anat followers in my afni_proc.py (AP) command:

    -anat_follower_ROI        a09all anat ${roi_all_2009}                    \
    -anat_follower_ROI        e09all epi  ${roi_all_2009}                    \ 
    -anat_follower_ROI        a09gmr anat ${roi_gmr_2009}                    \ 
    -anat_follower_ROI        e09gmr epi  ${roi_gmr_2009}                    \ 
    -anat_follower_ROI        a00all anat ${roi_all_2000}                    \ 
    -anat_follower_ROI        e00all epi  ${roi_all_2000}                    \ 
    -anat_follower_ROI        a00gmr anat ${roi_gmr_2000}                    \ 
    -anat_follower_ROI        e00gmr epi  ${roi_gmr_2000}                    \

… where “a09all …” is the dset of “all” aparc20"09" ROIs output on the final "a"natomical grid, etc.

You might want to define:

set roi_gm_2000 = ${sdir_suma}/aparc+aseg_REN_gm.nii.gz

… and then include this in your AP command:

    -anat_follower_ROI        a00gm anat ${roi_gm_2000}                    \ 
    -anat_follower_ROI        e00gm epi  ${roi_gm_2000}                    \

You can always “binarize” the output dset with:

3dcalc -a DSET -expr 'bool(a)' -prefix DSET_BINARIZED

… which maps every nonzero value in DSET to 1, leaving everything else 0. (But from the anat follower command, you should have the labels still attached in the mapped parcellation, which is a recent update in AFNI.)


And, on the perhaps separate topic of applying @SSwarper’s transformation pieces here, you first have (**though, note, I still think using the follower_ROI options with afni_proc.py is a better way to map these ROIs—see my parallel posting):

3dNwarpApply                                                                 \
    -nwarp   'anatQQ.sub1.s1.movie1.SE_WARP.nii anatQQ.sub1.s1.movie1.SE.aff12.1D' \
    -source  GMmask.s1.use+orig

… and that would indeed, be in the same “+orig” view as the input dset, because nothing is telling it to change.

This command adds a few options that will help you:

3dNwarpApply                                                                 \
    -nwarp   'anatQQ.sub1.s1.movie1.SE_WARP.nii anatQQ.sub1.s1.movie1.SE.aff12.1D' \
    -source  GMmask.s1.use+orig       \
    -master /Users/ramotlab/abin/MNI152_2009_template_SSW.nii.gz     \
    -ainterp NN \
    -prefix GMmask.s1.use_in_MNI.nii.gz 


  • “-master …” tells the program what output grid+space to use, which will be MNI here—so your final dset would be on the grid of the MNI template specifically, and it would have “+tlrc” viewing (even with the NIFTI file format I output with here). Though, perhaps you would want to use
    -master SOME_PATH/anatQQ.sub1.s1.movie1.SE.nii
    … to have the ROIs on the grid of your final anatomical dset, or even:
    -master SOME_PATH/errts_*HEAD
    … to have it the ROIs on the grid of your final residuals/EPI dset.

  • “-ainterp NN” means to use nearest neighbor (NN) interpolation when mapping the source dset to the output; this will preserve integer values, rather than blurring them, losing hte ROI-ness.

  • “-prefix …” to specify a desired output dset name.

For AFNI-created ROI dsets that have labeltables in them (like the REN_ ones mentioned in the parallel post in this thread), you can also re-attach the nice properties of telling the GUI to use an ROI-like colorbar when opening the file as an overlay:

3drefit -cmap INT_CMAP DSET_WARPED

… as well as re-attach the labeltable from the original that had one:

3drefit -copytables DSET_ORIG   DSET_WARPED

This latter one only applies if the original dset did have a labeltable or atlaspoints, which you can query with:

3dinfo -is_atlas_or_labeltable DSET_ORIG


It it working great with both aparc+aseg and the REN files!
Thank you!