请选择 进入手机版 | 继续访问电脑版

Hello Mat

 找回密码
 立即注册
查看: 4462|回复: 0

Tensorflow读取mnist图像数据并保存图像

[复制链接]

1278

主题

1504

帖子

90

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
22549
发表于 2017-8-14 20:48:14 | 显示全部楼层 |阅读模式
Tensorflow读取mnist图像数据并保存图像
百度网盘链接:
链接:http://pan.baidu.com/s/1i4BbOlJ
具体链接在halcom.cn论坛,联系人QQ:3283892722
该论坛是一个学习交流平台,我会逐一的和大家分享学习。
欢迎大家录制视频,你可在论坛进行打赏分享。
视频专用播放器:http://halcom.cn/forum.php?mod=viewthread&tid=258&extra=page%3D1

  1. import tensorflow as tf
  2. import os
  3. from PIL import Image

  4. cur_dir = os.getcwd()
  5. print("For Tensorflow to load images")
  6. print("current directory:",cur_dir)

  7. def read_image(filename_queue):
  8.     reader = tf.WholeFileReader()
  9.     key,value = reader.read(filename_queue)
  10.     image = tf.image.decode_png(value)
  11.     return key,image

  12. def inputs():
  13.     # 手写数字--灰度图像
  14.     #filenames = ['./Test/test/1.png', './Test/test/2.png' ]
  15.    
  16.     FullImageList = [];
  17.     filenames = os.listdir('./Test/test/')
  18.     for fn in filenames:
  19.         FullImage = os.path.join( cur_dir, 'Test/test', fn )
  20.         FullImageList.append(FullImage)

  21.     filename_queue = tf.train.string_input_producer(FullImageList)
  22.     filename,read_input = read_image(filename_queue)
  23.     return filename,read_input

  24. with tf.Graph().as_default():
  25.     image = inputs()
  26.     init = tf.global_variables_initializer()
  27.     sess = tf.Session()
  28.     sess.run(init)
  29.     tf.train.start_queue_runners(sess=sess)
  30.     for i in range(3):
  31.         filename,img = sess.run(image)
  32.         print (filename)
  33.         # 手写数字--灰度图像
  34.         img = Image.fromarray(img[:,:,0], "L")
  35.         img.save(os.path.join(cur_dir+'/Test/',"ysw"+str(i)+".bmp"))
  36.         
复制代码



算法QQ  3283892722
群智能算法链接http://halcom.cn/forum.php?mod=forumdisplay&fid=73
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Python|Opencv|MATLAB|Halcom.cn ( 蜀ICP备16027072号 )

GMT+8, 2024-3-28 22:52 , Processed in 0.210589 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表