List of clusters/ROIs

This is probably a very simple thing, but I can’t figure it out.

If I have a 3d data file with integer values only, how can I obtain a list of unique voxel values in the file or in a subbrick? For example, doing this to the standard segmentation produced by @animal_warper should output something like

If there was a way to extract any labels associated with the ROIs, that would be great too.
2 GM
3 scGM
4 WM

You can get that kind of information a few ways. There are two kinds of labels associated with ROIs - labels from a labeltable, labels from an atlas_point_list. Most atlases have both kinds. ROIs drawn with the Draw Dataset plugin will have a labeltable.

  1. 3dinfo -atlas_points atlasdset.nii.gz
  2. 3dinfo -labeltable labeldset.nii.gz
  3. whereami -atlas “atlasname” -show_atlas_code (if you leave out the “-atlas” option, all atlas regions are shown with their index codes)
  4. 3dROIstats automatically shows labels of regions included in the column headings

Thank you, this is very helpful.

Is there also method to extract such unique integer voxel values for a dataset that has no atlas point nor data table?

I think I should explain it better.

I am creating an atlas is a subset of the ARM atlas. ROIs that do not belong to the frontal lobe, temporal lobe, telecephalon, or diencephalon are removed. A mask covering these regions is created from subbrick 0, and the applied to all subbricks.

This done as follows (note - lateralization is removed earlier, corresponding L & R ROIs have the same codes at this point)

set frontal = 1
set temporal = 138
set telen = 1001
set dien = 1082

3dcalc -overwrite -a ${refatl}'[0]'    \
    -expr 'amongst(a, '${frontal}', '${temporal}', '${telen}', '${dien}')'    \
     -prefix ${dir_addatl}/IntBrain_mask

3dcalc -overwrite -a ${refatl} -b ${dir_addatl}/IntBrain_mask+tlrc                                  \
    -expr 'ifelse(b, a, 0)'   -prefix ${IntBrainUARM}

3drefit -copytables ${refatl} ${IntBrainUARM}+tlrc
3drefit -cmap INT_CMAP   ${IntBrainUARM}+tlrc

Because I am copying the tables from the original atlas, this preserves the labels for ROIs that do not exist anymore. So 3dinfo -atlas_points or 3dinfo -labeltable don’t work. I would like to obtain the list of ROI codes (and optionally their labels) of the ROIs that the new atlas still contains. Ideally as a simple text file. Is there a way to do it?

Apologies for talking to myself so much, but I think I almost got there

set nvi     = `3dinfo -nvi ${IntBrainUARM}`
foreach atlas_level ( `seq 0 1 ${nvi}` )

    3dROIstats -mask "${IntBrainUARM}+tlrc[${atlas_level}]" \
    -nomeanout -key \
    "${IntBrainUARM}+tlrc[${atlas_level}]" \
     > ${IntBrainUARM}_${atlas_level}_ROIs.txt


The format of the resulting files is still wrong for my purpose (rows instead of columns, some unnecessary info, each level preceded with Key_), but that’s a matter of reformatting, doable. Probably even in tcsh.

I’m not sure what you have against the full list of labels if you don’t use them, but assuming you want to make a “junior” atlas, you can do it with “@Atlasize -skip_novoxels”. The skip_novoxels just uses 3dBrickstat to find ROIs that have 0 voxels and leaves them. You have to provide a list of indices and labels. We have that list of course, but you can regenerate it.

The purpose is to use the labels externally in my Matlab scripts, this is why I want them in an external file, and why I want only keys and labels that were actually used by the atlas.

The original CHARM/ARM/SARM atlases come with text files listing keys and labels for each level, e.g. ARM_key_6.txt. I want to have something equivalent for my reduced atlas.

A cheating method to consider: use the output of, which is a supplementary program used by @animal_warper. Note: this “adjunct” program can change at any point at the cruel whim of developers (hence the ‘adjunct’ naming convention). But, it probably provides what you want.

If you have used @animal_warper (and you have!), you know that the QC/ dir contains report*.1D files about mapped atlas and template regions, to compare their before- and after-warping volumes. The output table looks something like this:

#  A atlas dset            : CHARM_in_sub-01_anat.nii.gz[4]
#  A mask dset             : sub-01_anat_mask.nii.gz
#  B atlas dset            : /data/demos/setup_MACAQUE_DEMO/MACAQUE_DEMO_REST/NMT_v2.1_sym/NMT_v2.1_sym_05mm/CHARM_in_NMT_v2.1_sym_05mm.nii.gz[4]
#  B mask dset             : /data/demos/setup_MACAQUE_DEMO/MACAQUE_DEMO_REST/NMT_v2.1_sym/NMT_v2.1_sym_05mm/NMT_v2.1_sym_05mm_brainmask.nii.gz
#  Mode_smooth size (nvox) : 1
#  A vox dims (mm)         : 0.500, 0.500, 0.500
#  B vox dims (mm)         : 0.500, 0.500, 0.500
#  A mask Nvox             :    800405
#  B mask Nvox             :    726796
#  A mask volume (mm^3)    :    100050.625
#  B mask volume (mm^3)    :     90849.500
#  MaskVol_A / MaskVol_B   :         1.101
#  A atlas Nroi            :       176
#  B atlas Nroi            :       176
#  Nroi difference         :         0
# ==========================================================================================================================================
# -- KEY --
#  ROI_value     = integer value of ROI
#  Nvox_A        = number of voxels in ROI in dset A
#  Nvox_B        = number of voxels in ROI in dset B
#  Vol_A         = ROI volume in dset A (mm^3)
#  Vol_B         = ROI volume in dset B (mm^3)
#  RelVol_A2B    = relative ROI volume, Vol_A / Vol_B
#  Frac_A        = ROI mask fraction, Vol_A / MaskVol_A
#  Frac_B        = ROI mask fraction, Vol_B / MaskVol_B
#  RelFrac_A2B   = relative ROI mask fraction, Frac_A / Frac_B
#  Label_str     = string label of ROI (if present)
# ==========================================================================================================================================
#    ROI_value        Nvox_A        Nvox_B         Vol_A         Vol_B    RelVol_A2B        Frac_A        Frac_B   RelFrac_A2B     Label_str
# ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------  ------------
             4           781           703        97.625        87.875         1.111     9.758e-04     9.673e-04         1.009  #  CL_area_32
             5           273           273        34.125        34.125         1.000     3.411e-04     3.756e-04         0.908  #  CL_area_25
             7           767           729        95.875        91.125         1.052     9.583e-04     1.003e-03         0.955  #  CL_area_24a/b
            10          1924          1589       240.500       198.625         1.211     2.404e-03     2.186e-03         1.099  #  CL_area_24c
            12           451           563        56.375        70.375         0.801     5.635e-04     7.746e-04         0.727  #  CL_area_24a/b_prime
            15          1283           930       160.375       116.250         1.380     1.603e-03     1.280e-03         1.253  #  CL_area_24c_prime
            18          1685          1821       210.625       227.625         0.925     2.105e-03     2.506e-03         0.840  #  CL_area_10
            22           515           538        64.375        67.250         0.957     6.434e-04     7.402e-04         0.869  #  CL_area_14
            27          1123          1104       140.375       138.000         1.017     1.403e-03     1.519e-03         0.924  #  CL_area_11
            30          3123          3327       390.375       415.875         0.939     3.902e-03     4.578e-03         0.852  #  CL_area_13
            34          1486          1189       185.750       148.625         1.250     1.857e-03     1.636e-03         1.135  #  CL_area_12m/o

Note how the first and last columns provide the info you want: the ROI value of any non-empty ROI and its string label, respectively.

The usage for the simple script is:

Takes >= 6 arguments: 
   1) an output file name;
   2) an (warped) atlas of interest, with subbrick selector, if necessary;
   3) a mask for the (warped) atlas (same grid)
   4) a reference atlas (i.e., same one but unwarped), with (same) 
      subbrick selector, if necessary.
   5) a mask for the reference atlas (same grid)
   6) a "modesmooth" value, from modal smoothing used after warping

So, you could use it like: OUTPUT.1D  DSET_ROI DSET_MASK DSET_ROI DSET_MASK 0

Note how DSET_ROI and DSET_MASK are duplicated (and yes, you need each—this is a simple program with non-optional usage of command line args). The final modesmooth value doesn’t matter in this case, so 0 should be fine.

After you output this, you could extract the first and last columns of non-commented values.


Hi Paul,

this seems like another great option, thank you. The good thing is that I don’t even need to run, I have these 1D files from animal_warper being run on an earlier stage. Probably the 1D files are easier to re-format than the output of 3dROIstats, but then the latter is guaranteed(?) to stay there. I’ll use one if these methods.