Last active
July 24, 2018 17:57
-
-
Save astromme/8116a154be8dae5528f33669e490c19a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
## Tensorflow image translation op | |
# images: A tensor of shape (num_images, num_rows, num_columns, num_channels) (NHWC), | |
# (num_rows, num_columns, num_channels) (HWC), or (num_rows, num_columns) (HW). | |
# tx: The translation in the x direction. | |
# ty: The translation in the y direction. | |
# interpolation: If x or y are not integers, interpolation comes into play. Options are 'NEAREST' or 'BILINEAR' | |
def tf_image_translate(images, tx, ty, interpolation='NEAREST'): | |
# got these parameters from solving the equations for pixel translations | |
# on https://www.tensorflow.org/api_docs/python/tf/contrib/image/transform | |
transforms = [1, 0, -tx, 0, 1, -ty, 0, 0] | |
return tf.contrib.image.transform(images, transforms, interpolation) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example use: