Is there any way to average 3d ROI masks?


I am writing to ask whether there are ways to average 3D ROI masks that are drawn through SUMA across multiple subjects.

I tried to do it through the 3dcalc function of AFNI. But, it seems that the function is eligible for datasets rather than 3D masks.

Is there any way to do it?

Shinyoung Jung

AFNI version info (afni -ver): Sep 18 2022 (Version AFNI_22.2.12 'Marcus Aurelius')

code text  # or delete if not needed

Can you please share your 3dcalc command? If the SUMA datasets are all on the same mesh, that should be possible, I would think.

And to be clear, did you convert your drawn ROIs to actual datasets? That is described a bit here in this AFNI Academy tutorial for drawing+converting SUMA ROIs to datasets (at around this time point):



3dcalc \
-a AB_visual_all_lh.niml.roi[1] \
-b AC_visual_all_lh.niml.roi[1] \
-c AD_visual_all_lh.niml.roi[1] \
-d AF_visual_all_lh.niml.roi[1] \
-expr (a+b+c+d)/4 \
-prefix v1v_averaged

Because each participant's roi file has multiple layers, I used '[1]'.

OK. Indeed, the issue is that those *.niml.roi files need to be converted to *.niml.dset files. That process is demonstrated in link I sent, as well as in the AFNI Bootcamp demo data, in the script: AFNI_data6/FT_analysis/FT/SUMA/run.roi2dset. That involves using ROI2dataset and 3dSurf2Vol, as shown there:

## ----------------------------------------------------------------------
## Convert a drawn surface ROI to the volume (and back?).
## In suma, draw an ROI and save it as (prefix) tuna.lh ,
## then run this script.
## This script runs ROI2dataset to convert the tuna ROI into a
## surface dataset (NIML), and then runs 3dSurf2Vol to project
## that into the volume domain, filling the volxels between the
## smooth WM and pial surfaces.
## Afterwards, one could view the volume ROI in afni, 'talk' to
## suma, and see how the volume ROI maps back to the surface.
## ----------------------------------------------------------------------

# ------------------------------
# note input dataset name
if ( $#argv > 0 ) then
   set prefix = $argv[1]
   set prefix = tuna

# ------------------------------
# be sure input exists
if ( ! -f $prefix.lh.niml.roi ) then
   echo "** missing input dataset: $prefix.lh.niml.roi"
   echo "   please 'draw' in suma to create it (save -> $prefix.lh)"
   echo ""
   exit 1

# ------------------------------
# 1. convert to proper surface dataset (not ROI),
#    with only one value per node
# 2. map to volume

ROI2dataset -prefix $prefix.lh.niml.dset -input $prefix.lh.niml.roi

# consider also @surf_to_vol_spackle
3dSurf2Vol                      \
   -spec std.141.FT_lh.spec     \
   -surf_A smoothwm             \
   -surf_B pial                 \
   -sv FT_SurfVol.nii           \
   -grid_parent FT_SurfVol.nii  \
   -map_func mode               \
   -f_steps 12                  \
   -sdata $prefix.lh.niml.dset  \
   -prefix $prefix.lh.s2v.roi

if ( $status ) then
   echo "** failed 3dSurf2Vol"
   echo 1

echo ""
echo "++ created $prefix.lh.s2v.roi"
echo ""

You would have to convert each of those *.niml.roi files individually.


Thank you for giving me the information.

However, I do not want to average datasets. I just want to average ROI masks itself across the participants. We want to see how much the ROIs overlap across the participants.

Is there any way to do it?

You have to convert them to full datasets so that they have access to that information. After that, you can check about their overlap. I believe the *.niml.roi information is to sparse to know about other ROIs.


... and these two videos actually show how to display and calculate with overlapping ROIs:


Thank you so much!

I will go over the information you gave me.

I appreciate it.

Shinyoung Jung