Skip to content

Instantly share code, notes, and snippets.

@lychrel
Created April 23, 2019 14:17
Show Gist options
  • Save lychrel/523020d03c4b61d2678421a6b4018536 to your computer and use it in GitHub Desktop.
Save lychrel/523020d03c4b61d2678421a6b4018536 to your computer and use it in GitHub Desktop.
convert a batch of images from RGB to greyscale
import tensorflow as tf
import numpy as np
def rgb2gray(rgb):
return np.dot(rgb[...,:3], [0.2989, 0.5870, 0.1140])
def batch_rgb2gray(rgb):
color = rgb
rgb_t = tf.transpose(rgb, [0, 2, 3, 1])
sess = tf.Session()
np_color = rgb_t
with sess.as_default():
rgb_np = rgb_t.eval()
grey = rgb2gray(rgb_np)
return grey
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment