更多的基本的API请参看TensorFlow中文社区:http://www.tensorfly.cn/tfdoc/api_docs/python/array_ops.html

下面是实验的代码,可以参考,对应的图片是输出的结果:

import tensorflow as tf
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import numpy as np
%matplotlib inline
path = '/home/ubuntu-mm/TensorFlow/Learning/D-TestJupyter/images/Train/Dogs.jpg'
file_queue = tf.train.string_input_producer([path])
image_reader = tf.WholeFileReader()
_, image = image_reader.read(file_queue)
image = tf.image.decode_jpeg(image)
with tf.Session() as sess:
coord = tf.train.Coordinator() #协同启动的线程
threads = tf.train.start_queue_runners(sess=sess, coord=coord) #启动线程运行队列
sess.run(image)
coord.request_stop() #停止所有的线程
coord.join(threads)
image_uint8 = tf.image.convert_image_dtype(image, dtype = tf.uint8)
plt.figure(1)
plt.imshow(image_uint8.eval())
print image_uint8.get_shape()
resize_image1 = tf.image.resize_images(image_uint8,[400,300],method=tf.image.ResizeMethod.NEAREST_NEIGHBOR) #修改图片的尺寸
resize_image2 = tf.image.resize_images(image_uint8,[400,300],method=1) #修改图片的尺寸 1代表的就是NEAREST_NEIGHBOR的方法
central_crop = tf.image.central_crop(image_uint8, 0.6) #从图片中心开始裁剪图片,裁剪比例为60%
bounding_crop = tf.image.crop_to_bounding_box(resize_image1, offset_height=100, offset_width=100, target_height=100, target_width=100) #设定裁剪的起始位置和终止位置进行裁剪
pad = tf.image.pad_to_bounding_box(bounding_crop, offset_height=0, offset_width=0, target_height=105, target_width=105) #设定边缘对图像的边缘进行填充(填0)
flip1 = tf.image.flip_left_right(resize_image1) #左右翻转图片
flip2 = tf.image.flip_up_down(flip1) #上下翻转图片
adjust_brightness = tf.image.adjust_brightness(resize_image1, 0.2) #调节图像的亮度为原来的20%
adjust_saturation = tf.image.adjust_saturation(resize_image1, 0.4) #调节图像的饱和度为原来的40%
adjust_hue = tf.image.adjust_hue(resize_image1, 0.7) #调节原来的H(灰度)为原来的70%
image_float = tf.cast(resize_image1, dtype=tf.float32)
gray = tf.image.rgb_to_grayscale(image_float) #对图像的类型进行转换rgb-grayscale
hsv = tf.image.rgb_to_hsv(image_float) #对图像进行hsv转换rgb-hsv
imag_gray = tf.image.convert_image_dtype(gray, tf.uint8)
imag_hsv = tf.image.convert_image_dtype(hsv, tf.uint8)
sess.run([flip1, flip2])
plt.figure(2)
plt.imshow(resize_image1.eval())
plt.figure(3)
plt.imshow(resize_image2.eval())
plt.figure(4)
plt.imshow(central_crop.eval())
plt.figure(5)
plt.imshow(bounding_crop.eval())
plt.figure(6)
plt.imshow(pad.eval())
plt.figure(7)
plt.imshow(flip2.eval())
plt.figure(8)
plt.imshow(adjust_brightness.eval())
plt.figure(9)
plt.imshow(adjust_saturation.eval())
plt.figure(10)
plt.imshow(adjust_hue.eval())
plt.figure(1)
plt.imshow(imag_hsv.eval(), cmap=cm.hsv)

原图                                               改变尺寸                                       改变尺寸                                  图像中心裁剪

图像边缘裁剪                                              图像边缘补0                                     图像水平垂直翻转

图像亮度度调节                           图像饱和度变换                                 图像弧度调节H                              图像HSV显示

相关函数介绍:

1、tf.image.resize_images(image_uint8,[400,300],method=tf.image.ResizeMethod.NEAREST_NEIGHBOR)

  函数的作用是修改图像的尺寸(缩放放大的形式),第一个参数是原始图像,第二个参数是输出图像的大小,第三个参数是缩放或放大的方法。

2、tf.image.central_crop(image_uint8, 0.6)

  函数的功能是裁剪图像,裁剪的中心式图像的中心位置,第一个参数是原始图像,第二个参数是裁剪的比例。

3、tf.image.crop_to_bounding_box(resize_image1, offset_height=100, offset_width=100, target_height=100, target_width=100)

  函数的功能是按照输入的参数的边缘来裁剪图像,第一个参数是原始的图像,第二个参数是裁剪的y轴起始位置,第三个是x轴起始位置,第4个参数和第5个参数是输出图像的尺寸大小。

4、tf.image.pad_to_bounding_box(bounding_crop, offset_height=0, offset_width=0, target_height=105, target_width=105)

  函数的功能是扩充图像的边缘,对图像的边缘进行补零的操作,第一个参数是原始图像,第二个参数和第三个参数是输出图像在原图上的起始位置,第4和5个参数是输出图像的大小,当输出图像超出了原始图像的大小时,就会将超出的部分进行补零的操作。

5、tf.image.flip_left_right(resize_image1)

  函数的功能是对图像进行水平方向的反转,参数1是原始图像。

6、tf.image.flip_up_down(flip1)

  函数的功能是对图像进行垂直方向的反转,参数1是原始图像。

7、tf.image.adjust_brightness(resize_image1, 0.2)

  函数的功能是调节原始图像的亮度值,第一个参数是原始图像,第二个参数是调节的比例。

8、tf.image.adjust_saturation(resize_image1, 0.4)

  函数的功能是调节原始图像的饱和度,第一个参数是原始图像,第二个参数是调节的比例。

9、tf.image.adjust_hue(resize_image1, 0.7)

  函数的功能是调节图像的灰度值(Hue),参数1是原始图像,参数2是调节的比例。

10、tf.image.rgb_to_grayscale(image_float)

  函数的功能是间输入的rgb格式的图像转换成grayscale的灰度图像,参数1是输入的原始图像。(注意输入图像的格式需要时浮点形式的float)

11、tf.image.rgb_to_hsv(image_float)

  函数的功能是间输入的图像转换成为hsv格式的图像,参数1是输入图像,输入的格式需要时浮点型的。

                         完!

TensorFlow图像预处理-函数的更多相关文章

  1. TensorFlow图像预处理完整样例

    参考书 <TensorFlow:实战Google深度学习框架>(第2版) 以下TensorFlow程序完成了从图像片段截取,到图像大小调整再到图像翻转及色彩调整的整个图像预处理过程. #! ...

  2. TensorFlow 图像预处理(一) 图像编解码,图像尺寸调整

    from: https://blog.csdn.net/chaipp0607/article/details/73029923 TensorFlow提供了几类图像处理函数,下面介绍图像的编码与解码,图 ...

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

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

  4. 『TensorFlow』第九弹_图像预处理_不爱红妆爱武装

    部分代码单独测试: 这里实践了图像大小调整的代码,值得注意的是格式问题: 输入输出图像时一定要使用uint8编码, 但是数据处理过程中TF会自动把编码方式调整为float32,所以输入时没问题,输出时 ...

  5. python+opencv 图像预处理

    一 python 生成随机字符串序列+ 写入到图片上 from PIL import Image,ImageDraw,ImageFont import numpy as np import rando ...

  6. 基于OpenCV的火焰检测(一)——图像预处理

    博主最近在做一个基于OpenCV的火焰检测的项目,不仅可以检测图片中的火焰,还可以检测视频中的火焰,最后在视频检测的基础上推广到摄像头实时检测.在做这个项目的时候,博主参考了很多相关的文献,用了很多种 ...

  7. [opencv]图像预处理方案及方式

    像识别中,图像质量的好坏直接影响识别算法的设计与效果精度,那么除了能在算法上的优化外,预处理技术在整个项目中占有很重要的因素,然而人们往往忽略这一点. 图像预处理,将每一个文字图像分检出来交给识别模块 ...

  8. 图像预处理第9步:存为.bmp文件

    //图像预处理第9步:将最终标准化后的字符图像分为单个单个的HDIB保存,并存为.bmp文件 void CChildView::OnImgprcToDibAndSave() { unsigned ch ...

  9. opencv 图像修复函数

    void cv::inpaint( const Mat& src, const Mat& mask, Mat& dst, double inpaintRange, int fl ...

随机推荐

  1. MYSQL修改字段

    当字段为空则插入0,不为空则原来的值  UPDATE t_pm_scheduleSET lesson_room_id1 = IFNULL(lesson_room_id1, 0), lesson_roo ...

  2. LONG数据类型转换为VARCHAR2并相互转换

    --方法1,支持表 --plsql中将long类型隐式转换为varchar2,但是sql不能CREATE OR REPLACE FUNCTION LONG_TO_CHAR( in_rowid rowi ...

  3. CSS margin合并

    外边距合并 块的顶部外边距和底部外边距有时被组合(折叠)为单个外边距,其大小是组合到其中的最大外边距 发生外边距合并的三种基本情况 1. 相邻的兄弟姐妹元素 <div id="marg ...

  4. android经典源码,很不错的开源框架

    高仿最美应用项目源码 项目介绍 这是仿最美应用开发的基于mvp+rxjava+retrofit的项目,很值得学   github地址: https://github.com/JJOGGER/Beaut ...

  5. -Dmaven.multiModuleProjectDirectory system property is not set.

    1.配置 maven 环境变量 新建系统变量 -> 变量名(N): M2_HOME 变量值(V): D:\apache-maven-3.5.4(改为自己的maven目录) -> 添加 pa ...

  6. Confluence 6 升级你的许可证

    如果你修改了你的许可证(例如为你的许可证增加了更多的用户),或者从 Cloud 中整合到你本地,你需要更新你的许可证. 希望更新你的额许可证: 进入  > 基本配置(General Config ...

  7. Confluence 6 为空白空间编辑默认主页

    希望编辑默认(空白)空间内容模板: 在屏幕的右上角单击 控制台按钮 ,然后选择 General Configuration 链接. 在左侧的面板中选择 全局模板和蓝图(Global Templates ...

  8. nginx实践(二)之静态资源web服务(浏览器缓存场景)

    配置语法-expires

  9. 第二十单元 计划任务crond服务

    什么是计划任务:后台运行,到了预定的时间就会自动执行的任务,前提是:事先手动将计划任务设定好.这就用到了crond服务 crond服务相关的软件包[root@MiWiFi-R3-srv ~]# rpm ...

  10. django 之知识点总结以及Form组件

    一.model常用操作 1.13个API查询:all,filter,get ,values,values_list,distinct,order_by ,reverse , exclude(排除),c ...