Tensorflow图像处理主要包括:调整尺寸,图像翻转,调整色彩,处理标注框。

代码如下:

#coding=utf-8
import matplotlib.pyplot as plt
import tensorflow as tf
import numpy as np image_raw_data = tf.gfile.FastGFile('cat.jpg','rb').read() with tf.Session() as sess:
img_data = tf.image.decode_jpeg(image_raw_data)
plt.subplot(331)
plt.title("Original") plt.imshow(img_data.eval())
#plt.show() resized = tf.image.resize_images(img_data, [100, 100], method=0)
# TensorFlow的函数处理图片后存储的数据是float32格式的,需要转换成uint8才能正确打印图片。
print("Digital type: ", resized.dtype)
resized = np.asarray(resized.eval(), dtype='uint8')
# tf.image.convert_image_dtype(rgb_image, tf.float32)
plt.subplot(332)
plt.title("100*100")
plt.imshow(resized) #plt.show() croped = tf.image.resize_image_with_crop_or_pad(img_data, 500, 500)
padded = tf.image.resize_image_with_crop_or_pad(img_data, 1500, 1500)
plt.subplot(333)
plt.title("500*500")
plt.imshow(croped.eval())
# plt.show()
plt.subplot(334)
plt.title("1500*1500")
plt.imshow(padded.eval())
#plt.show() central_cropped = tf.image.central_crop(img_data, 0.5)
plt.subplot(335)
plt.title("*0.5")
plt.imshow(central_cropped.eval())
# plt.show() # 上下翻转
flipped1 = tf.image.flip_up_down(img_data)
plt.subplot(336)
plt.title("up-down")
plt.imshow(flipped1.eval())
#plt.show()
# 左右翻转
flipped2 = tf.image.flip_left_right(img_data)
plt.subplot(337)
plt.title("left-right")
plt.imshow(flipped2.eval())
#plt.show()
# 对角线翻转
transposed = tf.image.transpose_image(img_data)
plt.subplot(338)
plt.title("transpose")
plt.imshow(transposed.eval())
# plt.show() flipped3 = tf.image.random_flip_up_down(img_data)
plt.subplot(339)
plt.title("flip-up-down")
plt.imshow(flipped3.eval())
plt.show()
#————————————————————————————————————————————#
# 将图片的亮度-0.5。
adjusted = tf.image.adjust_brightness(img_data, -0.5)
plt.subplot(331)
plt.imshow(adjusted.eval()) plt.title("bright-0.5")
#plt.show() # 将图片的亮度0.5
adjusted = tf.image.adjust_brightness(img_data, 0.5)
plt.subplot(332)
plt.imshow(adjusted.eval()) plt.title("bright+0.5")
#plt.show()
# 在[-max_delta, max_delta)的范围随机调整图片的亮度。
adjusted = tf.image.random_brightness(img_data, max_delta=0.5)
plt.subplot(333)
plt.imshow(adjusted.eval()) plt.title("bright-random")
#plt.show()
# 将图片的对比度-5
adjusted = tf.image.adjust_contrast(img_data, -5)
plt.subplot(334)
plt.imshow(adjusted.eval())
plt.title("contrast-5")
#plt.show()
# 将图片的对比度+5
adjusted = tf.image.adjust_contrast(img_data, 5)
plt.subplot(335)
plt.imshow(adjusted.eval()) plt.title("contrast+5")
#plt.show()
# 在[lower, upper]的范围随机调整图的对比度。
adjusted = tf.image.random_contrast(img_data, 0.1, 0.6)
plt.subplot(336)
plt.imshow(adjusted.eval())
plt.title("contrast-random")
#plt.show() # 调整图片的色相
adjusted = tf.image.adjust_hue(img_data, 0.1)
plt.subplot(337)
plt.imshow(adjusted.eval())
plt.title("hue_0.1")
#plt.show() # 在[-max_delta, max_delta]的范围随机调整图片的色相。max_delta的取值在[0, 0.5]之间。
adjusted = tf.image.random_hue(img_data, 0.5)
plt.subplot(338)
plt.imshow(adjusted.eval())
plt.title("hue-random_0.5")
#plt.show() # 将图片的饱和度-5。
adjusted = tf.image.adjust_saturation(img_data, -2)
plt.subplot(339)
plt.title("saturation-2")
plt.imshow(adjusted.eval())
plt.show() # 在[lower, upper]的范围随机调整图的饱和度。
#adjusted = tf.image.random_saturation(img_data, 0, 5) # 将代表一张图片的三维矩阵中的数字均值变为0,方差变为1。
#adjusted = tf.image.per_image_standardization(img_data)

  

效果图:

Tensorflow图像处理的更多相关文章

  1. TensorFlow图像处理API

    TensorFlow提供了一些常用的图像处理接口,可以让我们方便的对图像数据进行操作,以下首先给出一段显示原始图片的代码,然后在此基础上,实践TensorFlow的不同API. 显示原始图片 impo ...

  2. [tensorflow]图像处理相关模块的安装(python3中PIL)

    直接上过程图(平台为Anaconda): 默认已经配置完了tensorflow的3.5的环境 我这里已经安装完成 接下来,就可以在python文件中引入模块了 from PIL import Imag ...

  3. TensorFlow图像处理函数

    参考书 <TensorFlow:实战Google深度学习框架>(第2版) 图像编码处理+图像大小调整+图像翻转+图像色彩调整+处理标注框 #!/usr/bin/env python # - ...

  4. tensorflow图像处理函数(1)

    1.tensorflow中对jpeg格式图像的编码/解码函数: import matplotlib.pyplot as plt import tensorflow as tf image_raw_da ...

  5. 吴裕雄 python 神经网络——TensorFlow 图像处理函数

    import numpy as np import tensorflow as tf import matplotlib.pyplot as plt image_raw_data = tf.gfile ...

  6. 吴裕雄--天生自然 pythonTensorFlow图形数据处理:TensorFlow图像处理函数

    import numpy as np import tensorflow as tf import matplotlib.pyplot as plt #读取图片 image_raw_data = tf ...

  7. Tensorflow图像处理以及数据读取

    关于tensoflow的图像的处理,看到了一篇文章,个人觉得不错.https://blog.csdn.net/weiwei9363/article/details/79917942

  8. TensorFlow深度学习实战---图像数据处理

    图像的亮度.对比度等属性对图像的影响非常大,这些因素都会影响最后的识别结构.当然,复杂的预处理过程可能会导致训练效率的下降(利用TensorFlow中多线程处理输入数据的解决方案). 同一不同的原始数 ...

  9. ubuntu远程桌面

    用Linux已经有很长一段时间,但主要用于嵌入式开发(用交叉工具链进行版本编译),所以用命令行就可以了,而且敲的最多的命令就是make.最近开始搭建TensorFlow的开发环境,大部分工作都是命令行 ...

随机推荐

  1. VS编程,WPF中,获取鼠标相对于当前屏幕坐标的一种方法

    原文:VS编程,WPF中,获取鼠标相对于当前屏幕坐标的一种方法 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_43307934/article/det ...

  2. 实践:IIS7下访问ashx页面,显示404

    问题描述 1.路径什么的都对,这方面的原因就不要想了 2.在我的电脑上可以,在同事的电脑上不可以 方案1:未注册ashx的处理应用程序 也就是不知道IIS不知道用什么应用程序处理ashx文件,解决办法 ...

  3. 汇编 fsub ,fmul,fdiv,fild,CVTTPS2PI 指令

    知识点:  浮点指令 fsub 一.浮点指令fsub 格式 fsub memvar // st0=st0-memvar 知识点:  浮点指令 fmul 一.浮点指令fmul 格式 fmul mem ...

  4. it面试技巧

    一:请你自我介绍一下你自己? 回答提示:一般人回答这个问题过于平常,只说姓名.年龄.爱好.工作经验,这些在简历上都有.其实,企业最希望知道的是求职者能否胜任工作,包括:最强的技能.最深入研究的知识领域 ...

  5. PowerBI开发 第十二篇:钻取

    钻取是指沿着层次结构(维度的层次)查看数据,钻取可以变换分析数据的粒度.钻取分为下钻(Drill-down)和上钻(Drill-up),上钻是沿着数据的维度结构向上聚合数据,在更大的粒度上查看数据的统 ...

  6. CTE 递归查询全解

    TSQL脚本能实现递归查询,用户使用共用表表达式 CTE(Common Table Expression),只需要编写少量的代码,就能实现递归查询.本文详细介绍CTE递归调用的特性和使用示例,递归查询 ...

  7. linux chroot 命令

    chroot,即 change root directory (更改 root 目录).在 linux 系统中,系统默认的目录结构都是以 /,即以根 (root) 开始的.而在使用 chroot 之后 ...

  8. C#ToString() 格式化数值

    格式字符串采用以下形式:Axx,其中 A 为格式说明符,指定格式化类型,xx 为精度说明符,控制格式化输出的有效位数或小数位数. 格式说明符 说明 示例 输出 C 货币 2.5.ToString(&q ...

  9. Solr查询语法

    基于solr版本:6.0.0 当配置好本地的环境之后,就访问http://localhost:8080/solr/index.html.或者是访问已经放在服务器上的solr环境,例如http://10 ...

  10. Alpha 冲刺九

    团队成员 051601135 岳冠宇 051604103 陈思孝 031602629 刘意晗 031602248 郑智文 031602234 王淇 会议照片 项目燃尽图 项目进展 完善各自部分 项目描 ...