Skip to content

Commit

Permalink
Add test for mask_default_cube
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaRenauld committed Mar 7, 2024
1 parent f5d8f99 commit 7827048
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
13 changes: 12 additions & 1 deletion scilpy/image/tests/test_volume_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

from scilpy.image.volume_operations import (flip_volume, crop_volume,
apply_transform, compute_snr,
resample_volume, register_image)
resample_volume, register_image,
mask_data_with_default_cube)
from scilpy.io.fetcher import fetch_data, get_testing_files_dict, get_home
from scilpy.utils.util import compute_nifti_bounding_box

Expand Down Expand Up @@ -165,3 +166,13 @@ def test_resample_volume():
resampled_img = resample_volume(moving3d_img, res=(2, 2, 2), interp='nn')

assert_equal(resampled_img.get_fdata(), ref3d)


def test_mask_data_with_default_cube():
data = np.ones((12, 12, 12))
out = mask_data_with_default_cube(data)
assert np.array_equal(data.shape, out.shape)
assert out[0, 0, 0] == 0
assert out[-1, -1, -1] == 0
assert out[6, 6, 6] == 1

11 changes: 6 additions & 5 deletions scilpy/image/volume_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,16 +535,17 @@ def resample_volume(img, ref=None, res=None, iso_min=False, zoom=None,
return nib.Nifti1Image(data2.astype(data.dtype), affine2)


def crop_data_with_default_cube(data):
""" Crop data with a default cube
Cube: data.shape/3 centered
def mask_data_with_default_cube(data):
"""Masks data outside a default cube (Cube: data.shape/3 centered)
Parameters
----------
data : 3D ndarray
Volume data.
data : np.ndarray
Volume data, 3D.
Returns
-------
data: np.ndarray
Data masked
"""
shape = np.array(data.shape[:3])
Expand Down
6 changes: 3 additions & 3 deletions scripts/scil_tractogram_fix_trk.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
import nibabel as nib
import numpy as np

from scilpy.image.volume_operations import crop_data_with_default_cube
from scilpy.image.volume_operations import mask_data_with_default_cube
from scilpy.io.utils import (add_bbox_arg,
add_verbose_arg,
add_overwrite_arg,
Expand Down Expand Up @@ -210,8 +210,8 @@ def main():
# Sometimes DSI studio has quite a lot of skull left
# Dipy Median Otsu does not work with FA/GFA
if args.auto_crop:
moving_data = crop_data_with_default_cube(moving_data)
static_data = crop_data_with_default_cube(static_data)
moving_data = mask_data_with_default_cube(moving_data)
static_data = mask_data_with_default_cube(static_data)

# Since DSI Studio register to AC/PC and does not save the
# transformation We must estimate the transformation,
Expand Down

0 comments on commit 7827048

Please sign in to comment.