基于TensorFlow批量的随机处理图片,实现图像增强,亲测可直接用,可以作为参考

基于TensorFlow批量的随机处理图片,实现图像增强

import tensorflow as tf
import os
import random

source_file="./0/" #原始文件地址
target_file="./test2/" #修改后的文件地址
num=50 #产生图片次数

if not os.path.exists(target_file): #如果不存在target_file,则创造一个
os.makedirs(target_file)

file_list=os.listdir(source_file) #读取原始文件的路径

with tf.Session() as sess:
for i in range(num):

    max_random=len(file_list)-1
    a = random.randint(1, max_random)          #随机数字区间
    image_raw_data=tf.gfile.FastGFile(source_file+file_list[a],"rb").read()#读取图片
    print("正在处理:",file_list[a])
    image_data=tf.image.decode_jpeg(image_raw_data)

    filpped_le_re=tf.image.random_flip_left_right(image_data)   #随机左右翻转

    filpped_up_down=tf.image.random_flip_up_down(image_data)    #随机上下翻转

    adjust=tf.image.random_brightness(filpped_up_down,0.4)      #随机调整亮度

    image_data=tf.image.convert_image_dtype(adjust,dtype=tf.uint8)

    encode_data=tf.image.encode_jpeg(image_data)

    with tf.gfile.GFile(target_file+str(i)+"_enhance"+".jpeg","wb") as f:
        f.write(encode_data.eval())

print(“图像增强完毕”)






阅读更多


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值