Esempio n. 1
0
def test_compose_rotate(dtype):
    image = tf.constant(
        [[1, 1, 1, 0], [1, 0, 0, 0], [1, 1, 1, 0], [0, 0, 0, 0]], dtype=dtype)
    # Rotate counter-clockwise by pi / 2.
    rotation = transform_ops.angles_to_projective_transforms(np.pi / 2, 4, 4)
    # Translate right by 1 (the transformation matrix is always inverted,
    # hence the -1).
    translation = tf.constant([1, 0, -1, 0, 1, 0, 0, 0], dtype=tf.float32)
    composed = transform_ops.compose_transforms([rotation, translation])
    image_transformed = transform_ops.transform(image, composed)
    np.testing.assert_equal(
        image_transformed.numpy(),
        [[0, 0, 0, 0], [0, 1, 0, 1], [0, 1, 0, 1], [0, 1, 1, 1]],
    )
Esempio n. 2
0
 def test_compose(self):
     for dtype in _DTYPES:
         image = tf.constant(
             [[1, 1, 1, 0], [1, 0, 0, 0], [1, 1, 1, 0], [0, 0, 0, 0]],
             dtype=dtype)
         # Rotate counter-clockwise by pi / 2.
         rotation = transform_ops.angles_to_projective_transforms(
             np.pi / 2, 4, 4)
         # Translate right by 1 (the transformation matrix is always inverted,
         # hence the -1).
         translation = tf.constant([1, 0, -1, 0, 1, 0, 0, 0],
                                   dtype=tf.dtypes.float32)
         composed = transform_ops.compose_transforms(rotation, translation)
         image_transformed = transform_ops.transform(image, composed)
         self.assertAllEqual(
             [[0, 0, 0, 0], [0, 1, 0, 1], [0, 1, 0, 1], [0, 1, 1, 1]],
             image_transformed)