Tensorflow学习笔记之存取图像文件
2017-06-28 14:40
225 查看
读图的时候是用 tensorflow 的函数,存图像用的 scipy.misc 的 imsave 函数。
因为在使用 tensorflow 的队列时对存图像大小的限制有疑问所以进行测试。
读取图像有128、256、512、1024大小的,存储时也试过这些像素,可见 scipy.misc.imsave 方法可以很容易的将 numpy 数据存成图像格式,且基本没有大小限制。
还有一种方法是用 Pillow 库的 Image 类存取图像:
因为在使用 tensorflow 的队列时对存图像大小的限制有疑问所以进行测试。
import tensorflow as tf import numpy as np import scipy.misc #读取图像可任意大小 filenames = ['img1.png','img2.png'] filename_queue = tf.train.string_input_producer(filenames) reader = tf.WholeFileReader() key,value = reader.read(filename_queue) images = tf.image.decode_png(value) #设置图像大小 newsize = tf.convert_to_tensor([256,256]) resized = tf.image.resize_images(images, newsize) print(resized) #输出是Tensor("Squeeze:0", shape=(256, 256, ?), dtype=float32) resized.set_shape([256,256,3]) print(resized) #输出是Tensor("Squeeze:0", shape=(256, 256, 3), dtype=float32) flipped_images = tf.image.flip_up_down(resized) print(flipped_images) #输出是Tensor("ReverseV2:0", shape=(256, 256, 3), dtype=float32) with tf.Session() as sess: coord = tf.train.Coordinator() threads = tf.train.start_queue_runners(coord=coord) init = tf.global_variables_initializer() sess.run(init) #reimg1的类型是<class 'numpy.ndarray'> reimg1 = flipped_images.eval() reimg2 = flipped_images.eval() scipy.misc.imsave('reimg1.png', reimg1) scipy.misc.imsave('reimg2.png', reimg2) coord.request_stop() coord.join(threads)
读取图像有128、256、512、1024大小的,存储时也试过这些像素,可见 scipy.misc.imsave 方法可以很容易的将 numpy 数据存成图像格式,且基本没有大小限制。
还有一种方法是用 Pillow 库的 Image 类存取图像:
from PIL import Image # 读取图像可任意大小 im = Image.open("img1.png") # 设定图像大小 im.thumbnail([256,256]) # 存储图像数据 im.save("img1-256x256.png")这个方法不灵活,因为存储数据必须是Image类的对象。
相关文章推荐
- [转载]MongoDB学习笔记(五) MongoDB文件存取操作
- 图像处理 基于Visual C++编程 学习笔记 (1)建立MFC工程,打开bmp文件
- TensorFlow的学习之路--创建图像训练所需的tfrecords文件
- 图像编程学习笔记1——bmp文件结构处理与显示
- 【深度学习】【caffe实用工具3】笔记25 Windows下caffe中将图像数据集合转换为DB(LMDB/LEVELDB)文件格式之convert_imageset
- tensorflow 学习笔记(十二)- 用别人训练好的模型来进行图像分类
- opencv学习笔记2--存取图像元素
- Tensorflow学习笔记--使用迁移学习做自己的图像分类器(Inception v3)
- python学习笔记6—文件操作来生成船只侧面图像的描述文件
- MongoDB学习笔记(五) MongoDB文件存取操作
- opencv学习笔记-加载图像(释疑:非mat类与mat类、头文件引用)
- Caffe学习笔记10:图像数据生成caffe需要的(laveldb和lmdb)数据文件
- opencv3编程入门学习笔记-----图像的载入、显示和输出到文件
- Tensorflow学习笔记-通过slim读取TFRecord文件
- TensorFlow学习笔记-图像预处理
- [学习笔记]基于ffmpeg的视频解码,输出YUV图像到文件。
- Tensorflow学习笔记:CNN篇(9)——Finetuning,复用ImageNet的VGGNet进行图像识别
- cpp整理学习笔记 文件I/O:随机存取fseek()和ftell()
- 图像编程学习笔记1——bmp文件结构处理与显示
- OpenCV学习笔记---- 挨个读取图像文件夹下的所有文件,进行样本训练