import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt # 使用'r'会出错,无法解码,只能以2进制形式读取
# img_raw = tf.gfile.FastGFile('E:\\myresource\\moutance.jpg','rb').read()
img_raw = open('E:\\myresource\\moutance.jpg','rb').read() # 把二进制文件解码为uint8
img_0 = tf.image.decode_png(img_raw)
# 可以用np直接转换了
# img_1 = tf.image.convert_image_dtype(img_0,dtype=tf.uint8) sess = tf.Session()
print(sess.run(img_0).shape)
plt.imshow(sess.run(img_0))
plt.show() def show_pho(img,sess=sess):
'''
TF处理过的图片自动转换了类型,需要调整回uint8才能正常显示
:param sess:
:param img:
:return:
'''
moutance = np.asarray(sess.run(img),dtype='uint8')
print(moutance.shape)
plt.imshow(moutance)
plt.show()

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

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

# 比例中央裁剪
img_4 = tf.image.central_crop(img_0,0.5)
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. [一本通学习笔记] 最近公共祖先LCA

    本节内容过于暴力没什么好说的.借着这个专题改掉写倍增的陋习,虽然写链剖代码长了点不过常数小还是很香. 10130. 「一本通 4.4 例 1」点的距离 #include <bits/stdc++ ...

  2. sql 应用记录

    SELECT * FROM (select aa.*,bb.mentalvisitid, ' then '家庭访视' else '电话' end as BCSFXS ,bb.visitdate, ' ...

  3. C++-指针阅读能力提升

    下面的标识符你肯定在工程中看不到,但是在面试题中却非常常见,掌握掌握还是不错的. int (*p1)(int*, int (*f)(int*));              int (*p2[5])( ...

  4. linux - 数据库 - Connected to an idle instance

    运行 connect /as sysdba; 报错:Connected to an idle instance 原因:配置文件 .bash_profile 中的 ORACLE_HOME 的最后这个 / ...

  5. Educational Codeforces Round 81 (Rated for Div. 2) A-E简要题解

    链接:https://codeforces.com/contest/1295 A. Display The Number 贪心思路,尽可能放置更多位,如果n为奇数,消耗3去放置一个7,剩下的放1 AC ...

  6. jdk8-》日期时间及其格式处理类特性

    一.JDK8之时间⽇期处理类 核⼼类: LocalDate:不包含具体时间的⽇期. LocalTime:不含⽇期的时间. LocalDateTime:包含了⽇期及时间. LocalDate 常⽤API ...

  7. linux软件下载

    可以到linux官网下载:http://vault.centos.org/6.10/os/Source/SPackages/

  8. Linux - Shell - shell 执行方式

    概述 shell 的执行方式 背景 偶尔执行个 shell 脚本 一般都用 './script' 执行 最近忽然看到 有不同的执行方式, 感觉有必要整理一下, 然后和大家分享 准备 os centos ...

  9. 使用VS2017开发安卓app(2)新建项目

    安装完成后,在c#下找到Android,选择Android应用(Xamarin),修改项目名称和路径,新建第一个安卓项目! 点击确定后会出现 这里我们选择空白应用和Android 7.1. 创建新项目 ...

  10. 画图软件gliffy

    网上的资源真是海量丫: https://segmentfault.com/q/1010000000310976 gliffy软件在线网址:https://chrome.google.com/webst ...