question about incorporating masks

AFNI version info (afni -ver):
Apr 4 2024 (Version AFNI_24.1.00 'Publius Septimius Geta')

Hi guys, I have FS 7 segmentations and parcellations (converted with @SUMA_Make_Spec_FS)
and sswarper2 outputs

i'm incorporating both into a resting state afni_proc. i have the anat follower stuff and noise rois down; all good.

but right now my AP script only has one line related to masking:
-mask_epi_anat yes
and is defaulting all other masking (i also have "mask" after -blocks)

given that i have such high quality (and processing-intensive) outputs from FS and sswarper2, is there anything i should consider about bringing in better masks to AP? do you have recommendations? thanks!


Hi, Sam-

Just to check, what do you want to do with the masks? And what non-ideal behavior are you seeing---for example, is the final mask_dset too large or something? (NB: I'm not expecting that case to be the behavior, as described below, but I just wanted to check.) Or is it the EPI masking you would like to improve, specifically?

I think the mask for sswarper2 is essentially used still because presumably you input the anatomical datset as:

   -copy_anat         <some path>/anatSS.${subj}.nii        \
   -anat_has_skull   no                                     \


The -mask_epi_anat yes will intersect that with the EPI; so, changes in the final mask_dset might be related to the intersection of the EPI mask with the anatomical. However, that probably makes sense as reasonable behavior?


hey Paul!

i don't want to do anything special necessarily, but am aware that the tighter the final masks, the better the group average mask is (thresholded to a percent) for inputting to 3dClustsim.

i do currently have those 2 lines you wrote, which i think you're right, would mean sswarper2's "anatSS_mask.sub-*.nii" would be used essentially.

but what if i wanted to use the FS-derived "fs_parc_wb_mask.nii.gz" instead? i've noticed with older, atrophied brains it makes quite a difference and is a lot tighter to gray matter. if i could somehow swap AP's defaults with that mask would it propagate to the final mask from AP, which in turn could tighten my group mask? this isn't critical but something i'm wondering about and i suppose others might too.

on a somewhat related note, why in the AP examples is the -block "blur" sometimes before or sometimes after "mask"?

i know i could test multiple possibilities here but it's a garden of forking paths, which i figured a quick convo could help me machete through. THANKS A TON


Hi, Sam-

I see, that makes sense. Though, I'm a little surprised that the marginal difference in anatomical dset masking would make a difference for 3dClustsim? Are you sure that is the case?

Here are a couple options, though they involve an inelegant extra step in each case rather than telling AP that here's another mask to directly apply. I think I would favor the second out of these, assuming that the anatSS masking is still pretty good.

One option: pre-apply fs_parc*.nii.gz mask
I guess as long as the fs_parc_wb_mask.nii.gz is tighter than the masking applied to anatSS.${subj}.nii, then you could do:

# resample fs_parc* to anatSS* grid, preserving int values
3dresample \
   -input   ${path1}/fs_parc_wb_mask.nii.gz \
   -master ${path2}/anatSS.${subj}.nii \
   -prefix ${path2}/fs_parc_wb_mask_RES.nii.gz \
   -rmode NN

# use new resampled mask to refine the anatSS
3dcalc \ 
    -a ${path2}/anatSS.${subj}.nii \
    -b ${path2}/fs_parc_wb_mask_RES.nii.gz \
    -expr 'step(b)*a' \
    -prefix ${path2}/anatSS.${subj}_MSKD2.nii.gz

... and then use ${path2}/anatSS.${subj}_MSKD2.nii.gz as the copy_anat dset in the processing?

Second option: send fs_parc*.nii.gz mask to final space, as follower, to apply as desired
To do this, add:

-anat_follower_ROI FSmask epi fs_parc_wb_mask.nii.gz 

to your command. This will take your anatomical-space mask and send it along to final space, and more specifically put it on the final EPI grid there. Then you can always use it as an extra multiplier to the mask_dset later.


oh this is great, thanks for helping me think through this! i'll do the 2nd procedure which'll give me some comparisons to make for the group masks; and then i'll be able to answer your first question as to if it actually makes a meaningful difference. will report back when the time comes. thanks again!!

Grazie mille.


1 Like