AFNI Message Board

Dear AFNI users-

We are very pleased to announce that the new AFNI Message Board framework is up! Please join us at:

https://discuss.afni.nimh.nih.gov

Existing user accounts have been migrated, so returning users can login by requesting a password reset. New users can create accounts, as well, through a standard account creation process. Please note that these setup emails might initially go to spam folders (esp. for NIH users!), so please check those locations in the beginning.

The current Message Board discussion threads have been migrated to the new framework. The current Message Board will remain visible, but read-only, for a little while.

Sincerely, AFNI HQ

History of AFNI updates  

|
Daniel Glen
March 09, 2009 05:23PM
This kind of question, strangely, has come up recently several times in vastly different contexts. Last year we came up with a series of methods that could determine the periphery of a mask or the interior of a mask and some measures of interiorosity (?). So for the record, these are some simple and complicated ways to do this. Undoubtedly, there are a great many ways to do the same, and you are welcome to add ideas here.

For your case, you will need to make a mask, possibly with 3dAutomask or "3dSkullStrip -mask_vol" first. Then you can use 3dmaskdump for the periphery voxels you get.

1. Using 3dAutomask's erode feature:
3dAutomask -prefix anat_am anat+orig.
3dAutomask -erode 1 -prefix anat_am2 anat+orig.
3dcalc -a anat_am+orig -b anat_am2+orig -expr 'a-b' -prefix periphery_am2

Unfortunately, 3dAutomask's erode doesn't erode quite the way you might expect in concave regions especially for only a single voxel erosion. For multiple layers or deeper periphery, this is a quick way to do it.

2. Using 3dmerge's erode feature (which is limited to 1 layer at a time, but there's a little more control)
3dAutomask -prefix anat_am anat+orig.
3dmerge -1clust 1 27 -dxyz=1 -1erode 99 -prefix anat_mrg anat_am+orig
3dcalc -a anat_am+orig -b anat_mrg+orig -expr 'a-b' -prefix periphery_mrg

3. Using 3dcalc to look around the immediate neighborhood:
3dAutomask -prefix anat_am anat+orig.
3dcalc -a anat_am+orig -b a+i -c a-i -d a+j -e a-j -f a+k -g a-k -expr 'step(a) * (1-and(a,b,c,d,e,f,g))' -prefix periphery_3dc

4. You can also use 3dLocalstat to do almost the same thing:
3dLocalstat -stat num -automask -prefix anat_ls anat+orig
3dcalc -a anat_ls+orig. -expr 'step(a - a*step(a-6))' -prefix periphery_3dLs4

5. To find a periphery of some thickness other than one voxel, you will need to be a little trickier by applying the above techniques repeatedly for the number of voxels you would like or by doing something like this. Here 3dUndump can put spheres down on the 1 voxel edge periphery that was computed using one of the previous methods.

3dmaskdump -nozero periphery_3dc+orig > periphery.1D
3dUndump -prefix periphery_10mm_undump -srad 10 -master anat_am+orig -mask anat_am+orig periphery.1D

6. One could also compute a distance map of the distance of each voxel to some central voxel like the center of mass. Here the center of mass is computed for the mask, but it could be done on the original data too. 3dclust can be used to compute the center of mass for multiple ROIs.

set cm = `3dCM anat_am+orig`
3dcalc -a anat_am+orig -expr "step(a)*sqrt(($cm[1]-x)^2 + ($cm[2]-y)^2 + ($cm[3]-z)^2)" -prefix distmap

7. Using 3dLocalstat in a slightly different way than in method 4 can give a measure of how interior / exterior a voxel is within an ROI mask ("interiorosity" and "exteriorosity"). If one looks at the overlap of a large enough sphere, one wider than the original mask, with the original mask, that gives us this interiorosity measure. By giving a measure of overlap with neighboring voxels, the values of a count, mean or sum from 3dLocalstat then provide a relative measure of "interiorosity", but not the same as peripheral layers. Voxels on the edge closer to a thicker part of the ROI will have higher values than voxels on a thinner part. Voxels in the center will have higher values.

This method is terribly slow for large regions but works well for small regions. The interiorosity maximum point could be an alternative to center of mass coordinates, particularly for oddly shaped regions like crescents. The center of mass can sometimes occur outside the original region for these odd ROIs. Maximum values could be useful as measure of a kind of center
of mass that always lies within the mask even for oddly shaped images.

3dLocalstat -nbhd 'SPHERE 5' -stat num -mask crescentroi+orig. -prefix interiorosity crescentroi+orig

Some of these methods could probably be done by working with surfaces instead, but that will take some time to figure out.

Some caveats:
For the methods using spheres, spheres may go off edge of volume if
the mask is too close to the edge, or the spheres are too large.

Examining peripheral voxels of a single ROI will probably point out
partial volume effects that result from the resolution limits of the
scanner and motion.



Edited 1 time(s). Last edit at 12/26/2018 11:17PM by Daniel Glen.
Subject Author Posted

Boundary coordinates

AFNI User March 09, 2009 12:56PM

Re: Boundary coordinates

Bob Cox March 09, 2009 01:26PM

Edges, periphery and interiorosity

Daniel Glen March 09, 2009 05:23PM

Re: Edges, periphery and interiorosity

bob cox March 09, 2009 06:01PM

Re: Edges, periphery and interiorosity

Daniel Glen March 10, 2009 04:27PM

Re: Edges, periphery and interiorosity

Daniel Glen March 11, 2009 02:28PM

Re: Boundary coordinates

AFNI User March 10, 2009 07:59AM