Created
April 23, 2019 14:17
-
-
Save lychrel/523020d03c4b61d2678421a6b4018536 to your computer and use it in GitHub Desktop.
convert a batch of images from RGB to greyscale
This file contains hidden or 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 | |
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