-epi_strip in afni_proc.py for monkeys

Hello AFNI team,

I would like to “classically” co-registrate a BOLD image to a template using the movement parameters of the anatomical image, in a primate, with afni_proc.py.
for a typical command please see:

I would like to know if there is a way to modify the "3dSkullStrip or “3dAutomask” parameters in -epi_strip of afni_proc.py?
For example, if I would like to add “-monkey” to 3dSkullStrip. Is it possible?

Is there a way to provide an external EPI mask?

It seems to me that having a bad SkullStrip generates lots of problems for the co-registration?
This problem seems to be recurrent for primates or mammalian BOLD images with no homogenous BOLD signal.

Thank you for your help!

Salut, Clem–

For the first question about passing skullstrip opts to align_epi_anat.py, I think the following would work (note the 2nd line of options for “-align_opts_aea …”; the first line is just kinda standard stuff which is secondary for your question at hand):

-align_opts_aea -cost lpc+ZZ -giant_move  \
            -epi_strip 3dSkullStrip -skullstrip_opts -monkey   \

That created this align_epi_anat.py command in the proc* script:

# ================================= align ==================================
# for e2a: compute anat alignment transformation to EPI registration base
# (new anat will be intermediate, stripped, FT_anat_ns+orig)
align_epi_anat.py -anat2epi -anat FT_anat+orig                      \
       -save_skullstrip -suffix _al_junk                            \
       -epi vr_base_min_outlier+orig -epi_base 0                    \
       -epi_strip 3dAutomask                                        \
       -cost lpc+ZZ -giant_move -check_flip -epi_strip 3dSkullStrip \
       -skullstrip_opts -monkey                                     \
       -volreg off -tshift off

so it looks like that is working how you would want? Well, now I notice that there are 2 “-epi_strip …” commands, and from looking at the history of the files created, it seems like 3dAutomask is still used, oddly. I will have to check with Daniel about this.

To this question: “It seems to me that having a bad SkullStrip generates lots of problems for the co-registration?” well, severe inhomogeneity or odd brightness patterns in the EPI can cause lots of problems for alignment; it is possible that changing the cost function might help. Could you post an image of your EPI, as an example? The details likely matter for deciding what to do here…


Oh, and regarding how to tell afni_proc.py to tell align_epi_anat.py to use 3dSkullStrip on the EPI, Daniel has provided The Right Answer (as we knew he would).

It should be entered via this AP option:

-align_epi_strip_method METHOD : specify EPI skull strip method in AEA

        e.g. -align_epi_strip_method 3dSkullStrip
        default: 3dAutomask (changed from 3dSkullStrip, 20 Aug, 2013)

    When align_epi_anat.py is used to align the EPI and anatomy, it
    uses 3dSkullStrip to remove non-brain tissue from the EPI dataset.
    However afni_proc.py changes that to 3dAutomask by default (as of
    August 20, 2013).  This option can be used to specify which method
    to use, one of 3dSkullStrip, 3dAutomask or None.

    This option assumes the 'align' processing block is used.

So, your afni_proc.py command could contain this:

-align_epi_strip_method 3dSkullStrip                     \
        -align_opts_aea -cost lpc+ZZ -giant_move  \
            -skullstrip_opts -monkey   \

… and that passes everything along correctly.


Hello pt!

Thank you for your answer that will really help!
Here is an example of the kind of image that I am working with:

Indeed, I was already using -cost lpa+ZZ that is actually working fine on half of the images. lpc+zz and nmi doesn’t work at all.
I am confident that changing the epi strip parameters might help!
I will let you know

Thank you for explaining align_epi_strip_method,
I was also confused when I saw in the align_epi_anat command had two epi strip methods.

Hmmm, I see. This does seem to be a notable difference between monkey EPIs and human EPIs: in the human case, typically the skullstripping/automasking isn’t very important, because the skull often doesn’t show up much. But for monkeys, it is a much bigger feature within the FOV.

I can imagine that lpc (or lpc+ZZ) might not work here—that is when the tissue contrast in the EPI is essentially opposite from that in the anatomical. For example, T1w anatomicals have dark ventricles, and EPIs have bright ones. So you will have to explore what works… Sometimes the EPIs have contrast agents included (e.g., MION for monkeys), and that can change the relative contrast, too, so a different cost function would be necessary.


Yes, I think that this one has MION (I need to ask…)
However, my guess was good!
lpa+ZZ associated with the option -monkey did the trick for those who it didn’t work previously!

Hi Clem,

sorry for jumping into your thread, but I am a fellow AFNI/NHP/MION user who has been struggling with similar issues.

So you did you get it to work with 3dSkullStrip and -skullstrip_opts -monkey and cost lpa+ZZ, correct?

For me, both 3dSkullstrip and 3dAutomask always failed on a subset of session (each in its own distinct way), but I found out that no epi skullstripping and lpa (without +ZZ) worked surprisingly well for me.

But I never learned about -skullstrip_opts -monkey before, so thank you for this thread, it was educational for me and I am going to test this option on my dataset.

Hello Pawel,
3dSkullStrip, -skullstrip_opts -monkey and cost lpa+ZZ did the trick (I also used -resample off).
Happy to help you!


Just to note that AFNI’s macaque demo (@Install_MACAQUE_DEMO) includes subjects who have MION during the EPI acquisition. Indeed, we found that using lpa+zz was the way to go for those, noting in the afni_proc.py part of the script:

# Using the lpa+zz cost func for some macaques who have MION;
    # lpc+zz for the others

The align block options used there were as follows:

-align_opts_aea          -cost ${cost_a2e} -giant_move                \
                                 -cmass cmass -feature_size 0.5               \

with “cost_a2e” being lpa+zz for the MION-ated macaques. Things like the need for “-giant_move” and “-cmas cmass” will be very dependent on how you acquire and convert your data (do you have good coords? Do you have lots of non-brain matter in the FOV? etc.). So, indeed, these kinds of things will be study-dependent.

But that makes it all the nicer to:

  • share what ideas work in what contexts, to benefit other users
  • use a program like afni_proc.py where you can relatively easily tweak/adjust these things scriptically, and save them for later and/or share them widely.