1. import numpy as np
  2. import tensorflow as tf
  3. import matplotlib.pyplot as plt
  4.  
  5. # 使用'r'会出错,无法解码,只能以2进制形式读取
  6. # img_raw = tf.gfile.FastGFile('E:\\myresource\\moutance.jpg','rb').read()
  7. img_raw = open('E:\\myresource\\moutance.jpg','rb').read()
  8.  
  9. # 把二进制文件解码为uint8
  10. img_0 = tf.image.decode_png(img_raw)
  11. # 可以用np直接转换了
  12. # img_1 = tf.image.convert_image_dtype(img_0,dtype=tf.uint8)
  13.  
  14. sess = tf.Session()
  15. print(sess.run(img_0).shape)
  16. plt.imshow(sess.run(img_0))
  17. plt.show()
  18.  
  19. def show_pho(img,sess=sess):
  20. '''
  21. TF处理过的图片自动转换了类型,需要调整回uint8才能正常显示
  22. :param sess:
  23. :param img:
  24. :return:
  25. '''
  26. moutance = np.asarray(sess.run(img),dtype='uint8')
  27. print(moutance.shape)
  28. plt.imshow(moutance)
  29. plt.show()

  1. '''调整图像大小'''
  2. # 插值尽量保存原图信息
  3. img_1 = tf.image.resize_images(img_0,[500,500],method=3)
  4. show_pho(img_1)

  1. # 裁剪或填充
  2. # 自动中央截取
  3. img_2 = tf.image.resize_image_with_crop_or_pad(img_0,500,500)
  4. show_pho(img_2)

  1. # 比例中央裁剪
  2. img_4 = tf.image.central_crop(img_0,0.5)
  3. show_pho(img_4)

吴裕雄 python 神经网络——TensorFlow图片预处理的更多相关文章

  1. 吴裕雄 python 神经网络——TensorFlow图片预处理调整图片

    import numpy as np import tensorflow as tf import matplotlib.pyplot as plt def distort_color(image, ...

  2. 吴裕雄 python 神经网络——TensorFlow 图像预处理完整样例

    import numpy as np import tensorflow as tf import matplotlib.pyplot as plt def distort_color(image, ...

  3. 吴裕雄 python 神经网络——TensorFlow 卷积神经网络水果图片识别

    #-*- coding:utf- -*- import time import keras import skimage import numpy as np import tensorflow as ...

  4. 吴裕雄 python 神经网络——TensorFlow 卷积神经网络手写数字图片识别

    import os import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data INPUT_N ...

  5. 吴裕雄 python 神经网络——TensorFlow 数据集高层操作

    import tempfile import tensorflow as tf train_files = tf.train.match_filenames_once("E:\\output ...

  6. 吴裕雄 python 神经网络——TensorFlow 花瓣分类与迁移学习(4)

    # -*- coding: utf-8 -*- import glob import os.path import numpy as np import tensorflow as tf from t ...

  7. 吴裕雄 python 神经网络——TensorFlow 花瓣分类与迁移学习(3)

    import glob import os.path import numpy as np import tensorflow as tf from tensorflow.python.platfor ...

  8. 吴裕雄 python 神经网络——TensorFlow 花瓣分类与迁移学习(2)

    import glob import os.path import numpy as np import tensorflow as tf from tensorflow.python.platfor ...

  9. 吴裕雄 python 神经网络——TensorFlow 花瓣识别2

    import glob import os.path import numpy as np import tensorflow as tf from tensorflow.python.platfor ...

随机推荐

  1. 测度论--长度是怎样炼成的[zz]

    http://www.58pic.com/newpic/27882296.html http://www.58pic.com/newpic/27893137.html http://699pic.co ...

  2. 《NVM-Express-1_4-2019.06.10-Ratified》学习笔记(8.20)-- ANA

    8.20 非对称namespace访问报告 8.20.1 非对称namespace访问报告概况 非对称Namespace访问(ANA)在如下场景下产生,基于访问这个namespace的controll ...

  3. 1054 The Dominant Color

    大致题意就是给出N行M列的元素,找出出现次数最多的元素并输出. #include<iostream> #include<unordered_map> using namespa ...

  4. DTU DeepLearning: exercise 7

    torch activation functions: sigmoid, relu, tanh, softplus. https://morvanzhou.github.io/tutorials/ma ...

  5. XMLHttpRequest: 网络错误 0x2ee4, 由于出现错误 00002ee4 而导致此项操作无法完成

    原因: IE11有默认设置安全策略,如果url需要证书,一发送请求IE11就会拒绝,因为ssl certificate(SSL证书) 是非法的 解决方案: (1)修改IE浏览器配置 - 用户使用的电脑 ...

  6. Python七夕记

  7. 使用validate进行表单验证时土方法(appendTo)改变error显示的位置

    <span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255) ...

  8. echo -e 实现color output

    拓展: cp  简化: c'p  -rv   /data/project/test {.txt,_bak.txt}

  9. java Map 迭代key,value 最简洁的方法

    import java.util.HashMap; import java.util.Map; public class EntrySets { public static void main(Str ...

  10. Mybatis学习笔记——输入参数parameterType、Mybatis调用存储过程

    输入参数:parameterType(两种取值符号) 1.类型为简单类型 区别:     (1) #{可以为任意值}         ${vaue}--->标识符只能是value     (2) ...