博客
关于我
python 实现将RGBA 转换为RGB
阅读量:795 次
发布时间:2023-03-07

本文共 587 字,大约阅读时间需要 1 分钟。

批量处理图片文件

import osimport globfrom PIL import Imageroot_dir = './image_net_mini'dirs = os.listdir(root_dir)for path in dirs:    JPEG_list = glob.glob(root_dir + '/' + path + '/*.jpg')    for jpeg in JPEG_list:        img = Image.open(jpeg)        if img.mode != 'RGB':            img = img.convert('RGB')            print(jpeg)            os.remove(jpeg)            img.save(jpeg)

以上代码实现了一个批量处理图片文件的脚本,主要功能包括:

  • 遍历指定目录下的所有子目录
  • 查找每个子目录下的所有.jpg图片文件
  • 对每张图片进行RGB模式转换,如果原始图片不是RGB模式
  • 删除处理后的临时图片文件
  • 保存转换后的图片到原位置
  • 该脚本适用于对图片格式进行统一处理,确保所有图片都以RGB模式保存,避免后续处理中出现颜色问题。

    通过该脚本可以自动化处理图片文件,减少人工干预,提高工作效率。

    转载地址:http://vsofk.baihongyu.com/

    你可能感兴趣的文章
    python socket模块_Python socket模块实现TCP服务端客户端
    查看>>
    Python SOCKS5代理客户端HTTPS
    查看>>
    Python Soc网络分析:通过使用函数迭代列表来计算机会网络
    查看>>
    Python SQL和NoSQL数据库操作实战
    查看>>
    python stdout flush_sys.stdout.flush()方法的用法
    查看>>
    python string 运算
    查看>>
    Python str与bytes之间的转换
    查看>>
    Python subprocess ffmpeg
    查看>>
    python subprocess Permission denied Errno 13
    查看>>
    Python subprocess.call - 将变量添加到 subprocess.call
    查看>>
    Python Subprocess.Popen 从一个线程
    查看>>
    Python subprocess.Popen 作为 Windows 上的不同用户
    查看>>
    Python subprocess.Popen() 等待完成
    查看>>
    Python Sympy模块NoConversion:收敛到根失败;请尝试n<;15或MaxSteps>;50
    查看>>
    python time模块
    查看>>
    Python Tkinter Multiple Windows 教程
    查看>>
    Python tkinter 中的多处理
    查看>>
    Python tweepy写入到sqlite3 db
    查看>>
    Python TypeError:格式字符串的参数不足
    查看>>
    Python UI自动化测试Page Objects企业级实战
    查看>>