您的位置:首页 > 其它

tensorflow 图像数据处理

2017-09-22 17:00 246 查看
一、图像解编码、尺寸调整

       TensorFlow提供了常用图片格式(包括png和jpeg)的解码和编码操作,下面用一个jpg的图像演示:

          import matplotlib.pyplotas plt
          import tensorflowas tf

          image_raw_data = tf.gfile.FastGFile('.//image//img.jpg','rb').read()

          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()

               img_data = tf.image.convert_image_dtype(img_data,dtype = tf.float32)

               encoded_image = tf.image.encode_jpeg(img_data)

               with tf.gfile.GFile(".//image//img1.jpg","wb")as
f:

                    f.write(encoded_image.eval())

    tf.image.decode_jpeg为jpg解码过程,tf.image.encode_jpeg为jpg编码过程。

图像尺寸调整有三个函数:tf.image.resize_images、tf.image.resize_image_with_crop_or_pad、tf.image.central_crop。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: