tensorflow图像数据处理
2018-03-20 23:21
471 查看
今天学到tensorflow图像数据处理,所以写个笔记。
import tensorflow as tf
import numpy as np
tf.image.resize_images函数的method参数取值对应不同的图像大小调整算法
1 首先是导入库
import matplotlib.pyplot as pltimport tensorflow as tf
import numpy as np
2 读取图片
image_raw_data = tf.gfile.FastGFile('../datasets/cat.jpg','rb').read() with tf.Session() as sess: img_data = tf.image.decode_jpeg(image_raw_data) # 输出解码之后的三维矩阵。 print (img_data.eval()) img_data.set_shape([1797, 2673, 3]) print (img_data.get_shape())用的python3。读的是一个猫的图片其shape是(1797, 2673, 3)。
3 打印图片
with tf.Session() as sess: plt.imshow(img_data.eval()) plt.show()
4 调整图像大小
with tf.Session() as sess: resized = tf.image.resize_images(img_data, [300, 300], method=0) # TensorFlow的函数处理图片后存储的数据是float32格式的,需要转换成uint8才能正确打印图片。 print ("Digital type: ", resized.dtype) cat = np.asarray(resized.eval(), dtype='uint8') # tf.image.convert_image_dtype(rgb_image, tf.float32) plt.imshow(cat) plt.show()其核心是tf.image.resize_images函数。通过上面程序,图片被调整成为300×300的。tf.image.resize_images函数的method参数取值对应不同的图像大小调整算法,如下表
|
相关文章推荐
- tensorflow 图像数据处理(二)
- TensorFlow:实战Google深度学习框架(六)图像数据处理
- tensorflow处理自己的图像数据(不使用队列)
- Tensorflow图像预处理,Numpy读取数据踩坑
- tensorflow 图像数据处理
- tensorflow 图像数据处理(一)
- 深度学习框架Tensorflow学习与应用 图像数据处理之一
- 深度学习框架Tensorflow学习与应用 图像数据处理之二
- TensorFlow图像数据处理
- Tensorflow--图像数据处理
- TensorFlow输入数据处理框架
- TensorFlow学习(十):图像预处理
- 【图像处理】提取图片中的交点数据 [已删除]
- TensorFlow 图像数据预处理及可视化
- 使用TensorFlow进行常用的图像处理-图像转为矩阵以及图像大小调整
- Tensorflow 处理libsvm格式数据生成TFRecord (parse libsvm data to TFRecord)
- JDBC处理大数据(存储图像、声音、二进制)
- TensorFlow学习--tensorflow图像处理--图像翻转及大小色彩调整
- Kreas 训练自己的图像数据处理回归问题
- Cimage类处理图像像素(数据)的3种方式