Transforming freesurfer segmentation labels into MNI space

Hi — I’m looking to check if this is a reasonable approach or if something else is preferable. I used to segment the hippocampus, which produces segmentation labels ([l|r]h.hippoAmygLabels-T1.v21.mgz), which I’d like to use as roi in MNI space.

I used mri_label2vol to convert these into volumetric labels in the same space (although I couldn’t use the --identity flag, but rather had to use --regheader lh.hippoAmygLabels-T1.v21.mgz, which hopefully isn’t an issue):

mri_label2vol \
--regheader derivatives/freesurfer/sub-001/mri/lh.hippoAmygLabels-T1.v21.mgz \
--seg derivatives/freesurfer/sub-001/mri/lh.hippoAmygLabels-T1.v21.mgz \
--temp derivatives/freesurfer/sub-001/mri/orig.mgz \
--o derivatives/roi/sub-001/sub-001_space-fsorig_desc-hippo_roi.nii.gz

Then I used antsApplyTransforms and the _from-fsnative_to-T1w_mode-image_xfm.txt and _from-T1w_to-MNI152NLin2009cAsym_mode-image_xfm.h5 transformations generated by fmriprep to produce the MNI segmentation:

singularity exec -B derivatives:/derivatives fmriprep-20_2_1.simg \
antsApplyTransforms -d 3 --float 1 --interpolation MultiLabel --verbose 1 \
-i /derivatives/roi/sub-001/sub-001_space-fsorig_desc-hippo_roi.nii.gz \
-r /derivatives/fmriprep/sub-001/anat/sub-001_space-MNI152NLin2009cAsym_desc-preproc_T1w.nii.gz \
-t /derivatives/fmriprep/sub-001/anat/sub-001_from-fsnative_to-T1w_mode-image_xfm.txt \
-t /derivatives/fmriprep/sub-001/anat/sub-001_from-T1w_to-MNI152NLin2009cAsym_mode-image_xfm.h5 \
-o /derivatives/roi/sub-001/sub-001_space-MNI152NLin2009cAsym_desc-hippo_roi.nii.gz

So I want to check – does this make sense? Would something else be better?

I had initially looked at init_segs_to_native_wf() and opted to bring the .mgz labels into T1w space by using rawavg.mgz as the template for mri_label2vol, followed by replacing with mri_convert (then converting from T1w to MNI with ANTs). The two approaches (the first using xfm.txt and the second using rawavg.mgz) yield different results, but both look reasonable, so I wanted to check what’s the preferred way to bring labels from free surfer orig space to MNI space.

Thanks!! I appreciate your feedback.

And in case it’s useful to someone else, I had a rough time getting antsApplyTransforms to work with the .h5 files. The errors differed depending on the version of ANTs and the env, but might look something like the one below. I had to use the ANTs packaged in the fmriprep container for the transformation to run.

HDF5-DIAG: Error detected in HDF5 (1.8.7) thread 0:
  #000: /om/user/satra/software_builds/build/ITKv4/Modules/ThirdParty/HDF5/src/itkhdf5/src/H5D.c line 334 in H5Dopen2(): not found
    major: Dataset
    minor: Object not found
  #001: /om/user/satra/software_builds/build/ITKv4/Modules/ThirdParty/HDF5/src/itkhdf5/src/H5Gloc.c line 430 in H5G_loc_find(): can't find object
    major: Symbol table
    minor: Object not found
Transform reader for derivatives/fmriprep/sub-001/anat/sub-001_from-T1w_to-MNI152NLin2009cAsym_mode-image_xfm.h5 caught an ITK exception:

itk::ExceptionObject (0x30fed00)
Location: "unknown"
File: /om/user/satra/software_builds/build/ITKv4/Modules/IO/TransformHDF5/include/itkHDF5TransformIO.hxx
Line: 283
Description: itk::ERROR: HDF5TransformIOTemplate(0x2f62590): H5Dopen2 failed

Can't read initial transform derivatives/fmriprep/sub-001/anat/sub-001_from-T1w_to-MNI152NLin2009cAsym_mode-image_xfm.h5

Hi, I also want to use FS subfield segmentation as ROIs…
I am wondering how it goes.

Hi you could use FSL-fslmaths with the -thr and -uthr parameters. The thresholds you would use normally equal to the index in the FS segmentation.

More details on this page: