更多的基本的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. Url解码和编码 escape()、encodeURI()、encodeURIComponent()区别详解

    Server.UrlDecode;解码 Server.UrlEncode;编码 url编码是一种浏览器用来打包表单输入的格式.浏览器从表单中获取所有的name和其中的值 ,将它们以name/value ...

  2. Ubuntu下Mongodb和Robo3T的安装与使用

    Mongodb的安装:https://blog.csdn.net/Canhui_WANG/article/details/78995388 Robo3T的安装:https://www.jianshu. ...

  3. jquery_ajax 跨域

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  4. Best Cow Line(POJ3617)

    Description FJ is about to take his N (1 ≤ N ≤ 2,000) cows to the annual"Farmer of the Year&quo ...

  5. Java 并发类

    java.util.concurrent包里 提供了一批线程安全的类 一. java.util.concurrent.atomic java.util.concurrent.atomic包里的原子处理 ...

  6. java 自动包装功能

    基本类型直接存储在堆栈中 基本类型所具有的包装容器,使得可以在堆中创建一个非基本对象,用来表示对应的基本类型 基本类型与包装容器类对应如下:boolean Booleanbyte Byte short ...

  7. hdu3586 树形dp+二分答案

    /* dp[i]表示孤立i结点的费用,二分功率上限w,即dp[i]在选择时不可以选择功率大于w的边 */ #include<bits/stdc++.h> using namespace s ...

  8. Vue 导入文件import、路径@和.的区别

    ***import: html文件中,通过script标签引入js文件.而vue中,通过import xxx from xxx路径的方式导入文件,不光可以导入js文件. from前的:“xxx”指的是 ...

  9. ORA-12519 ORA-12516

    目录: 错误信息 原因分析 解决方法 1. 错误信息 [oracle@test1 admin]$ oerr ora , , "TNS:no appropriate service handl ...

  10. SpringMVC - 1.快速入门

    1. HelloWorld 步骤: 加入 jar 包 mons-logging-1.1.3.jar spring-aop-4.0.0.RELEASE.jar spring-beans-4.0.0.RE ...