Problems with @Align_centers

Dear AFNI experts,

I am trying to implement @SSwarper into my pre-processing and whilst the defaults (@SSwarper -input {T1 file} -subid {subject} -odir {out_dir} -base {template}) worked well for most subjects, some subjects had clippings in axial inferior slices. To combat this, I have updated AFNI (now running Precompiled binary linux_ubuntu_16_64: Nov 12 2020 (Version AFNI_20.3.02 ‘Vespasian’)) and consulted the message board where I found suggestions that the lack of alignment between the anatomical scan and the template image could be the reason for clippings (see this post). Hence, I have changed my pipeline to (a) run @Align_centers to align the template and scan before running @SSwarper and (b) add settings (-giant_move -SSopt ‘-push_to_edge’) for the skull stripping (see code below).


#!/bin/bash

# define path
DIR="/storage/shared/research/cinn/2018/MAGMOT"

# change directory to BIDS folder
BIDS_dir="$DIR"/MAGMOT_BIDS
# change directory to the raw NIFI files
cd $BIDS_dir

subjects=($(ls -d sub*))
subjects=(sub-control003)

# define derivatives directory
deriv_dir="$DIR"/derivatives

# define which template to use and where to find them
template=MNI152_2009_template_SSW.nii.gz
template_path=`@FindAfniDsetPath $template`

# for each subject in the subjects array
for subject in "${subjects[@]}"; do

    echo "###################################################################################"	
    echo "@SSwarper for subject $subject"
    echo "###################################################################################"	

	# create output folder
	out_root=$deriv_dir/afniproc
	out_dir=$out_root/$subject/SSwarper
	mkdir $out_dir

	# define BIDS anat folder
	anat_dir=$DIR/MAGMOT_BIDS/"${subject}"/anat
    anat="$subject"_rec-NORM_T1w.nii.gz
    prefix="$subject"_shft.nii.gz
    cd $anat_dir

    # copy original anatomical scan
    3dcopy $anat $out_dir/$anat

    cd $out_dir

    # align centers
    @Align_Centers  \
        -cm \
        -prefix $prefix     \
        -dset $anat \
        -base $template_path/$template

	# specify SSwarper
	@SSwarper -input $prefix                             \
		-subid $subject							\
		-odir $out_dir							\
		-base $template_path/$template	\
		-giant_move -SSopt '-push_to_edge'

done


Although the adaptations have improved the output of @SSwarper significantly (compared to default ran on an older version), it is still not as good as the output of most default subjects and some cortex is still clipped (see attachment). When checking the file init_qc_00_overlap_usrc_obase.jpg I noticed that even though the output of @Align_centers is used as input for @SSwarper, the alignment is still poor. I have tried to play with the alignments a bit to improve the results (e.g. by running 3dMC before running @Align_centers; see code below), but the result still does not seem satisfying (see attachment).


#!/bin/bash

# define path
DIR="/storage/shared/research/cinn/2018/MAGMOT"

# change directory to BIDS folder
BIDS_dir="$DIR"/MAGMOT_BIDS
# change directory to the raw NIFI files
cd $BIDS_dir

# define subjects based on folder names in the BIDS directory
subjects=($(ls -d sub*))
subjects=(sub-control003)

# define derivatives directory
deriv_dir="$DIR"/derivatives

# define which template to use and where to find them
template=MNI152_2009_template_SSW.nii.gz
template_path=`@FindAfniDsetPath $template`

# for each subject in the subjects array
for subject in "${subjects[@]}"; do

  # create output folder
	out_root=$deriv_dir/afniproc
	out_dir=$out_root/$subject/align_centers
	mkdir $out_dir

	# define BIDS anat folder
	anat_dir=$DIR/MAGMOT_BIDS/"${subject}"/anat
    anat="$subject"_rec-NORM_T1w.nii.gz
    anat_rf="$subject"_refit.nii.gz
	cd $anat_dir

	# define prefix
    prefix_shft="$subject"_shft.nii.gz
    prefix_shft_rf="$subject"_shft_refit.nii.gz	

	prefix_3dCM="$subject"_3dCM.nii.gz
	prefix_3dCM_rf="$subject"_3dCM_refit.nii.gz
	prefix_3dCM_shft="$subject"_3dCM_shft.nii.gz
	prefix_3dCM_shft_rf="$subject"_3dCM_shft_refit.nii.gz

    # copy original anatomical scan
    3dcopy $anat $out_dir/$anat

	# go to output directory
    cd $out_dir

	# change center of mass
	3dcopy $anat $prefix_3dCM
	3dCM -automask -set 0 0 0 $prefix_3dCM

    # align centers between anatomical and template
    @Align_Centers \
        -cm \
        -prefix $prefix_shft \
        -dset $anat \
        -base $template_path/$template

    # align centers between anatomical and template after changing center of mask of anatomical
    @Align_Centers \
        -cm \
        -prefix $prefix_3dCM_shft \
        -dset $prefix_3dCM \
        -base $template_path/$template
	

	# refit to MNI for visualisation purposes: first copy files, then refit
	3dcopy $anat $anat_rf	
	3dcopy $prefix_shft $prefix_shft_rf
	3dcopy $prefix_3dCM $prefix_3dCM_rf
	3dcopy $prefix_3dCM_shft $prefix_3dCM_shft_rf

	3drefit -space MNI $anat_rf
	3drefit -space MNI $prefix_shft_rf
	3drefit -space MNI $prefix_3dCM_rf
	3drefit -space MNI $prefix_3dCM_shft_rf

	# copy template into directory for visualisation purposes
	3dcopy $template_path/$template $template
		
done

I have noticed that even after running 3dCM the center of mass is still not close to the ACPC line (though closer than before) and also that it seems as if the center of mass moves back to its original position if I run 3dCM + @Align_centers. Is there any way how I can improve the alignment between my anatomical scan and the MNI template further to improve the skull stripping performed by @SSwarper?

Also, because this has been discussed previously, I have added the obliquity information of the original anatomical image and the output of @Align_centers.
3dWarp -disp_obl_xform_only -deoblique $anat
++ 3dWarp: AFNI version=AFNI_20.3.02 (Nov 12 2020) [64-bit]
++ Authored by: RW Cox

mat44 Obliquity Transformation ::

  0.998696      0.015065     -0.048780      -5.739861
 -0.026233      0.971115     -0.237165     -13.290672
  0.043798      0.238135      0.970244     -36.265778

3dWarp -disp_obl_xform_only -deoblique $prefix_shft
++ 3dWarp: AFNI version=AFNI_20.3.02 (Nov 12 2020) [64-bit]
++ Authored by: RW Cox

mat44 Obliquity Transformation ::

  1.000000      0.000000      0.000000       0.000000
  0.000000      1.000000      0.000000       0.000000
  0.000000      0.000000      1.000000       0.000023

Any pointers on how to improve the alignment between anatomical and MNI would be really helpful!

Many thanks in advance,
Stef

Hi, Stef-

It sounds like you have done a lot of the steps I would have done-- rockin’.

One thing to note about aligning by CM: the template dset is just the brain, so its CM is about in its midde; but the subj anat has a loooot of nonbrain material, so I can see its CM being below the brain, which appears to be the case, and that’s why “aligning by CM” isn’t giving you what you want. As usual, I am blaming the data :slight_smile:

One thing I would do to alleviate this would be to “3dZeropad -I -50 …” the initial dset: that is, remove the bottom 50 rows of not-useful neck/cheek scan. NB: I am just guessing at 50, a good number would remove a lot of non-brain material at the inferior part of the FOV, while not chopping into the brain — 50 was just an initial guess. If you did CM alignment on the resulting dset, I think you would probably be in much better initial alignment.

Second thing: based on the image you uploaded, I am not sure if the somewhat poor initial alignment is causing the problem with skullstripping here, though. (That is, the not-so-great initial alignment might have been overcome here during the processing.) I wonder if the alignment is having a hard time separating brain from dura or something because of the brightness inhomogeneity by the edge of the brain? I notice you are using the SSopt-push_to_edge for 3dSkullstrip in @SSwarper, perhaps because of this? Would you be able to upload this subj, if I email you a link?

–pt

Thank you for your reply, Paul, this is really appreciated. I am happy to upload the data if you provide me with instructions. I had added the SSopt-push_to_edge based on the 3dSkullStrip help for general clippings.

Best wishes,
Stef

Hey Paul,

To further follow up on the second part of your message: I again checked the output of the whole sample (50 subjects) and the initial alignment (init_qc_00_overlap_usrc_obase.jpg) after running @Align_centers was actually comparably good/bad across all of them - probably as suggested by you due to considerably large neck/cheek areas. Whilst this not-so-great initial alignment was overcome in most cases, the fact that some subjects (like the data I uploaded) have clippings suggests that there is indeed a problem in their data and I am not quite sure what the best steps would be to deal with this. I don’t know whether it helps, but we also processed the anatomical data in FreeSurfer (recon-all with defaults) and ran @SUMA_Make_Spec_FS -sid ${subject} -NIFTI afterwards, so we have those output files (i.e., T1.nii & ${subject}_SurfVol.nii) and I was wondering whether either of those could be a better input for @SSwarper? If so, should any steps be omitted (e.g., using -unifize_off or -aniso_off)? I have uploaded the T1.nii & ${subject}_SurfVol.nii as well for you to have a look at. Before “switching” to @SSwarper, I used T1.nii as anatomical input for afni_proc.py.

Again, thanks so much for your help, this is really appreciated!

Best wishes,
Stef