Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compute the volume of a single voxel of nifti medical image?

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.

like image 525
Carlao Avatar asked Feb 02 '26 22:02

Carlao


1 Answers

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³
like image 100
fepegar Avatar answered Feb 05 '26 12:02

fepegar