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. Android开发——官方推荐使用DialogFragment替换AlertDialog

    )比如当屏幕旋转时,AlertDialog会消失,更不会保存如EditText上的文字,如果处理不当很可能引发异常,因为Activity销毁前不允许对话框未关闭.而DialogFragment对话框会 ...

  2. libgdx学习记录23——图片移动选择

    模拟移动选择图片,采用相机实现. package com.fxb.newtest; import com.badlogic.gdx.ApplicationAdapter; import com.bad ...

  3. NetBeans的(默认)快捷键

    NetBeans的(默认)快捷键 1.完成代码:ctrl+\ //任何地方按下此组合键,均会提示相应的参考字段:  2.错误提示:alt + enter //顾名思义,当系统报错时,按下此组合可以查看 ...

  4. laraver框架学习

    最近开始学习laravel框架,这个框架在国外很流行,近些年开始在国内流行.自己而是刚开始学习这个框架. 使用composer 更新系统内的依赖包 在终端输入:composer update Entr ...

  5. 学习git 新手。这个写的不错

    转自:https://www.cnblogs.com/wupeiqi/p/7295372.html 版本控制 说到版本控制,脑海里总会浮现大学毕业是写毕业论文的场景,你电脑上的毕业论文一定出现过这番景 ...

  6. OpenGL:使用顶点数组法绘制正六面体

    在今天的opengl的课程以及实验中,我们学习了如何使用顶点数组的方法来绘制图形,但相信还有很多同学对它的实际使用方法不太了解,我们就用我们今天实验课上的实例来简单讲解一下 题目及要求 绘制一个正六面 ...

  7. unity纯粹物理驱动方式

    首先见官方文档 In most cases you should not modify the velocity directly, as this can result in unrealistic ...

  8. B1010.一元多项式求导

    12/25 #include<bits/stdc++.h> using namespace std; void solve(){ int A,B,coef,exp; cin>> ...

  9. Magento 总结

    ZEND EAV 速度 作者:李淼链接:https://www.zhihu.com/question/20656910/answer/25793452来源:知乎著作权归作者所有.商业转载请联系作者获得 ...

  10. ajax请求超时判断(转载)

    ajax请求时有个参数可以借鉴一下 var ajaxTimeOut = $.ajax({ url:'', //请求的URL timeout : 1000, //超时时间设置,单位毫秒 type : ' ...