def test_pad(self): image = self.sample_subject.t1 padding = 1, 2, 3, 4, 5, 6 sitk_image = image.as_sitk() low, high = padding[::2], padding[1::2] sitk_padded = sitk.ConstantPad(sitk_image, low, high, 0) tio_padded = tio.Pad(padding, padding_mode=0)(image) sitk_tensor, sitk_affine = sitk_to_nib(sitk_padded) tio_tensor, tio_affine = sitk_to_nib(tio_padded.as_sitk()) self.assertTensorEqual(sitk_tensor, tio_tensor) self.assertTensorEqual(sitk_affine, tio_affine)
def test_sitk_to_nib(self): data = np.random.rand(10, 12) image = sitk.GetImageFromArray(data) tensor, _ = io.sitk_to_nib(image) self.assertAlmostEqual(data.sum(), tensor.sum())
def sitk_to_nib(image: sitk.Image): return sitk_to_nib(image)