@@ 290-304 (lines=15) @@ | ||
287 | transformed = aff(image) |
|
288 | assert all(n in (0, 1) for n in transformed.data.flatten()) |
|
289 | ||
290 | def test_no_inverse(self): |
|
291 | tensor = torch.zeros((1, 2, 2, 2)) |
|
292 | tensor[0, 1, 1, 1] = 1 # most RAS voxel |
|
293 | expected = torch.zeros((1, 2, 2, 2)) |
|
294 | expected[0, 0, 1, 1] = 1 |
|
295 | scales = 1, 1, 1 |
|
296 | degrees = 0, 0, 90 # anterior should go left |
|
297 | translation = 0, 0, 0 |
|
298 | apply_affine = tio.Affine( |
|
299 | scales, |
|
300 | degrees, |
|
301 | translation, |
|
302 | ) |
|
303 | transformed = apply_affine(tensor) |
|
304 | self.assert_tensor_almost_equal(transformed, expected) |
|
305 | ||
306 | def test_different_spaces(self): |
|
307 | t1 = self.sample_subject.t1 |
@@ 208-222 (lines=15) @@ | ||
205 | with pytest.raises(ValueError): |
|
206 | tio.RandomAffine(default_pad_label='minimum') |
|
207 | ||
208 | def test_no_inverse(self): |
|
209 | tensor = torch.zeros((1, 2, 2, 2)) |
|
210 | tensor[0, 1, 1, 1] = 1 # most RAS voxel |
|
211 | expected = torch.zeros((1, 2, 2, 2)) |
|
212 | expected[0, 0, 1, 1] = 1 |
|
213 | scales = 1, 1, 1 |
|
214 | degrees = 0, 0, 90 # anterior should go left |
|
215 | translation = 0, 0, 0 |
|
216 | apply_affine = tio.Affine( |
|
217 | scales, |
|
218 | degrees, |
|
219 | translation, |
|
220 | ) |
|
221 | transformed = apply_affine(tensor) |
|
222 | self.assert_tensor_almost_equal(transformed, expected) |
|
223 | ||
224 | def test_different_spaces(self): |
|
225 | t1 = self.sample_subject.t1 |