Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tensorflow as tf
- import numpy as np
- import matplotlib.pyplot as plt
- from PIL import Image
- def load_image(filename):
- image = Image.open(filename)
- image.load()
- data = np.asarray(image, dtype="uint8")
- return data
- def to_image(data):
- image = Image.fromarray(data)
- return image
- r = tf.placeholder(dtype=tf.float32, shape=[None, None])
- g = tf.placeholder(dtype=tf.float32, shape=[None, None])
- b = tf.placeholder(dtype=tf.float32, shape=[None, None])
- d = tf.placeholder(dtype=tf.float32, shape=None)
- out = (0.3*r + 0.59*g + 0.11*b) * d / 255
- img = load_image("HappyFish.jpg")
- img_ = Image.open("HappyFish.jpg")
- with tf.Session() as sess:
- plt.subplot(1, 2, 1)
- plt.imshow(to_image(img))
- plt.title("Original")
- plt.subplot(1, 2, 2)
- plt.title("Grayscaled")
- plt.imshow(to_image(sess.run(out, feed_dict={r: img_.split()[0], g: img_.split()[1], b: img_.split()[2], d: 255})))
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement