Splitting ROI into thirds along anterior posterior axis

Hello everyone,

I am trying to take a previously defined ROI and split it into 3 even sub-divisions along the anterior-posterior axis. Splitting the ROI in half is straightforward with 3dCM but I am having trouble figuring out how I could divide it into thirds.

How about the following? It uses integer division, so you have to decide how you want to round things.

``````
#!/bin/tcsh

set dset_roi = THE_DATASET_NAME

# get the 6 extents in terms of IJK slice indices
set extent = `3dAutobox -extent_ijk "\${dset_roi}"`

# select out the min/max along the AP axis
set apmin = \${extent[3]}
set apmax = \${extent[4]}

set div1 = `echo "scale=0; \${apmin} + (\${apmax} - \${apmin}) / 3" | bc`
set div2 = `echo "scale=0; \${apmin} + 2*(\${apmax} - \${apmin}) / 3" | bc`

# report results in terminal
cat << EOF
Slice values are:
\${apmin}
\${div1}
\${div2}
\${apmax}
EOF

# apply results
3dcalc                                  \
-overwrite                          \
-a "\${dset_roi}"                    \
-expr "step(a)*(1+ispositive(j-\${div1})+ispositive(j-\${div2}))" \
-prefix TRIPLE_ROI.nii.gz

``````

Here is a little different variation that works based on euclidean distance instead of distance along the A-P axis.