Split an ROI mask into half and half along the anterior-posterior axis

Hi AFNI masters,

Is there any way I can divided an ROI mask into half and half along y axis. This ROI mask was previously defined using cluster method in AFNI from functional localizer scans.

Thank you so much!



Well, you can use 3dcalc to specify conditions based on either i, j, k index coordinate values or x, y, z physical space coordinate values; see the 3dcalc help section: “COORDINATES and PREDEFINED VALUES” for more details.

In your case, you could use this to specify that you want to keep all voxel values for some y > YTHR and zero out the rest-- that seems to be what you are asking about. So, the syntax would be something like this:

3dcalc -a INPUT -expr "a*step(y-YTHR)" -prefix OUTPUT

… where you need to state what your YTHR value is; to get the other side of the ROI, you could calculate:

3dcalc -a INPUT -expr "a*not(step(y-YTHR))" -prefix OUTPUT2

If you wanted to get the “center” of your ROI in some sense along the y-axis, you could use 3dCM to get the center of mass location within a mask, and use the y-value there for YTHR.


Thank you so much! That’s extremely helpful! But I’m not familiar with 3dCM. I am reading the Output of -help. I think it should be something like this?


Thank you!


In order to use the coordinate values, you can dump them into a variable, then use that variable. In tcsh syntax this could be done:

# go into tcsh mode, if not there already
# calculate the center of mass of the input data set;  if the ROI is smaller, then use "-mask ..." to select just the ROI of interest; store the (x, y, z) physical coordinates in the variable named xyz.
set xyz = `3dCM INPUT`
# print the y-value to the screen (just for fun)
echo $xyz[1]
# use the y-value as the boundary point above which to 'keep' showing the ROI of interest
3dcalc -a INPUT -expr "a*step(y-$xyz[1])" -prefix OUTPUT


Thank you so much!