tf读取灰度图片

1.tensorflow 读取 图片并灰度化

    with tf.Session() as sess:
        img = tf.read_file(imgfile) #读取图片,
        img_data = tf.image.decode_jpeg(img, channels=3) #解码
        #img_data = sess.run(tf.image.decode_jpeg(img, channels=3))
        img_data = sess.run(tf.image.rgb_to_grayscale(img_data)) #灰度化
        print('大小:{}'.format(img_data.shape))
        print("类型:%s" % type(img_data))
        print(img_data)

这里其实有个要注意的,不同于PIL.image 和 cv 的图片读取,这里会带上通道!

 

posted @ 2019-10-15 11:03  闪存第一菜鸡  阅读(455)  评论(0)    收藏  举报