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
October 22, 2010 12:34PM
Okay, let's take for example an anatomical dataset, anat_partialamy+tlrc, that has had a small number of voxels set to 0 within the amygdala, just for demonstration purposes here, but the majority of the region still has non-zero voxels. Consider the following commands that all accomplish some sort of counting of the voxels within the amygdala.

The simplest way is to do this. Use 3dBrickStat to count all voxels that lie within the mask. Include all voxels (zero or non-zero). Note the amygdala mask dataset is automatically extracted from the atlas dataset in your afni binary directory with both left and right included.

% 3dBrickStat -count -mask 'TT_Daemon::amygdala' anat_partialamy+tlrc
2296

Strictly speaking though, we don't even need the dataset to do this, just our mask dataset. We could just count the number of voxels in the amygdala mask itself.

This counts all the voxels in the mask dataset including non-zeros, so not what you want.
% 3dBrickStat -count 'TT_Daemon::amygdala'
4643401

Instead, count the non-zero voxels in the mask:
% 3dBrickStat -count -non-zero 'TT_Daemon::amygdala'
2296

Now, if you want to count a voxel if it is non-zero in the dataset and within the mask, this command would work. Note the lower number of voxels than the previous results:
% 3dBrickStat -count -non-zero -mask 'TT_Daemon::amygdala' anat_partialamy+tlrc
2268

If it's clearer to you, you can apply the mask to the dataset with 3dcalc. Here, applying the mask means leave voxels in an output dataset where there is non-zero value in the mask.
% 3dcalc -a anat_partialamy+tlrc -b 'TT_Daemon::amygdala' -expr 'a*step(b)' \
-prefix anat_p_amy
++ 3dcalc: AFNI version=AFNI_2009_12_31_1431 (Sep 29 2010) [64-bit]
++ Authored by: A cast of thousands
++ Output dataset ./anat_p_amy+tlrc.BRIK

Then count the non-zero voxels in the masked dataset. These voxels would be non-zero from the original dataset and the mask dataset.
% 3dBrickStat -count -non-zero anat_p_amy+tlrc.
2268

Note you can also get the volume of the non-zero voxels this way. This is just a multiplication of the number of voxels by the voxel size to give a result in ul.
% 3dBrickStat -volume -non-zero anat_p_amy+tlrc.
2268.000000

3dBrickStat is not the only command to count voxels. 3dmaskave and 3dROIstats also do this.
% 3dmaskave -quiet -mask 'TT_Daemon::amygdala' anat_partialamy+tlrc
++ 3dmaskave: AFNI version=AFNI_2009_12_31_1431 (Sep 29 2010) [64-bit]
+++ 2296 voxels survive the mask
762.308
% 3dROIstats -nzvoxels -mask 'TT_Daemon::amygdala' anat_partialamy+tlrc
File Sub-brick Mean_71 NZcount_71
anat_partialamy+tlrc 0[#0] 762.307927 2268
Subject Author Posted

Count of voxels in a mask in a specific region.

Binu Varghese October 21, 2010 06:14PM

Re: Count of voxels in a mask in a specific region.

Daniel Glen October 21, 2010 06:22PM

Re: Count of voxels in a mask in a specific region.

Binu Varghese October 22, 2010 07:38AM

Re: Count of voxels in a mask in a specific region.

Daniel Glen October 22, 2010 12:34PM

Re: Count of voxels in a mask in a specific region.

Binu Varghese October 22, 2010 01:40PM

Re: Count of voxels in a mask in a specific region.

Daniel Glen October 22, 2010 02:11PM