Using 3dcalc to create a binary mask from a parcellation scheme

This recipe uses 3dcalc in AFNI to output a binarized 3D image file (nifti) of a region-of-interest in a parcellation scheme that is indexed by number of parcels.

Ingredients:

Example usage:

This example uses the Harvard Oxford Atlas

1
2
3
4
5
6
7
#!/bin/bash

ATLAS_FILENAME='Harvard_Oxford_Atlas.nii.gz'
MASK_NAME='r_amygdala'
ROI_INDEX=102 # index assigned to parcel/region of interest in atlas parcellation scheme (the index for right amygdala in Harvard Oxford atlas is 102)

3dcalc -a ${ATLAS_FILENAME} -prefix ${MASK_NAME}.nii.gz -expr "amongst(a,${ROI_INDEX})"

You can also extract all parcels using a .txt file containing a parcel name on each row:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
#!/bin/bash

ATLAS_FILENAME='Harvard_Oxford_Atlas.nii.gz'
MASKLIST_FILENAME='Harvard_Oxford_Atlas_ROIs.txt'

ROI_INDEX=0
for MASK_NAME in $(cat "${MASKLIST_FILENAME}); do
    ROI_INDEX=$((COUNTER+1))
    3dcalc -a ${ATLAS_FILENAME} -prefix ${MASK_NAME}.nii.gz -expr "amongst(a,${ROI_INDEX})"
done

Recipe made by Shawn Rhoads

These recipes may also be of interest