Before I give up on this for a while, the map of iteratively eroding may be a useful measure too. Versus interiorosity, erosion levels can be computed faster, especially for very large ROIs. For generally blob shaped objects, it has the pleasing property of being uniformly low on all outer edges and reaching a maximum at a single voxel. For hollow objects or ROIs that have a narrow neck, the maximum can be in multiple voxels, but all these measures have that characteristic. Attached is an image of the erosion levels of an anatomical dataset.
Okay, that's it. Back to real work...
#!/bin/tcsh
# erodemulti.csh
# erode a dataset repeatedly to separate datasets until nothing left
# add up all the erosions at the end to get erosionlevels dataset
# and normalize to get erosionnorm dataset
# usage:
# erodemulti.csh dsetmask+orig
# the output could then be used to select an interior or periphery mask
# with 3dcalc, or the maximum can be used as a center of mass equivalent
set base = `@GetAfniPrefix $1`
set view = `@GetAfniView $1`
set nvox = `3dBrickStat -count -non-zero $1`
rm -f __tt_${base}_erode_??${view}.*
set iter = `printf "%2.2d" 0`
set iterp1 = `printf "%2.2d" 1`
# put copy of original dset in 1st iteration as mask and for easier bookkeeping
3dcalc -a $1 -prefix __tt_${base}_erode_$iter -expr 'step(a)'
# iterate until no more voxels in mask
while ( $nvox != 0 )
# erode facing voxels with 3dcalc
3dcalc -a __tt_${base}_erode_${iter}${view} \
-b a+i -c a-i -d a+j -e a-j -f a+k -g a-k \
-expr 'and(a,b,c,d,e,f,g)' \
-prefix __tt_${base}_erode_${iterp1}${view}
set iter = $iterp1
@ iterp1++
set iterp1 = `printf "%2.2d" $iterp1`
# count the voxels left
set nvox = `3dBrickStat -count -non-zero __tt_${base}_erode_${iter}${view}`
end
rm -rf ${base}_erosionlevels${view}.*
# add all the erosions together for a continuous map of the erosion
3dMean -sum -prefix ${base}_erosionlevels __tt_${base}_erode_??${view}.HEAD
rm -rf ${base}_erosionnorm${view}.*
# compute normalized erosion, to range from 0-1
3dcalc -a ${base}_erosionlevels${view} -expr "a / $iter" -prefix ${base}_erosionnorm
# cleanup all the erosion iterations
rm -f __tt_${base}_erode_??${view}.*