Masks

Hi AFNI experts.

I have a few striatal masks that were generated from a probabalistic atlas thresholded at 60%. Now, I want to make sure that each voxel is assigned to only one mask…so each voxel is assigned to the one that it had the highest likelihood of belonging to. I am sure this is something that I can do with a 3dcalc function/functions but was not 100% sure which function/functions might do this for me!

Thanks,

Emily

Hi, Emily-

I will assume that each “mask” file actually still has the probability value in it-- that isn’t just a binary map.

First, you can provide the set of files to 3dTcat to make a single, 4D data set. Then, use 3dTstat to make a mask where there are nonzero voxels at any point across time; finally, provide the concatenated dataset and mask to 3dTstat, and have it make a new dataset whose values tell you which brick contains the maximum value across “time” at each voxel (Note that I have now edited my answer to correct it, as per my next message in this thread; apologies for confusion. --pt):


# concatenate data sets of interest
3dTcat -prefix ALLCAT.nii.gz  DSET1 DSET2 DSET3 ...
# make a mask of anywhere that is nonzero across the original data sets
3dTstat -nzcount -prefix MMM.nii.gz ALLCAT.nii.gz
# find the volume index+1 of the subbrick with the maximum value, per voxel
3dTstat -argmax1 -mask MMM.nii.gz -prefix MAP  ALLCAT.nii.gz

Note tthe use of argmax1: This is because AFNI starts counting from zero (as all great programs do!), and if the [0]th volume contains the maximum, then it would put a zero at that voxel, which would be indistinguishable from the hoi polloi of the great empty voxels. So, wherever there is a “1” in the final MAP dset, that is where the [0]th volume in the list had greatest value; wherever there is a “2”, the [1]st volume had the max value, etc.

–pt

Similar advice with a little variant that can use “argmax” if you use the slightly tricky way of adding in a zero volume at the beginning.

http://blog.cogneurostats.com/?p=466
https://afni.nimh.nih.gov/afni/community/board/read.php?1,147688,147693#msg-147693

Actually, I see that I made a mistake in my previous code listing: I forgot to use the mask MMM.nii.gz that was created in the 2nd command in the third command… whoops! This is what should have been written initially (and I will edit my previous answer to be correct and match this, so that future generations are not thrown off by my error):


# concatenate data sets of interest
3dTcat -prefix ALLCAT.nii.gz  DSET1 DSET2 DSET3 ...
# make a mask of anywhere that is nonzero across the original data sets
3dTstat -nzcount -prefix MMM.nii.gz ALLCAT.nii.gz
# find the volume index+1 of the subbrick with the maximum value within the mask, per voxel
3dTstat -argmax1 -mask MMM.nii.gz -prefix MAP  ALLCAT.nii.gz

–pt