Extract volume based on subcortical mask from recon-all output

Hi all!

I have a dataset where recon-all was already calculated, and I have a subcortical mask for auditory structures that is in MNI space. Is there any way to extract the volume of these subcortical structures in the already processed brains? If not, what would be the best tool to do this?


First of all, freesurfer outputs a stats file for you, so if the masks were calculated by running recon-all, then you just got to look at the stats files inside the $SUBJECTS_DIR/$SUBJECT_ID/stats folder.

If you just want the complete volume of all nonzero voxels you can run

fslstats $DATA -V

If you want the volume of each structure from any random nifti where each structure is coded by a different number, you can run a variation of (python for simplicity):

import nibabel as nib
import numpy as np
from collections import Counter

data = nib.load("nifti.nii")
voxelvol_mm3 = np.prod(data.header["pixdim"][1:4])

for roi, nvoxels in Counter(data.get_fdata().flat).items():
    print(f"ROI {roi} volume is {nvoxels * voxelvol_mm3} mm^3")
1 Like