Cannot get good alignment with align_epi_anat.py or 3dAllineate

Hi there,

I have been trying to do an alignment with the following details:

  • Anatomical to epi
  • Partial coverage (I have a small epi slab centred over left SI)
  • 7T data

I have two subjects, and things worked differently for the two. Only method 2 produced something that was not way, way off for sub2 where sub1 was generally ok with most methods (aside from method 3 & 5)

I have tried the following methods:

1. align_epi_anat.py, giant move (below)

2. align_epi_anat.py, ginormous move (as below but with ginormous)

align_epi_anat.py -anat2epi -anat FR_uniden_avg+orig
-suffix _al_keep
-epi vr_base_min_outlier+orig -epi_base 0
-epi_strip 3dAutomask
-epi2anat -giant_move -partial_coverage
-volreg off -tshift off

3. align_epi_anat.py with lpc+ZZ cost function

align_epi_anat.py -anat2epi -anat FR_uniden_avg+orig
-suffix _al_keep_lpcZZ
-epi vr_base_min_outlier+orig -epi_base 0
-epi_strip 3dAutomask
-epi2anat -giant_move -partial_coverage
-cost lpc+ZZ
-volreg off -tshift off

4. zpad & nudge, then align_epi_anat.py

3dZeropad -I 0 -S 30 -A 0 -P 0 -L 0 -R 70 -prefix FR_uniden_avg_zpad FR_uniden_avg+orig
3drotate -quintic -clipit -rotate 0.00I 0.00R 0.00A -ashift 25.00S -45.00L 0.00P -prefix FR_uniden_zpad_nudged FR_uniden_avg_zpad+orig
3dZeropad -I -30 -S -30 -A 0 -P 0 -L -80 -R 0 -prefix FR_uniden_avg_zpad_nudged_zcor FR_uniden_zpad_nudged+orig

align_epi_anat.py -anat2epi -anat FR_uniden_avg_zpad_nudged_zcor+orig
-suffix _al_keep_Ngiant
-epi vr_base_min_outlier+orig -epi_base 0
-epi_strip 3dAutomask
-epi2anat -giant_move -partial_coverage
-volreg off -tshift off

5. zpad & nudge, then 3dAllineate
3dAllineate
-base vr_base_min_outlier+orig
-input FR_uniden_avg_zpad_nudged_zcor+orig
-prefix FR_uniden_avg_N3dA+orig
-1Dmatrix_save FR_uniden_avg_N3dA_al_12.1D
-cost lpc
-final wsinc5
-source_automask -autoweight
-twopass
-verb

Any help on what I could try to improve these alignments would be very much appreciated!

Thank you,

Harriet

Partial volumes are often tricky based on the content of the slab and contrast. Seems like you’ve tried most of the ways I’ve used in the past to get alignment. Can you post some screenshots and perhaps send me a PM to download the data?

Some have found this blog post to be helpful: https://blog.cogneurostats.com/2019/04/22/aligning-partial-volume-fmri-in-afni/

Adding on to Pete’s useful advice, I would recommend trying “lpa+ZZ” or “lpa” cost functions for EPI data where it’s hard to distinguish CSF. For data that may be very bright on the edge of the brain, you could use “-perc 99” to increase the ceiling percentile value in the EPI used for alignment.

Hi Peter,

Thanks for getting back, here are some images (sorry I can never get the image upload in afni to work properly)

This is the problematic participant, P07_LV

With giant move - big fail

https://photos.app.goo.gl/Hd4xEBvWh229zkYH6

With ginormous move - better but still bad

https://photos.app.goo.gl/QQcVooTsAz4KuRC76

Thanks for the link, that’s where I got the idea for the nudge and 3dAllineate from - which works well for the problematic P07_LV (note the apparent misalignment at the front and back looks to be due to signal drop out, apparent when viewed at higher overlay threshold)

https://photos.app.goo.gl/czRgrV9c3HXPVmAU6

This is for the other participant where I had more success

Giant move, ginormous move and nudge + giant move all produce nearly identical results (you have to really look closely to see the differences). It looks like the below. The alignment in frontal/ medial areas seems to be quite off still with these methods

https://photos.app.goo.gl/KxDZdsMoVoJu4Rfv9

I’ve never had any luck using lpc+ZZ cost function in alignment with my data, they always turn out warped. Perhaps because it is partial data and I should try lpa lpa+ZZ as Daniel suggests?

https://photos.app.goo.gl/3ZSeE8yFc88WfmKp9
https://photos.app.goo.gl/grLx4yPZ1WqPPaA38

Happy to share data if that might be helpful. Thank you for your help!

Harriet

Hi Daniel,

Thank you for the suggestions.

I just tried lpa – it produces a decent alignment (nearly identical to the other things I tried that worked ok: default cost function with giant move/ ginormous move, nudging + those things)

I included a picture of this alignment. I have put the crosshairs where I see the main issue to be, that curved line looks like it should fit a nearby anatomical landmark. My supervisor says I am being too picky and the alignment is fine. What do you think??

https://drive.google.com/file/d/1W2qdZVs_NtHGqLrTQDTbVNwtik4JAtnw/view?usp=sharing

I also tried lpa+ZZ, it made a big bad warpy brain (see second image). This happens whenever I try and use +ZZ (whether with lpa or lpa, this subject or others), could it be because of partial data?

https://drive.google.com/file/d/1oxrlAieJvmz6vh4Fnpo63ON-Dw3QZZdk/view?usp=sharing

Tried adding -perc_99 but it is also near identical to lpa etc., and still contains that one problem area shown in the image.

I have sent the data to Peter by pm, interested to see if he comes back with anything.

Thanks both for your help,

Harriet

Hi, Harriet-

I for one can’t see these images, because they require a google login. Can you please try attaching them here again?

A general point about alignment; there is only so far that affine alignment—12 degrees of freedom, 3 dimensions of rotation, translation, shear and scale–can go. We generally use affine to align data from one subject to other data of that subject—e.g., an EPI to an anatomical of sub-000. Why might that not provide exact alignment? EPIs can be distorted by B0 inhomogeneity and other effects; DWI images (also typically from an EPI sequence) can have even more distortions. Also, EPI images tend to be lower spatial resolution than an antomical, so there is partial voluming and loss of structural detail. Also also, EPI images (and also structural images) can have brightness inhomogeneities (separate from geometric distortion), which change their appearance and potential alignability. Scanning on a different day or in a different scanner can also lead to different distortions/effects. In short, life can be hard sometimes.

So, sometimes higher order alignment is necessary, depending on the data, even for data within the same subject, depending on the degree of alignment you need. But this depends a lot on the data, data quality, goals, etc.

To align data from different subjects (e.g., sub-000 to sub-001 or sub-000 to a template), we would typically recommend using nonlinear alignment, because the degree of expected difference is pretty large.

In all of this, the relative contrast of your data (and presence of inhomogeneities/oddities) can also inform what cost function is used to guide the alignment.

A lot of alignment issues in MRI are discussed here:
https://www.youtube.com/watch?v=PaZinetFKGY&list=PL_CD549H9kgqJ1GDXAs1BWkgEimAHZeNX

Again, these are just general points, because I cannot see the images you have linked above.

–pt

Hi sorry,

Images should be attached now. The one where alignment is better is using lpa, the warped one is lpa+ZZ

My questions were:

  • My colleague said the lpa alignment was ‘good enough’ but is it?
  • Why do I always get a weird warp when using +ZZ?

So, pt, you would recommend trying higher order alignment, e.g., non-linear methods as used in 3dQwarp or @SSwarper?

  • Data quality is high and very close alignment is definitely a goal

Unfortunately, I don’t have B0 maps or anything to correct inhomogeneities (it is old data).

Hi-

I’m a little confused about what that non-anatomical dataset is. It just looks like a sparse mask, and probably lpa would not be a useful cost function for it.

Can I send you a link to upload the data so I can look at the full sets in vivo?

–pt

Hi all,

I have been experimenting with non-linear alignment to see if I can improve my alignment issue. Below is an image of the best I could get with ginormous move (see first post)

https://ibb.co/Bf565df

I used 3dQwarp following the suggestion for aligning epi to T1 (though with a small modification to make it an anat2epi alignment, not epi2anat as in the example)

It has done a great job of aligning around the medial part of the brain (near SI) where I was most concerned about. However, the first alignment step (with align_epi_anat.py) chops off the back of the anatomical - very back occipital cortex and some cerebellum. Thus, this step and the final 3dQwarp step fail badly on the back of the brain.

View 1/ epi threshold 1

https://ibb.co/8DyvTVs

View 2/ epi threshold 2

https://ibb.co/ssQkThK

I tried avoiding this clipping by zpadding the epi, but this does not seem to work (makes the alignment go crazy)

Anyone have any ideas of how to improve this clipping/ poor alignment at the back of the brain issue. Or anything else to try?

Thank you,

Harriet


Code

Pre-prep anat for skull strip by unifizing

3dUnifize -prefix {$anat}_uni {$anat}+orig

Skull strip anat

3dSkullStrip -shrink_fac 0.4 -input {$anat}_uni+orig -prefix {$anat}_uni_SS

Extracting just 0th sub-brick for registration purposes

3dbucket -prefix epi0 pb01.{$subj}.r0{$run}.despike+orig’[123]’

Other attempt (from second pass) - try zpadding epi before removing sub-brick of interest (so as to avoid anat getting clipped)

Zpad epi - so as not to clip anat

set run = 5

3dZeropad -I 5 -S 5 -A 5 -P 5 -L 5 -R 5 \

-prefix epi_padded+orig \

pb01.{$subj}.r0{$run}.despike+orig

Extracting just the 0th sub-brick for registration purposes

FG: Use min outlier: run 05, TR 123

3dbucket -prefix epi0 epi_padded+orig’[123]’

anat is aligned to the epi sub-brick and resampled to the epi grid

align_epi_anat.py
-anat {$anat}_SS+orig
-anat_has_skull no
-epi $epi0+orig
-epi_base 0
-partial_coverage
-anat2epi
-master_anat {$epi0}+orig
-big_move

anat is nonlinearly aligned ONLY using the global warping – it is futile to try to align such dissimilar image types precisely.

EPI = base (thing you align to) in 3dQwarp so that it provides the weighting, and so partial brain coverage (as long as it covers MOST of the brain) should not cause a problem

Removed -blur 0 3

Removed -iwarp

3dQwarp -source {$anat}_SS_al+orig.HEAD
-base {$epi0}+orig
-prefix {$anat}_SS_3dQ
-lpc -maxlev 0 -verb

The “-master_anat” option controls the output grid for the anatomical dataset. Some choices:

  1. Remove the "-master_anat {$epi0}+orig ". This ought to be in the same grid with the “-big_move” option.
  2. Set the master_anat to “SOURCE” to keep it in the original grid
  3. Zeropad an EPI dataset, single subbrick volume to use as a target grid.
    3dZeropad -prefix temp_epizp.nii.gz -R 5 -L 5 -A 5 -P 5 -I 5 -S 5 myepi.nii.gz’[0]’
    align_epi_anat.py -master_anat temp_epizp.nii.gz -master_anat_dxyz 1.0 …
  4. For very oblique data, consider using the oblique grid of the anatomical data as a target
    3dWarp -card2oblique myepi.nii.gz -prefix temp_anatob.nii.gz myanat.nii.gz
    align_epi_anat.py -master_anat temp_epizp.nii.gz …