<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Converting to Grayscale
Step1:  Resizing Images
Step2:  Scaling Pixel Values
Step3:  Putting it Together - Making a Image Preprocessing Pipeline
<ASSISTANT_TASK:>
Python Code:
# reshape is needed so we can use plt.imshow
rgb_to_gray = tf.reshape(tf.image.rgb_to_grayscale(ob), [ob.shape[0], ob.shape[1]])
gray_ob = rgb_to_gray.eval()
gray_ob.shape, gray_ob.dtype
plt.gray()
plt.imshow(gray_ob)
Explanation: Converting to Grayscale
End of explanation
# let's get the current ratio
from __future__ import division
ratio = ob.shape[0] / ob.shape[1]
print ratio
def resize_op(img, h, w):
    resized_ob = tf.image.resize_bilinear(tf.reshape(ob, [1, ob.shape[0], ob.shape[1], ob.shape[2]]), [h,w ])
    return tf.reshape(resized_ob, [h, w, 3])
# 84 x 84 is the size of the img used in the original DQN paper, 21168 or 7056 (grayscale) points per img
plt.imshow(resize_op(ob, 84, 84).eval())
w = 40
h = int(w * ratio)
rgb_pixels = 3 * h * w
grayscale_pixels = h * w
print 'height =', h, 'width =', w
print 'pixels with rgb =', rgb_pixels, 'grayscale =', grayscale_pixels
plt.imshow(resize_op(ob, h, w).eval())
Explanation: Resizing Images
End of explanation
scaled_ob = tf.image.convert_image_dtype(ob, tf.float32, saturate=True).eval()
print scaled_ob.min(), scaled_ob.max()
np.unique(ob)
np.unique(gray_ob)
np.unique(scaled_ob)
Explanation: Scaling Pixel Values
End of explanation
# assumes img.shape is (batch_size, h, w, c)
def img_preprocess(img, h, w):
    img = tf.convert_to_tensor(img)
    rgb2y = tf.image.rgb_to_grayscale(img)
    resized = tf.image.resize_bilinear(rgb2y, [h, w])
    return resized
obs = np.reshape(ob, [1] + list(ob.shape))
obs.shape
preprocessed_img = img_preprocess(obs, 84, 84).eval()
plt.gray()
plt.imshow(preprocessed_img.reshape(84, 84))
Explanation: Putting it Together - Making a Image Preprocessing Pipeline
End of explanation
<END_TASK>