Neuroimaging in Python — NiBabel 5.4.0.dev1+g3b1c7b37 documentation (original) (raw)

imagestats

Functions for computing image statistics

count_nonzero_voxels(img) Count number of non-zero voxels
mask_volume(img) Compute volume of mask image.

count_nonzero_voxels

nibabel.imagestats.count_nonzero_voxels(img)

Count number of non-zero voxels

Parameters:

imgSpatialImage

All voxels of the mask should be of value 1, background should have value 0.

Returns:

countint

Number of non-zero voxels

mask_volume

nibabel.imagestats.mask_volume(img)

Compute volume of mask image.

Equivalent to “fslstats /path/file.nii -V”

Parameters:

imgSpatialImage

All voxels of the mask should be of value 1, background should have value 0.

Returns:

volumefloat

Volume of mask expressed in mm3.

Examples

import numpy as np import nibabel as nb mask_data = np.zeros((20, 20, 20), dtype='u1') mask_data[5:15, 5:15, 5:15] = 1 nb.imagestats.mask_volume(nb.Nifti1Image(mask_data, np.eye(4))) 1000.0