FreeSurface Surface Registration Error

Summary of what happened:

I’m working on a project where I need to align an existing FreeSurfer segmentation (from an older T1 image) with a the same T1 image of the same subject, but it is debiased and in a different atlas space. The goal is to leverage the manual edits and refinements made in the original FreeSurfer output while utilizing the improved image quality of the new T1 scan.

Current approach:

  1. Using mri_robust_register to align the old FreeSurfer T1 to the new T1 image
  2. Applying the resulting transformation to all FreeSurfer volumes (mri/*.mgz files)
  3. Transforming the surface files using mri_surf2surf

Main Issue: After applying our current approach, we’ve noticed that while the volume files (mri/.mgz) seem to align well with the new T1 image, the surface files (surf/.pial, surf/*.white, etc.) are not aligning properly or just don’t open with freeview.

Command used (and if a helper script was used, a link to the helper script or the command generated):

# Set up variables
set FSdir = "/FreeSurfer"
set structid = "subject1"
set T1_IMAGE = "${structid}/T1/${structid}_T1w_1_debias.nii.gz"

# Set up directories
set EXISTING_FS_DIR = "FS73/${structid}"
set NEW_FS_DIR = "${FSdir}/${structid}_registered"
set TEMP_DIR = "${FSdir}/${structid}_temp"

# Set SUBJECTS_DIR for FreeSurfer
setenv SUBJECTS_DIR ${FSdir}
echo "SUBJECTS_DIR set to: $SUBJECTS_DIR"

# Create temporary and new directories
mkdir -p ${TEMP_DIR}/transforms ${NEW_FS_DIR}/mri ${NEW_FS_DIR}/surf ${NEW_FS_DIR}/label

# Copy necessary files from EXISTING_FS_DIR to NEW_FS_DIR
echo "Copying necessary files from existing FreeSurfer directory..."
rsync -av ${EXISTING_FS_DIR}/mri/ ${NEW_FS_DIR}/mri/
rsync -av ${EXISTING_FS_DIR}/surf/ ${NEW_FS_DIR}/surf/
rsync -av ${EXISTING_FS_DIR}/label/ ${NEW_FS_DIR}/label/
rsync -av ${EXISTING_FS_DIR}/stats/ ${NEW_FS_DIR}/stats/
rsync -av ${EXISTING_FS_DIR}/scripts/ ${NEW_FS_DIR}/scripts/
rsync -av ${EXISTING_FS_DIR}/touch/ ${NEW_FS_DIR}/touch/

# Convert FreeSurfer T1 images to NIfTI format
mri_convert ${NEW_FS_DIR}/mri/T1.mgz ${TEMP_DIR}/old_fs_T1.nii.gz
mri_convert ${T1_IMAGE} ${TEMP_DIR}/new_fs_T1.nii.gz

# Use mri_robust_register to register old FreeSurfer T1 to new FreeSurfer T1
echo "Registering old FreeSurfer T1 to new FreeSurfer T1..."
mri_robust_register --mov ${TEMP_DIR}/old_fs_T1.nii.gz --dst ${TEMP_DIR}/new_fs_T1.nii.gz --lta ${TEMP_DIR}/old_to_new.lta --satit --mapmov ${TEMP_DIR}/old_to_new.nii.gz

# Apply transformation to all old FreeSurfer MRI volumes
echo "Transforming old FreeSurfer volumes to new FreeSurfer space..."
foreach file (${NEW_FS_DIR}/mri/*.mgz)
    set basename = `basename $file .mgz`
    echo "Processing $basename..."
    
    mri_vol2vol --mov $file --targ ${TEMP_DIR}/new_fs_T1.nii.gz --o ${NEW_FS_DIR}/mri/${basename}.nii.gz --reg ${TEMP_DIR}/old_to_new.lta --no-save-reg --interp trilin

    # Convert back to mgz format
    mri_convert ${NEW_FS_DIR}/mri/${basename}.nii.gz ${NEW_FS_DIR}/mri/${basename}.mgz
end

# Apply transformation to the original surfaces
echo "Applying transformation to the original surfaces..."
foreach hemi (lh rh)
    echo "Processing $hemi hemisphere..."
    
    mri_surf2surf --srcsubject ${structid}_registered --trgsubject ${structid}_registered --hemi ${hemi} --sval-xyz white --tval ${NEW_FS_DIR}/surf/${hemi}.white --reg ${TEMP_DIR}/old_to_new.lta --trg_type curv
    if ($status != 0) then
        echo "Error: mri_surf2surf failed for ${hemi} white surface"
        exit 1
    endif

    mri_surf2surf --srcsubject ${structid}_registered --trgsubject ${structid}_registered --hemi ${hemi} --sval-xyz pial --tval ${NEW_FS_DIR}/surf/${hemi}.pial --reg ${TEMP_DIR}/old_to_new.lta --trg_type curv
    if ($status != 0) then
        echo "Error: mri_surf2surf failed for ${hemi} pial surface"
        exit 1
    endif
end

# Move the transformed .mgz files to the NEW_FS_DIR/mri directory
mv ${NEW_FS_DIR}/mri/*.mgz ${NEW_FS_DIR}/mri/

# # Run cortical parcellation
# echo "Running cortical parcellation..."
# recon-all -subjid ${structid}_registered -autorecon3 -parallel -openmp 8

# Clean up
#rm -rf ${TEMP_DIR}

echo "Registration completed successfully"
echo "Registered data is now in: ${NEW_FS_DIR}"
echo "Script completed."

Version:

<!- FreeSurfer version 7.4>