Hello AFNI Gurus!

I have extracted Hippocampal masks from participants’ Freesurfer segmentations. I want to subdivide this ROI into thirds along the anterior-posterior axis (y-axis?). E.g., if a certain participant’s hippocampus goes from slice 90 to slice 120 , I want the first ROI to go from slices 90-103, the second ROI to go from 104-117 and so on. I am using 3dAutobox to get the extent of the ROI, but I can’t figure out to the command to divide the ROIs based on these slice numbers. Is there a way to do this?

Thank you,

Mrinmayi

Hi, Mrinmayi-

[*This message edited to correct an earlier typo I made—thanks to D Glen for noticing: the integer index for time that can be used in 3dcalc below is *l*, as in the first letter of Lima, and not n, as I had mistaken put.]

With 3dcalc, you can use {i, j, k, l} as matrix indices in logic expressions, which represent the first, second and third spatial dimensions and the time dimension, respectively; to do this with coordinates, you can similarly use {x, y, z, t}. These letters will be interpreted in this way as long as you haven’t used that letter to load in a datset.

Thus, with:

```
3dcalc -a DSET1 -expr "a*step(i-10)*step(j-15)" ...
```

… you should get a new dset with the same shape as DSET1 and with same values as DSET1 where the [i] index is greater than 10 AND the [j] index is greater than 15, and 0 everywhere else.

However, if you loaded a dset like this for some reason:

```
3dcalc -a DSET2 -i DSET2 -expr "a*step(i-10)*step(j-15)" ...
```

… then "i’ would be treated to represent the DSET2 dset, not the coordinate.

In general, I find using coordinates is easier: because the dset orientation could be RAI, AIR, LPI, ASL, etc., using {i,j,k} is more confusing, harder to figure out and more potentially unstable than {x,y,z} coordinates, which will be independent of dset orientation (NB: I think these coords are always interpreted as RAI). You can open your image in the AFNI GUI, click where you want and get the RAI coords from the upper left part of the GUI, and use your 3dcalc logic expression with that, something like:

```
3dcalc -a DSET1"<ROI_NAME>" -expr "step(27-y)*not(step(20-y))" ...
```

… depending on your y-axis coords.

You can verify your ROIs in the GUI. (You could also use these logic expressions to make a single 3D volume that contains your 3 ROI chunks, each just defined as a different integer value, if you want.)

–pt

Your question reminded me of an old thread on how to divide up a region based on distance.

https://afni.nimh.nih.gov/afni/community/board/read.php?1,157456,157474#msg-157474

A couple small corrections - from 3dcalc’s help, the use of the ‘l’ (“ell”) character is for the 4th dimension index. The RAI order is *NOT* assumed unless -RAI or -dicom is given as an option; the storage orientation is assumed for xyz.

```
Similarly, the '-i', '-j', and '-k' values, if not otherwise used,
will be loaded with the voxel spatial index coordinates. The '-l'
(letter 'ell') value will be loaded with the temporal index coordinate.
The '-n' value, if not otherwise used, will be loaded with the overall
voxel 1D index. For a 3D dataset, n = i + j*NX + k*NX*NY, where
NX, NY, NZ are the array dimensions of the 3D grid. [29 Jul 2010]
Otherwise undefined letters will be set to zero. In the future, new
default values for other letters may be added.
NOTE WELL: By default, the coordinate order of (x,y,z) is the order in
********* which the data array is stored on disk; this order is output
by 3dinfo. The options below control can change this order:
-dicom }= Sets the coordinates to appear in DICOM standard (RAI) order,
-RAI }= (the AFNI standard), so that -x=Right, -y=Anterior , -z=Inferior,
+x=Left , +y=Posterior, +z=Superior.
-SPM }= Sets the coordinates to appear in SPM (LPI) order,
-LPI }= so that -x=Left , -y=Posterior, -z=Inferior,
+x=Right, +y=Anterior , +z=Superior.
```