tf.image.random_contrast函数等常见的图片预处理操作

tf.image.random_contrast函数

tf.image.random_contrast(
    image,
    lower,
    upper,
    seed=None
)

函数功能:通过随机因子调整图像的对比度,相当于adjust_contrast(),但使用了在区间[lower, upper]中随机选取的contrast_factor.

参数:

  • image:具有3个或更多维度的图像张量.
  • lower:浮点型,随机对比因子的下限.
  • upper:浮点型,随机对比因子的上限.
  • seed:一个Python整数,用于创建一个随机种子.查看tf.set_random_seed行为.
  • 返回:对比度调整张量.

常见的图片处理行为

import matplotlib.pyplot as plt
import tensorflow as tf

image_raw_data = tf.gfile.FastGFile('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_standardization(img_data)

猜你喜欢

转载自blog.csdn.net/weixin_38145317/article/details/89631616