前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >TensorFlow 图像预处理(二) 图像翻转,图像色彩调整

TensorFlow 图像预处理(二) 图像翻转,图像色彩调整

作者头像
chaibubble
发布2018-01-02 11:02:45
1.7K0
发布2018-01-02 11:02:45
举报

图像翻转 tf.image.flip_up_down:上下翻转 tf.image.flip_left_right:左右翻转 tf.image.transpose_image:对角线翻转 除此之外,TensorFlow还提供了随机翻转的函数,保证了样本的样本的随机性: tf.image.random_flip_up_down:随机上下翻转图片 tf.image.random_flip_left_right:随机左右翻转图片

import matplotlib.pyplot as plt
import tensorflow as tf
import numpy as np

image_raw_data = tf.gfile.FastGFile('.//image//1.jpg','rb').read()

with tf.Session() as sess:
     img_data = tf.image.decode_jpeg(image_raw_data)
     plt.imshow(img_data.eval())
     plt.show()

     # 上下翻转
     flipped1 = tf.image.flip_up_down(img_data)
     plt.imshow(flipped1.eval())
     plt.show()
     # 左右翻转
     flipped2 = tf.image.flip_left_right(img_data)
     plt.imshow(flipped2.eval())
     plt.show()
     #对角线翻转
     transposed = tf.image.transpose_image(img_data)
     plt.imshow(transposed.eval())
     plt.show()

     # 以一定概率上下翻转图片。
     #flipped = tf.image.random_flip_up_down(img_data)
     # 以一定概率左右翻转图片。
     #flipped = tf.image.random_flip_left_right(img_data)
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述

图像色彩调整 亮度: tf.image.adjust_brightness:调整图片亮度 tf.image.random_brightness:在某范围随机调整图片亮度 对比度: tf.image.adjust_contrast:调整图片对比度 tf.image.random_contrast:在某范围随机调整图片对比度 色相: tf.image.adjust_hue:调整图片色相 tf.image.random_hue:在某范围随机调整图片色相 饱和度: tf.image.adjust_saturation:调整图片饱和度 tf.image.random_saturation:在某范围随机调整图片饱和度 归一化: per_image_whitening:三维矩阵中的数字均值变为0,方差变为1。

import matplotlib.pyplot as plt
import tensorflow as tf

image_raw_data = tf.gfile.FastGFile('.//image//1.jpg','rb').read()

with tf.Session() as sess:
     img_data = tf.image.decode_jpeg(image_raw_data)
     plt.imshow(img_data.eval())
     plt.show()

     # 将图片的亮度-0.5。
     adjusted = tf.image.adjust_brightness(img_data, -0.5)
     plt.imshow(adjusted.eval())
     plt.show()

     # 将图片的亮度0.5
     adjusted = tf.image.adjust_brightness(img_data, 0.5)
     plt.imshow(adjusted.eval())
     plt.show()
     # 在[-max_delta, max_delta)的范围随机调整图片的亮度。
     adjusted = tf.image.random_brightness(img_data, max_delta=0.5)
     plt.imshow(adjusted.eval())
     plt.show()
     # 将图片的对比度-5
     adjusted = tf.image.adjust_contrast(img_data, -5)
     plt.imshow(adjusted.eval())
     plt.show()
     # 将图片的对比度+5
     adjusted = tf.image.adjust_contrast(img_data, 5)
     plt.imshow(adjusted.eval())
     plt.show()
     # 在[lower, upper]的范围随机调整图的对比度。
     adjusted = tf.image.random_contrast(img_data, 0.1, 0.6)
     plt.imshow(adjusted.eval())
     plt.show()

     #调整图片的色相
     adjusted = tf.image.adjust_hue(img_data, 0.1)
     plt.imshow(adjusted.eval())
     plt.show()

     # 在[-max_delta, max_delta]的范围随机调整图片的色相。max_delta的取值在[0, 0.5]之间。
     adjusted = tf.image.random_hue(img_data, 0.5)
     plt.imshow(adjusted.eval())
     plt.show()  


     # 将图片的饱和度-5。
     adjusted = tf.image.adjust_saturation(img_data, -5)
     plt.imshow(adjusted.eval())
     plt.show()  


     # 在[lower, upper]的范围随机调整图的饱和度。
     adjusted = tf.image.random_saturation(img_data, 0, 5)

     # 将代表一张图片的三维矩阵中的数字均值变为0,方差变为1。
     adjusted = tf.image.per_image_whitening(img_data)

图片有点多,不贴图了,大家运行一下就能看到效果了。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017-06-12 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
图像处理
图像处理基于腾讯云深度学习等人工智能技术,提供综合性的图像优化处理服务,包括图像质量评估、图像清晰度增强、图像智能裁剪等。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档