tensorflow 读图并显示

#!/usr/bin/env python
# @Time    : 2019/10/26 11:59
# @File    : f102601.py
import pylab

import tensorflow as tf



import numpy as np

import  matplotlib.pyplot as plt

image_raw_data_jpg= tf.io.gfile.GFile(r'C:\Users\Administrator\Desktop\test\cat\c1.jpg','rb').read()

with tf.compat.v1.Session() as sess:        #这种情况下不能用tensor.numpy()
    img= tf.image.decode_jpeg(image_raw_data_jpg,channels=3)
    #开重新保存的,说明下图片是网上下载的数据集,于是我猜测可能图片本身就是多通道的,但是由于收集图片的人使用

    #编辑器的问题,导致图像不是真实的通道,试将decode_jpeg里的channel=1改为channel=3
    # img= tf.image.convert_image_dtype(img_data_jpg,dtype=tf.uint8)
    plt.figure() #图像显示
    # img = tf.image.decode_jpeg(img)
    # img_data_jpg=img.numpy()
    # img_data_jpg=tf.reshape(img_data_jpg,[100,200])
    print((img.eval()).shape)
    plt.imshow(img.eval()) #调用.eval()该张量对象应返回一个numpy ndarray
    plt.show()

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值