如何在 TensorFlow 中绘制调整大小的图像?
How do I draw a resized image in TensorFlow?
在应用任何变换(例如调整大小)后,TensorFlow 中的图像似乎会变换到另一种图像坐标系。绘制图像结果如下:
%matplotlib inline
import tensorflow as tf
from matplotlib import pyplot as plt
with tf.device("/cpu:0"):
file_contents = tf.read_file('any_image.png')
image = tf.image.decode_png(file_contents)
image.set_shape([375, 1242, 3])
image = tf.image.resize_images(image, 448, 448)
with tf.Session() as sess:
sess.run(tf.initialize_all_variables())
image_val = sess.run([image])
plt.figure(figsize=(16, 8))
plt.imshow(image_val[0], interpolation='nearest')
plt.show()
plt.close()
如果我删除调整大小操作,它会绘制常规图像。如何让 matplotlib 正确绘制调整后的图像或告诉 Tensorflow return 将其转为 RGB?
好像除了无符号整数浮点数之外没有图像变换。转换回无符号整数解决了问题。
plt.imshow(image_val[0].astype(np.uint8), interpolation='nearest')
在应用任何变换(例如调整大小)后,TensorFlow 中的图像似乎会变换到另一种图像坐标系。绘制图像结果如下:
%matplotlib inline
import tensorflow as tf
from matplotlib import pyplot as plt
with tf.device("/cpu:0"):
file_contents = tf.read_file('any_image.png')
image = tf.image.decode_png(file_contents)
image.set_shape([375, 1242, 3])
image = tf.image.resize_images(image, 448, 448)
with tf.Session() as sess:
sess.run(tf.initialize_all_variables())
image_val = sess.run([image])
plt.figure(figsize=(16, 8))
plt.imshow(image_val[0], interpolation='nearest')
plt.show()
plt.close()
如果我删除调整大小操作,它会绘制常规图像。如何让 matplotlib 正确绘制调整后的图像或告诉 Tensorflow return 将其转为 RGB?
好像除了无符号整数浮点数之外没有图像变换。转换回无符号整数解决了问题。
plt.imshow(image_val[0].astype(np.uint8), interpolation='nearest')