Skip to content

Instantly share code, notes, and snippets.

@Prasad9
Last active October 21, 2017 03:41
Show Gist options
  • Save Prasad9/b042cb649c62d7ee13e6a25bdc17f103 to your computer and use it in GitHub Desktop.
Save Prasad9/b042cb649c62d7ee13e6a25bdc17f103 to your computer and use it in GitHub Desktop.
Tensorflow framework code to flip images left-right, up-down and transpose.
def flip_images(X_imgs):
X_flip = []
tf.reset_default_graph()
X = tf.placeholder(tf.float32, shape = (IMAGE_SIZE, IMAGE_SIZE, 3))
tf_img1 = tf.image.flip_left_right(X)
tf_img2 = tf.image.flip_up_down(X)
tf_img3 = tf.image.transpose_image(X)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
for img in X_imgs:
flipped_imgs = sess.run([tf_img1, tf_img2, tf_img3], feed_dict = {X: img})
X_flip.extend(flipped_imgs)
X_flip = np.array(X_flip, dtype = np.float32)
return X_flip
flipped_images = flip_images(X_imgs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment