1 Star 0 Fork 1

diycp2015 / imageProcessing

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
readImages.py 1.43 KB
一键复制 编辑 原始数据 按行查看 历史
北部湾的落日 提交于 2018-05-09 09:58 . Initial commit
import matplotlib.pyplot as plt
import tensorflow as tf
import numpy as np
import os
'''
获取目录下的所有文件名(全名)
'''
def getFilenameList(direction):
namelist=[]
for filename in os.listdir(direction):
namelist.append(os.path.join(direction,filename))
# print(direction+filename)
# print(type(namelist))
return namelist
def readImages(filenameList):
imageList = []
with tf.Session() as sess:
for filename in filenameList:
# print(filename)
# 读取图像的原始数据
image_raw_data = tf.gfile.FastGFile(filename,'rb').read() # 必须是 ‘rb’ 模式打开,否则会报错
# 将图像使用 jpeg 的格式解码从而得到图像对应的三维矩阵
# tf.image.decode_jpeg 函数对 png 格式的图像进行解码。解码之后的结果为一个张量,
# 在使用它的取值之前需要明确调用运行的过程。
print(filename)
img_data = tf.image.decode_jpeg(image_raw_data)
# arr = np.reshape(img_data.eval(sess), [-1]) # 多维矩阵转一维矩阵
arr = sess.run(tf.reshape(img_data.eval(), [-1]))
imageList.append(arr)
return np.array(imageList)
filework = 'D:/images/opencv/image_9000/'
# filework = r'D:\python\workspace\ideaTest\venv\images'
a = getFilenameList(filework)
print(np.shape(a))
b = readImages(a)
# print(np.shape(b))
1
https://gitee.com/diycp2015/imageProcessing.git
git@gitee.com:diycp2015/imageProcessing.git
diycp2015
imageProcessing
imageProcessing
master

搜索帮助