Skip to content

NF: volume computation function for nifti masks #952

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Oct 20, 2020
Prev Previous commit
Next Next commit
Apply suggestions from code review
Co-authored-by: Chris Markiewicz <[email protected]>
  • Loading branch information
JulianKlug and effigies authored Oct 19, 2020
commit 2331e9d33677cb7fb14eec84d925b7dd18cce740
6 changes: 4 additions & 2 deletions nibabel/imagestats.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,23 @@
def count_nonzero_voxels(img):
"""
Count number of non-zero voxels

Parameters
----------
img : ``SpatialImage``
All voxels of the mask should be of value 1, background should have value 0.

Returns
-------
non zero voxel volume: int
count : int
Number of non-zero voxels

"""
return np.count_nonzero(img.dataobj)

def mask_volume(img):
""" Compute volume of mask image.

Equivalent to "fslstats /path/file.nii -V"

Parameters
Expand All @@ -41,7 +43,7 @@ def mask_volume(img):

Returns
-------
mask_volume_mm3: float
volume : float
Volume of mask expressed in mm3.

Examples
Expand Down
3 changes: 0 additions & 3 deletions nibabel/tests/test_imagestats.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
from .. import imagestats
from .. import Nifti1Image

import pytest


def test_mask_volume():
# Test mask volume computation
Expand All @@ -28,4 +26,3 @@ def test_mask_volume():

assert vol_mm3 == 1000.0
assert vol_vox == 1000