Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tensorflow as tf
- import matplotlib.image as mpimg
- filename = "MarshOrchid.jpg"
- raw_image_data = mpimg.imread(filename)
- image = tf.placeholder("uint8", [None, None, 3])
- # Reduce axis 2 by mean (= color)
- # i.e. image = [[[r,g,b], ...]]
- # out = [[[ grayvalue ], ... ]] where grayvalue = mean(r, g, b)
- out = tf.reduce_mean(image, 2, keep_dims=True)
- # Associate r,g,b to the same mean value = concat mean on axis 2.
- # out = [[[ grayvalu, grayvalue, grayvalue], ...]]
- out = tf.concat(2, [out, out, out])
- with tf.Session() as session:
- result = session.run(out, feed_dict={image: raw_image_data})
- print(result.shape)
- plt.imshow(result)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement