Visualize ROI edges

Hi AFNI experts,

Is there any way in AFNI/SUMA to visualize only the edges of ROIs, without filling inside each ROI?

Thanks in advance,
Soo Hyun

Hi Soo Hyun,

Here’s a short script where almost all the action happens in just two steps. If you are careful, you can actually do this mostly in a single 3dcalc command using relative indexing, but I think this is a little clearer and more flexible.



make ROIs edgy by creating dataset of just the edges of the ROI


@edgy_rois mydset.nii

output is edgy_rois.nii.gz

set dset = $1
set prefix = “edgy_rois”

see if voxels are on edge by looking for any differences in a voxel neighborhood

3dLocalstat -stat stdev -nbhd ‘SPHERE(-1.42)’ -prefix temp_sd.nii.gz -overwrite

alternatively, use a bigger neighborhood, particularly for anisotropic voxels - thicker edges

#3dLocalstat -stat stdev -nbhd ‘RECT(-1,-1,-1)’ -prefix temp_sd.nii.gz -overwrite \


color the edges only by the ROI value

3dcalc -a $dset -b temp_sd.nii.gz -prefix $prefix.nii.gz -overwrite
-expr ‘a*step(b)’
3drefit -cmap INT_CMAP $prefix.nii.gz

Another tricky way to show edges is to make surfaces of all the regions and then use suma to draw the surface nodes in the afni GUI.

mkdir surfs
cd surfs
IsoSurface -isorois+dsets -input …/myrois.nii -o mysurfs.gii

Then start afni in the volumetric data directory and suma with the surfaces you just created.
afni -niml …/
suma -onestate -i *.gii -sv …/myrois.nii

In AFNI, set the underlay to some desired dataset. In suma, press ‘t’ for suma to talk to afni, and the surface edges will appear in the afni viewer. You can control the thickness of the edge lines with the Control Surfaces menu in afni.