Passed
Push — master ( c291a8...879ee9 )
by Fernando
59s
created

TestToCanonical.test_no_changes()   A

Complexity

Conditions 1

Size

Total Lines 5
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
import numpy as np
2
from numpy.testing import assert_array_equal
3
from torchio.transforms import ToCanonical
4
from ...utils import TorchioTestCase
5
6
7
class TestToCanonical(TorchioTestCase):
8
    """Tests for :py:class:`ToCanonical` class."""
9
10
    def test_no_changes(self):
11
        transform = ToCanonical()
12
        transformed = transform(self.sample)
13
        assert_array_equal(transformed.t1.data, self.sample.t1.data)
14
        assert_array_equal(transformed.t1.affine, self.sample.t1.affine)
15
16
    def test_LAS_to_RAS(self):
17
        self.sample.t1.affine[0, 0] = -1    # Change orientation to 'LAS'
18
        transform = ToCanonical()
19
        transformed = transform(self.sample)
20
        self.assertEqual(transformed.t1.orientation, ('R', 'A', 'S'))
21
        assert_array_equal(
22
            transformed.t1.data,
23
            self.sample.t1.data.numpy()[:, ::-1, :, :]
24
        )
25
26
        fixture = np.eye(4)
27
        fixture[0, -1] = -self.sample.t1.spatial_shape[0] + 1
28
        assert_array_equal(transformed.t1.affine, fixture)
29