def test_ExtrapolationMirror(self):
   with self.session():
     src = np.array([[[0], [1], [2], [3], [4]]]).astype(np.float32)
     deform = np.array([[[0, -10], [0, -9], [0, -8], [0, -7], [0, -6],
                         [0, -5], [0, -4], [0, -3], [0, -2], [0, -1], [0, 0],
                         [0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6],
                         [0, 7], [0, 8], [0, 9], [0, 10]]]).astype(np.float32)
     trg = augmentation_ops.apply_deformation2d(
         src, deform, []).eval()
     self.assertAllEqual(
         np.array([[[2], [1], [0], [1], [2], [3], [4], [3], [2], [1], [0],
                    [1], [2], [3], [4], [3], [2], [1], [0], [1], [2]]]), trg)
 def test_ExtrapolationZero(self):
   with self.session():
     src = np.array([[[10], [11], [12], [13], [14]]]).astype(np.float32)
     deform = np.array([[[0, -10], [0, -9], [0, -8], [0, -7], [0, -6],
                         [0, -5], [0, -4], [0, -3], [0, -2], [0, -1], [0, 0],
                         [0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6],
                         [0, 7], [0, 8], [0, 9], [0, 10]]]).astype(np.float32)
     trg = augmentation_ops.apply_deformation2d(
         src, deform, [], extrapolation="zero_padding").eval()
     self.assertAllEqual(
         np.array([[[0], [0], [0], [0], [0], [0], [0], [0], [0], [0], [10],
                    [11], [12], [13], [14], [0], [0], [0], [0], [0], [0]]]),
         trg)
Exemplo n.º 3
0
    def test_IdentityTransform(self):
        with self.session():
            src = np.random.random([10, 7, 3]).astype(np.float32)
            deformation = np.ndarray([10, 7, 2], dtype=np.float32)

            for x0 in range(deformation.shape[0]):
                for x1 in range(deformation.shape[1]):
                    deformation[x0, x1, 0] = x0
                    deformation[x0, x1, 1] = x1

            result = augmentation_ops.apply_deformation2d(src, deformation, [])
            self.assertEqual(result.get_shape(), src.shape)
            trg = result.eval()

            self.assertAllEqual(trg, src)
  def test_ExtrapolationConstMultichannel(self):
    with self.session():
      src = np.array([[[10, 9, 8, 7], [11, 10, 9, 8], [12, 11, 10, 9],
                       [13, 12, 11, 10], [14, 13, 12, 11]]]).astype(np.float32)
      deform = np.array([[[0, -10], [0, -9], [0, -8], [0, -7], [0, -6],
                          [0, -5], [0, -4], [0, -3], [0, -2], [0, -1], [0, 0],
                          [0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6],
                          [0, 7], [0, 8], [0, 9], [0, 10]]]).astype(np.float32)
      trg = augmentation_ops.apply_deformation2d(
          src,
          deform,

          extrapolation="const_padding",
          padding_constant=np.array([1, 2, 3, 4])).eval()
      self.assertAllEqual(
          np.array([[[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4],
                     [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4],
                     [1, 2, 3, 4], [1, 2, 3, 4], [10, 9, 8, 7], [11, 10, 9, 8],
                     [12, 11, 10, 9], [13, 12, 11, 10], [14, 13, 12, 11],
                     [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4],
                     [1, 2, 3, 4], [1, 2, 3, 4]]]), trg)