• 图像预处理之图像翻转、图像色彩调整、图像尺寸调整


    图像翻转 

    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:随机左右翻转图片

    图像色彩调整 

    亮度: 
    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_standardization:三维矩阵中的数字均值变为0,方差变为1。在以前的版本中,它其实叫做per_image_whitening,也就是白化操作。

    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_standardization(img_data)
    

    图像尺寸调整 

    图像尺寸调整属于基础的图像几何变换,TensorFlow提供了几种尺寸调整的函数: 
    tf.image.resize_images:将原始图像缩放成指定的图像大小,其中的参数method(默认值为ResizeMethod.BILINEAR)提供了四种插值算法,具体解释可以参考图像几何变换(缩放、旋转)中的常用的插值算法 
    tf.image.resize_image_with_crop_or_pad:剪裁或填充处理,会根据原图像的尺寸和指定的目标图像的尺寸选择剪裁还是填充,如果原图像尺寸大于目标图像尺寸,则在中心位置剪裁,反之则用黑色像素填充。 
    tf.image.central_crop:比例调整,central_fraction决定了要指定的比例,取值范围为(0,1],该函数会以中心点作为基准,选择整幅图中的指定比例的图像作为新的图像。

    参考:https://blog.csdn.net/chaipp0607/article/details/73089910

  • 相关阅读:
    阿里云播放器弹幕选型
    使用swiper组件,轮播图在高分辨率情况下变形,图片拉高该如何解决?
    解决图片无法设置hover,以设置图片的阴影
    当标题文字超出长度后,后续用...来代替
    windows 安装wget
    【Go学习】GO中...的用法
    【Go】go test
    tcpdump工具及使用介绍
    leetcode32.最长有效括号
    Global Round 21 部分题解
  • 原文地址:https://www.cnblogs.com/dong-zhen/p/9604483.html
Copyright © 2020-2023  润新知