Tensorflow图像预处理(3)色彩调整

#图像色彩调整
#调整图片的亮度,对比度,饱和度,色相等

import matplotlib.pyplot as plt

image_raw_data=tf.gfile.GFile("pic/ma.jpg","rb").read()

with tf.Session() as sess:
    img_data=tf.image.decode_jpeg(image_raw_data)
    img_data=tf.image.convert_image_dtype(img_data,dtype=tf.float32)
    #亮度调整
    bri_adjust_down=tf.image.adjust_brightness(img_data,-0.5)           #降低亮度
    bri_adjust_up=tf.image.adjust_brightness(img_data,0.5)              #提高亮度
    bri_adjust_random=tf.image.random_brightness(img_data,0.9)          #在某个范围内随机调整亮度

在这里插入图片描述

 #对比度调整
    contrast_adj_down=tf.image.adjust_contrast(img_data,0.5)            #减少对比度为原先0.5倍
    contrast_adj_up=tf.image.adjust_contrast(img_data,5)                #增加对比度到原来5倍
    contrast_adj_ran=tf.image.random_contrast(img_data,lower=0.1,upper=3)   #一定范围内随机调整对比度

在这里插入图片描述

 #色相
    adjust_hue_01=tf.image.adjust_hue(img_data,0.1)                     #色相相加0.1
    adjust_hue_07 = tf.image.adjust_hue(img_data, 0.7)                  #色相相加0.7
    adjust_hue_ran = tf.image.random_hue(img_data, 0.5)                 #色相随机相加 这里加的值在0-0.5之间
    adjust_hue_07=tf.clip_by_value(adjust_hue_07,0,1.0)                 #截断操作保证像素值在0-1之间

在这里插入图片描述

 #饱和度
    sat_adjust_down=tf.image.adjust_saturation(img_data,-5)             #降低饱和度
    sat_adjust_up = tf.image.adjust_saturation(img_data, 5)           #增加饱和度
    sat_adjust_ran = tf.image.random_saturation(img_data, lower=0,upper=3)          #随机更改饱和度

在这里插入图片描述

  #图像标准化
    std_adjust=tf.image.per_image_standardization(img_data)             #操作后,图像中的数字均值变为0,方差变为1




    fig=plt.figure(figsize=(10,4))
    ax1 = fig.add_subplot(1,3, 1)
    ax2 = fig.add_subplot(1, 3, 2)
    ax3 = fig.add_subplot(1, 3, 3)
    ax1.imshow(std_adjust.eval())
    ax2.imshow(sat_adjust_up.eval())
    ax3.imshow(sat_adjust_ran.eval())

    plt.show()
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值