Skip to content

Instantly share code, notes, and snippets.

@Prasad9
Created October 20, 2017 21:59
Show Gist options
  • Save Prasad9/217374ad687bc284eb147c1a776c4758 to your computer and use it in GitHub Desktop.
Save Prasad9/217374ad687bc284eb147c1a776c4758 to your computer and use it in GitHub Desktop.
Tensorflow framework code to rotate image at 90, 180 and 270 degrees
def rotate_images(X_imgs):
X_rotate = []
tf.reset_default_graph()
X = tf.placeholder(tf.float32, shape = (IMAGE_SIZE, IMAGE_SIZE, 3))
k = tf.placeholder(tf.int32)
tf_img = tf.image.rot90(X, k = k)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
for img in X_imgs:
for i in range(3): # Rotation at 90, 180 and 270 degrees
rotated_img = sess.run(tf_img, feed_dict = {X: img, k: i + 1})
X_rotate.append(rotated_img)
X_rotate = np.array(X_rotate, dtype = np.float32)
return X_rotate
rotated_imgs = rotate_images(X_imgs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment