当前位置:网站首页>批量将PPM格式图片转化为JPG格式
批量将PPM格式图片转化为JPG格式
2022-07-26 04:38:00 【TBYourHero】
亲测可用
(60条消息) 批量将PPM格式图片转化为JPG格式_阿松丶的博客-CSDN博客_ppm转jpg
from PIL import Image
import os
input_train_path = r"E:\test\BelgiumTSC_Training\Training"
output_train_path = r"E:\BelgiumTSC_JPG\Train_data"
input_test_path = r"E:\test\BelgiumTSC_Testing\Testing"
output_test_path = r"E:\BelgiumTSC_JPG\Test_data"
def batch_image(in_dir, out_dir):
if not os.path.exists(out_dir):
print(out_dir, 'is not existed.')
os.mkdir(out_dir)
if not os.path.exists(in_dir):
print(in_dir, 'is not existed.')
return -1
directories = [d for d in os.listdir(in_dir) if os.path.isdir(os.path.join(in_dir, d))]
for d in directories:
# 每一类的路径
label_directory = os.path.join(in_dir, d)
new_directory = os.path.join(out_dir, d)
out_folder = os.path.exists(out_dir + d)
if not out_folder:
os.mkdir(new_directory)
file_names = [os.path.join(label_directory, f) for f in os.listdir(label_directory) if f.endswith(".ppm")]
# file_names is every photo which is end with ".ppm"
count = 0
for files in file_names:
file_path, extfilename = os.path.split(files)
filename, extname = os.path.splitext(extfilename)
out_file = filename + '.jpg'
# print(filepath,',',filename, ',', out_file)
im = Image.open(files)
new_path = os.path.join(new_directory, out_file)
print(count, ',', new_path)
count = count + 1
im.save(new_path)
if __name__ == '__main__':
batch_image(input_test_path, output_test_path)
batch_image(input_train_path, output_train_path)
边栏推荐
- [uoj 429] runs (inclusive) + a little record about Lyndon tree and its application
- Integrated architecture of performance and cost: modular architecture
- Whether the SQL that fails to execute MySQL is counted into the slow query?
- Page pull-up refresh and pull-down loading
- 一个sql server查询截止某个日期最新的记录
- 青少年创客教育的创意设计原理
- Phaser(一):平台跳跃收集游戏
- Rotate array minimum number
- qt编译报错整理及Remote模块下载
- 2022 Henan Mengxin League game (3): Henan University a - corn cannon
猜你喜欢

User defined type details

Authentication Encyclopedia (cookies, sessions, tokens, JWT, single sign on), in-depth understanding and understanding of authentication

Threadpooltaskexecutor and ThreadPoolExecutor

MySQL的优化分析及效率执行

An SQL server queries the latest records as of a certain date

数据仓库

Credit card fraud detection based on machine learning

Face database collection summary

Li Kou daily question - day 42 -661. Picture smoother

Phaser (I): platform jumping collection game
随机推荐
Li Kou daily question - day 42 -661. Picture smoother
MySQL日志分类:错误日志、二进制日志、查询日志、慢查询日志
Yuansaka Lin wallpaper
[300 + selected interview questions from big companies continued to share] big data operation and maintenance sharp knife interview question column (VIII)
[enterprise micro procedure]
Codeforces Round #807 (Div. 2)
idea插件离线安装(持续更新)
egg-ts-sequelize-CLI
Codeforces Round #807 (Div. 2)
五、域对象共享数据
What if win11 cannot wake up from sleep? Solution of win11 unable to wake up during sleep
Steam科学教育赋予课堂教学的创造力
常函数const的学习
Build a maker Education Laboratory for teenagers
Optimization analysis and efficiency execution of MySQL
旋转数组最小数字
Bsdiff and bspatch incremental updates
Authentication Encyclopedia (cookies, sessions, tokens, JWT, single sign on), in-depth understanding and understanding of authentication
Compiled by egg serialize JS
Add watermark to ffmpeg video