Converting Atlas Space

I am trying to convert the space, orientation and resolution of a single niimg atlas file based on the space, orientation and resolution a template niimg.

For my purposes (reconstruction with qsirecon), atlases must be in the MNI152NLin2009cAsym space, have a resolution of 1 x 1 x 1mm and be oriented to LPS+ (QSIPrep docs). I have the Craddock atlas in “MNI152” space; however, the resolution of the atlas image is 4 x 4 x 4mm, and is oriented to RAS.

I attempted to reregister the atlas to the desired space using FLIRT, with the following command:

flirt -in craddock.nii.gz -ref mni_1mm_t1w_lps.nii.gz -out craddock_lps

The header as inspected with fslhd looks good, the correct orientation and resolution is displayed; however, when inspecting the output atlas with fslview the result is clearly wrong.

I have searched around a lot for help reregistering atlases to templates but there is very little information anywhere about it. It’s mostly about reregistering subjects to the same space that an atlas is in which is not an option in this case.

Is there an obvious step I’m missing or am I just doing it wrong? Any help would be greatly appreciated.

Many thanks,
Rory

flirt may be overkill here if you already have the image in MNI space. I would suggest using 3dresample from AFNI. See here AFNI program: 3dresample and here Frequently Asked Questions — Andy's Brain Book 1.0 documentation

So your line of code may be something like 3dresample -input craddock.nii.gz -master mni_1mm_t1w_lps.nii.gz -prefix craddock_lps.nii.gz -orient LPS

Hope this can help you out!
Steven

Adding on to Steven’s useful response, if your atlas data is already in the desired template space, then you don’t have to do alignment; you only need to resample the dataset. If you still want to align, then generally one does not align an “atlas” with segmentation, labels,… to a template. Alignment software typically relies on somewhat similar data in both datasets aligned - T1 to T1 template, for instance. The atlases are usually created on a particular template. (We are working on a general list of these correspondences). Instead of computing alignment between the atlas and a template, one can compute a spatial transformation between the underlying template (the template space in AFNI-speak) and the desired template using alignment tools.

A variety of tools that do affine and nonlinear alignment can do that job - AFNI’s auto_warp.py, 3dAllineate, 3dQwarp, align_epi_anat.py, FSL flirt, fnirt, ANTs,… TemplateFlow, RheMap keep sets of these for specific templates.

Some more comments on this - AFNI’s orientation codes are not necessarily the same as the other software. In AFNI, for instance, RAI means data is stored to Right to left along columns, Anterior to posterior along rows and Inferior to superior across slices. The opposite is true in Freesurfer and FSL where the same storage order would be called LPS. You will need to account for that in your desired output.

Also the “MNI” space represents correspondence to a variety of templates over its relatively long history (MNI-152, ICBM-452, MNI-305, MNI-N27, MNI-2009a,b,c symmetric/asymmetric- 1mm,2mm, MNI-Mai,…). The MNI-2009c asymmetric template is one of these choices, and one that AFNI commonly supports, but FSL generally uses the 2006 nonlinear version. While they are similar, they are not exactly the same. You can get around this somewhat by alignment.

1 Like

Many thanks to you both, I will take a look into your suggestions.

@dglen,

For clarity, do you mean that I can flirt the underlying template for the Craddock atlas against the desired space, save the underlying transformation and apply that transformation afterwards to the atlas. Something like the following in FSL?

flirt -in {craddock_template} -ref mni_1mm_t1w_lps.nii.gz -omat affine.mat
flirt -in craddock.nii.gz -ref mni_1mm_t1w_lps.nii.gz -applyxfm -init affine.mat -out craddockMNI_lps.nii.gz

I’m not actually certain which space the craddock atlas is in… Would the atlas and the template space have the exact same resolution?

Many thanks,
Rory

If the low resolution atlas is correctly aligned to the high resolution image, you should be able to simply reslice the data to match. The only caveat is that you must make sure to use nearest neighbor interpolation to deal with partial volume effects. In other words, an output voxel that contains portions of area 18 and area 20 of the input data should not be assigned the label 19. Here is a sample Matlab/SPM script that reslices images. You would want to make sure that the interp argument is zero (for nearest neighbor).

https://github.com/rordenlab/spmScripts/blob/master/nii_reslice_target.m

I do think FLIRT will have a hard time working out a cost function, as the atlas indices are not scalar intentensities that map on to the values of a T1 scan. Have you considered another atlas, e.g. AICHA, Harvard-Oxford, etc?

Yes, I think that looks about right, but I know little about FSL’s implementation. I would think that, if it’s like AFNI’s, the grid does not have to match in voxel size or extent.