Skip to content

Generating the group mask

czarrar edited this page Sep 11, 2014 · 2 revisions

Before running any of the connectir group analyses, you will need to generate a group mask. You can use the --automask1 option with connectir_subdist.R that does this automatically for you. This is a new option so still experimental. Below I suggest another possible approach. Whatever approach you take, the goal is to create a mask where each voxel has a time-series with a non-zero standard-deviation across 100% of the subjects.

AFNI Approach

I assume that you have a file with the list of your 4D functional files in standard space or can get the list via glob expressions. For now, I imagine a file called func_paths.txt as your input. First, for each subject, we will generate a brain mask that includes voxel with non-zero standard deviation values. Then, we will combine those masks together and take only those voxels present in 100% of the subjects. The commands below should be run in the terminal.

# I/O Paths
funcpaths=( $(cat func_paths.txt) ) # inputs
maskdir=$(pwd)  # output directory for subject masks
maskfile="group_mask.nii.gz" # output file

# Create individual subject brain masks
n=${#funcpaths[@]}
for (( i = 0; i < $n; i++ )); do
    func=${funcpaths[$i]}
    mask="${maskdir}/mask${i}.nii.gz"
    3dTstat -stdev -prefix ${mask} ${func}
done

# Take the mean of the masks
# (i.e., proportion of subjects with value in each voxel)
3dMean -prefix group_prop_subjs.nii.gz ${maskdir}/mask*.nii.gz

# Get voxels with all subjects having a value
3dcalc -a group_prop_subjs.nii.gz -expr 'equals(a,1)' -prefix ${mask_file}

Things to Think About

Note that I plan on creating an automatic group mask generation script into the different scripts. Stay tuned.