Tensorflow学习笔记之存取图像文件

这篇博客探讨了使用TensorFlow读取图像并利用scipy.misc.imsave函数保存图像的过程。博主测试了不同尺寸的图像,确认imsave函数在保存图像时几乎无大小限制。另外,提到了Pillow库的Image类作为另一种图像存取的替代方案。
摘要由CSDN通过智能技术生成

读图的时候是用 tensorflow 的函数,存图像用的 scipy.misc 的 imsave 函数。

因为在使用 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.
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值