def test_value(self): key = "img" shifter = RandShiftIntensityd(keys=[key], offsets=1.0, prob=1.0) shifter.set_random_state(seed=0) result = shifter({key: self.imt}) np.random.seed(0) expected = self.imt + np.random.uniform(low=-1.0, high=1.0) np.testing.assert_allclose(result[key], expected)
def test_value(self): key = "img" for p in TEST_NDARRAYS: shifter = RandShiftIntensityd(keys=[key], offsets=1.0, prob=1.0) shifter.set_random_state(seed=0) result = shifter({key: p(self.imt)}) np.random.seed(0) # simulate the randomize() of transform np.random.random() expected = self.imt + np.random.uniform(low=-1.0, high=1.0) assert_allclose(result[key], p(expected))
def test_factor(self): key = "img" stats = IntensityStatsd(keys=key, ops="max", key_prefix="orig") shifter = RandShiftIntensityd(keys=[key], offsets=1.0, factor_key=["orig_max"], prob=1.0) data = {key: self.imt, key + "_meta_dict": {"affine": None}} shifter.set_random_state(seed=0) result = shifter(stats(data)) np.random.seed(0) # simulate the randomize() of transform np.random.random() expected = self.imt + np.random.uniform(low=-1.0, high=1.0) * np.nanmax(self.imt) np.testing.assert_allclose(result[key], expected)