Skip to content

Commit

Permalink
Improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
fepegar committed Sep 1, 2021
1 parent 761aac1 commit 2a9c091
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 12 additions & 0 deletions tests/transforms/preprocessing/test_resize.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import torch
import numpy as np
import torchio as tio
from ...utils import TorchioTestCase

Expand All @@ -17,3 +19,13 @@ def test_all_dims(self):
transformed = transform(self.sample_subject)
for image in transformed.get_images(intensity_only=False):
self.assertEqual(image.spatial_shape, target_shape)

def test_fix_shape(self):
# We use values that are known to need cropping
tensor = torch.rand(1, 8, 180, 320)
affine = np.diag((5, 1, 1, 1))
im = tio.ScalarImage(tensor=tensor, affine=affine)
target = 12
with self.assertWarns(UserWarning):
result = tio.Resize(target)(im)
self.assertEqual(result.spatial_shape, 3 * (target,))
4 changes: 3 additions & 1 deletion tests/transforms/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@ def get_transform(self, channels, is_3d=True, labels=True):
disp = 1 if is_3d else (1, 1, 0.01)
elastic = tio.RandomElasticDeformation(max_displacement=disp)
cp_args = (9, 21, 30) if is_3d else (21, 30, 1)
resize_args = (10, 20, 30) if is_3d else (10, 20, 1)
flip_axes = axes_downsample = (0, 1, 2) if is_3d else (0, 1)
swap_patch = (2, 3, 4) if is_3d else (3, 4, 1)
pad_args = (1, 2, 3, 0, 5, 6) if is_3d else (0, 0, 3, 0, 5, 6)
crop_args = (3, 2, 8, 0, 1, 4) if is_3d else (0, 0, 8, 0, 1, 4)
remapping = {1: 2, 2: 1, 3: 20, 4: 25}
transforms = [
tio.CropOrPad(cp_args),
tio.EnsureShapeMultiple(2, method='crop'),
tio.Resize(resize_args),
tio.ToCanonical(),
tio.RandomAnisotropy(downsampling=(1.75, 2), axes=axes_downsample),
tio.EnsureShapeMultiple(2, method='crop'),
tio.CopyAffine(channels[0]),
tio.Resample((1, 1.1, 1.25)),
tio.RandomFlip(axes=flip_axes, flip_probability=1),
Expand Down

0 comments on commit 2a9c091

Please sign in to comment.