#jpeg解码和编码
import matplotlib.pyplot as plt
image_raw_data=tf.gfile.FastGFile("pic/ma.jpg","rb").read() #读图 图片不是utf8编码的话,就需要改成rb而不是r
with tf.Session() as sess:
img_data=tf.image.decode_jpeg(image_raw_data) #解码
print(img_data.eval())
plt.imshow(img_data.eval()) #展示
plt.show()
encoded_image=tf.image.encode_jpeg(img_data)
with tf.gfile.GFile("pic/output_ma.jpg","wb")as f: #编码再写入
f.write(encoded_image.eval())
Tensorflow图像预处理(1)解码和编码
最新推荐文章于 2021-11-02 11:00:07 发布