I have loaded a nifti image file using nibabel tool and I have played with some properties. But I don’t have idea how to compute the volume (in mm³) of a single voxel.
Here's the answer using NiBabel, as OP asked:
>>> import nibabel as nib
>>> nii = nib.load('t1.nii.gz')
>>> sx, sy, sz = nii.header.get_zooms()
>>> volume = sx * sy * sz
>>> spatial_unit, _ = header.get_xyzt_units()
>>> print(f"Volume: {volume:.2f} {spatial_unit}³")
Volume: 1.45 mm³
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With