python对jpeg图像的编码

matplotlib.pyplot是一个python的画图工具,当读取jpg格式的文件时,可以对图像进行解码,解码之后的结果是一个张量,利用程序输出解码之后的三维矩阵和重构出的解码后的图像,代码以及结果如下:

import tensorflow as tf
import matplotlib.pyplot as plt
sess = tf.Session()
# 加载一张彩色图像
image_filename = '97.jpg'
image_file = tf.gfile.FastGFile(image_filename,'rb').read()
# 解码
image1 = tf.image.decode_jpeg(image_file)
#print(image1.eval())
print(sess.run(image1))
#print(image.eval())
plt.imshow(sess.run(image1))
plt.show()

猜你喜欢

转载自blog.csdn.net/sy20173081277/article/details/82683762