def test_inverse_compose(self): transform = Compose( [ Resized(keys="img", spatial_size=[100, 100, 100]), OneOf( [ RandScaleIntensityd(keys="img", factors=0.5, prob=1.0), RandShiftIntensityd(keys="img", offsets=0.5, prob=1.0), ] ), ] ) transform.set_random_state(seed=0) result = transform({"img": np.ones((1, 101, 102, 103))}) result = transform.inverse(result) # invert to the original spatial shape self.assertTupleEqual(result["img"].shape, (1, 101, 102, 103))
def test_random_compose(self): class _Acc(Randomizable): self.rand = 0.0 def randomize(self): self.rand = self.R.rand() def __call__(self, data): self.randomize() return self.rand + data c = Compose([_Acc(), _Acc()]) self.assertNotAlmostEqual(c(0), c(0)) c.set_random_state(123) self.assertAlmostEqual(c(1), 2.39293837) c.set_random_state(223) c.randomize() self.assertAlmostEqual(c(1), 2.57673391)