Beispiel #1
0
 def test_value(self):
     key = "img"
     factor = np.random.rand()
     offset = np.std(self.imt) * factor
     shifter = ShiftIntensityd(keys=[key], offset=offset)
     expected = shifter({key: self.imt})
     std_shifter = StdShiftIntensityd(keys=[key], factor=factor)
     result = std_shifter({key: self.imt})
     np.testing.assert_allclose(result[key], expected[key], rtol=1e-5)
Beispiel #2
0
 def test_dtype(self):
     key = "img"
     trans_dtype = np.float32
     for dtype in [int, np.float32, np.float64]:
         image = np.random.rand(2, 2, 2).astype(dtype)
         factor = np.random.rand()
         std_shifter = StdShiftIntensityd(keys=[key],
                                          factor=factor,
                                          dtype=trans_dtype)
         result = std_shifter({key: image})
         np.testing.assert_equal(result[key].dtype, trans_dtype)
Beispiel #3
0
 def test_nonzero(self):
     key = "img"
     image = np.asarray([[4.0, 0.0, 2.0], [0, 2, 4]])  # std = 1
     factor = np.random.rand()
     std_shifter = StdShiftIntensityd(keys=[key],
                                      factor=factor,
                                      nonzero=True)
     result = std_shifter({key: image})
     expected = np.asarray([[4 + factor, 0, 2 + factor],
                            [0, 2 + factor, 4 + factor]])
     np.testing.assert_allclose(result[key], expected, rtol=1e-5)
Beispiel #4
0
 def test_zerostd(self):
     key = "img"
     image = np.ones([2, 3, 3])
     for nonzero in [True, False]:
         for channel_wise in [True, False]:
             factor = np.random.rand()
             std_shifter = StdShiftIntensityd(keys=[key],
                                              factor=factor,
                                              nonzero=nonzero,
                                              channel_wise=channel_wise)
             result = std_shifter({key: image})
             np.testing.assert_allclose(result[key], image, rtol=1e-5)
Beispiel #5
0
 def test_channel_wise(self):
     key = "img"
     image = np.stack(
         (np.asarray([1.0, 2.0]), np.asarray([1.0, 1.0])))  # std: 0.5, 0
     factor = np.random.rand()
     std_shifter = StdShiftIntensityd(keys=[key],
                                      factor=factor,
                                      channel_wise=True)
     result = std_shifter({key: image})
     expected = np.stack((np.asarray([1 + 0.5 * factor,
                                      2 + 0.5 * factor]), np.asarray([1,
                                                                      1])))
     np.testing.assert_allclose(result[key], expected, rtol=1e-5)