1.tf.image.random_flip_left_right(image,seed=None)为随机翻转函数,注意这里的image有三个维度[height, width, channels]。还有一点就是此函数是在width方向上随机翻转的,有可能结果就是从左往右翻转,从左往左翻转即没有翻转。
翻转图像
tf.image.flip_up_down()
将图像上下翻转
tf.image.flip_left_right()
将图像左右翻转
tf.image.transpose_image()
通过交换第一维和第二维来转置图像
随机翻转
tf.image.random_flip_up_down()
将图像上下翻转的概率为0.5,即输出的图像有50%的可能性是上下翻转的否则就输出原图.
tf.image.random_flip_left_right()
将图像左右翻转的概率为0.5,即输出的图像有50%的可能性是左右翻转的否则就输出原图
2.tf.image.random_brightness(image,max_delta,seed=None)为随机调整亮度函数,实际上是在原图的基础上随机加上一个值(如果加上的是正值则增亮否则增暗),此值取自[-max_delta,max_delta),要求max_delta>=0。
3.tf.image.random_contrast(image,lower,upper,seed=None)为随机调整对比度函数,对比度调整值取自[lower,upper],
image = img.imread(‘D:/Documents/Pictures/logo4.jpg’)
flipped_image = tf.image.random_flip_left_right(image)#随机翻转函数
imaged = tf.cast(image,tf.float32) #这句必须加上
brightness_image = tf.image.random_brightness(imaged,max_delta=63)#随机调整亮度函数
imaged = tf.cast(image,tf.float32)
contrast_image = tf.image.random_contrast(imaged,lower=0.2,upper=1.8)#随机调整对比度函数
#!/usr/bin/python
# coding:utf-8
import matplotlib.pyplot as plt
import tensorflow as tf
# 读取图像数据
img = tf.gfile.FastGFile('daibola.jpg').read()
with tf.Session() as sess:
img_data = tf.image.decode_jpeg(img)
# 将图像的亮度-0.2
adjusted0 = tf.image.adjust_brightness(img_data, -0.2)
# 将图像的对比度+3
adjusted1 = tf.image.adjust_contrast(img_data, +3)
# 将图像的色相+0.2
adjusted2 = tf.image.adjust_hue(img_data, 0.2)
# 将图像的饱和度+3
adjusted3 = tf.image.adjust_saturation(img_data, 3)
# 将图像线性缩放为零均值和单位范数
adjusted4 = tf.image.per_image_standardization(img_data)
plt.subplot(231), plt.imshow(img_data.eval()), plt.title('original')
plt.subplot(232), plt.imshow(adjusted0.eval()), plt.title('adjust_brightness')
plt.subplot(233), plt.imshow(adjusted1.eval()), plt.title('adjust_contrast')
plt.subplot(234), plt.imshow(adjusted2.eval()), plt.title('adjust_hue')
plt.subplot(235), plt.imshow(adjusted3.eval()), plt.title('adjust_saturation')
plt.subplot(236), plt.imshow(adjusted4.eval()), plt.title('per_image_standardization')
plt.show()