Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. import tensorflow as tf
  2. import matplotlib.image as mpimg
  3.  
  4. filename = "MarshOrchid.jpg"
  5. raw_image_data = mpimg.imread(filename)
  6.  
  7. image = tf.placeholder("uint8", [None, None, 3])
  8.  
  9. # Reduce axis 2 by mean (= color)
  10. # i.e. image = [[[r,g,b], ...]]
  11. # out = [[[ grayvalue ], ... ]] where grayvalue = mean(r, g, b)
  12. out = tf.reduce_mean(image, 2, keep_dims=True)
  13.  
  14. # Associate r,g,b to the same mean value = concat mean on axis 2.
  15. # out = [[[ grayvalu, grayvalue, grayvalue], ...]]
  16. out = tf.concat(2, [out, out, out])
  17.  
  18. with tf.Session() as session:
  19. result = session.run(out, feed_dict={image: raw_image_data})
  20.  
  21. print(result.shape)
  22. plt.imshow(result)
  23. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement