Poor aligment using scripts that have worked before

Hi AFNI people!

We have a set of scripts that has served us well before, but we are now analyzing data from another lab and we have problems with the alignment of the EPI onto the anatomy.

Using tips we got from Paul Taylor we prepp our T1: data by first:

3dcopy T1_$subject.nii tmp
3drefit -oblique_recenter tmp+orig
3drefit -deoblique tmp+orig 
3dcopy tmp+orig T1_do_$subject.nii
#3dZeropad -I -70 -prefix T1_do_zp.nii T1_do.nii (these data don't include much neck at all, so we don't clip anything)
3dCM -set 0 0 0 T1_do_$subject.nii

Then we run SSwarper: on the T1_do_$subject.nii

@SSwarper -input T1_do_$subject.nii -base /usr/local/abin/MNI152_2009_template_SSW.nii.gz -subid ${sub_id} -giant_move -deoblique_refitly -odir $startdir/pre_warp_${sub_id}

This looks good. Then we run afni-proc with these relevant settings:

-blocks despike tshift align tlrc volreg blur mask scale regress \
    -copy_anat pre_warp_$sub_id/anatSS.$sub_id.nii \
    -anat_has_skull no \
    -anat_follower anat_w_skull anat $T1_data \
    -dsets $fmri_data \
    -align_opts_aea -ginormous_move -cost lpc+ZZ -check_flip \
    -tlrc_base MNI152_2009_template_SSW.nii.gz \
    -tlrc_NL_warp \
    -tlrc_NL_warped_dsets \
           pre_warp_$sub_id/anatQQ.$sub_id.nii \
           pre_warp_$sub_id/anatQQ.$sub_id.aff12.1D \
           pre_warp_$sub_id/anatQQ.${sub_id}_WARP.nii \
    -volreg_align_to MIN_OUTLIER \
    -volreg_align_e2a \
    -volreg_tlrc_warp \

Normally, this looks good for other data. But here the EPI seem to be way off. There is no other option than ginormous move, so I tried to align centers of epi and anat prior to this and I tried to use 3dAllineate to move the volumes closer to each other prior to afni-proc but did not mange.

@Align_Centers -base temp_T1_$sub_id.nii -dset $fmri_data -no_cp -cm -1Dmat_only
3dAllineate -master temp_T1_$sub_id.nii -1Dmatrix_apply rs-fMRI_shft.1D -prefix test_pre_align -input $fmri_data

This resamples the EPI, whis not what we want and it still does not overlay well when looking at the native space data in the viewer.

I’m attaching the de-oblieq pre/post and alignment maps.
The T1->MNI looks really good, to this must be an alignment issue.

Data quality of EPI? I think it looks good, visually. So it is probably a distance between EPI and T1 issue?
Attaching EPI snap shot as well. (next post)

Thanks in advance!

EPI print:


Hi, Robin-

That EPI has a fair amount of brightness inhomogeneity. See how a lot of sulcal/gyral structures appear washed out and hard to see by the brightness around the edge.

To help deal with that, we created a new local unifizer that seems to really help with EPI-anatomical alignment of human FMRI datasets (*animal datasets have more external features, so still working on some special cases there, separately but relatedly). Anyways, can you try adding option this to your AP command:

-align_unifize_epi local \

(NB: this is not in place of anything there, but added separately.) Please let us know if that improves EPI-anatomical alignment.

Note: deobliquing the anat and EPI ahead of time makes a lot of sense. In your first chunk of code, this does deobliquing of the anatomical while preserving the location of the (x,y,z)=(0,0,0) part of the dataset:

3dcopy T1_$subject.nii tmp
3drefit -oblique_recenter tmp+orig
3drefit -deoblique tmp+orig 
3dcopy tmp+orig T1_do_$subject.nii

The subsequent 3dCM command then translates the dataset spatially so that its center-of-mass will sit at (x,y,z)=(0,0,0). Note that that might leave the EPI dataset behind, and relatively far away, because its coordinates were not reset—that appears to be the case, from the “initial overlap” images. What I might do instead would be to run, assuming your EPI and anatomical were pretty well aligned to start:

# deoblique the T1w volume, keeping coord origin
3dcopy T1_$subject.nii tmp
3drefit -oblique_recenter tmp+orig
3drefit -deoblique tmp+orig 
3dcopy tmp+orig T1_do_$subject.nii

# deoblique the EPI volume, keeping coord origin
3dcopy EPI_$subject.nii tmp
3drefit -oblique_recenter tmp+orig
3drefit -deoblique tmp+orig 
3dcopy tmp+orig EPI_do_$subject.nii

# translate the anatomical to have its CM match the template's CM,
# ... and bring along the EPI as a "child" dataset
@Align_Centers \
   -cm \
   -base MNI152_2009_template_SSW.nii.gz \
   -dset T1_do_$subject.nii \
   -child EPI_do_$subject.nii

# check anatomical-template overlap
@djunct_overlap_check \
    -ulay T1_do_${subject}_shft+orig \
    -olay MNI152_2009_template_SSW.nii.gz \
    -prefix img_olap_t1w_template

# check EPI-anatomical overlap
@djunct_overlap_check \
    -ulay T1_do_${subject}_shft+orig \
    -olay EPI_do_${subject}_shft+orig \
    -prefix img_olap_epi_t1w

… and see how those overlap images look? Can you try that for one subject?

Then, you would run SSW on the T1_do_${subject}shft+orig, and use those results and the EPI_do${subject}_shft+orig dset in your AP command.


Thanks Paul!

How well should the results from @djunct overlay images align?
Because these commands do not align them, but move them closer, right?
They do not perfectly overlap. See attached. Is this expected?

Thanks again!

These are not the problematic data, they are on a system I can’t access right now. These data did work well with the old scripts.
But you can still see if this is reasonable =)

Hi, Robin-

Those look reasonable for a starting point. Note how it is much closer than in the initially shown case.

You could also check those overlaps (anatomical-template, and EPI-anatomical) before running @Align_Centers here—that might not be necessary, if the datasets are already well-centered around the (x,y,z)=(0,0,0) coordinate origin.