当前位置:网站首页>批量将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)
边栏推荐
- MapReduce中分区数与ReduceTask个数关系比较
- 2022 Henan Mengxin League game (3): Henan University B - reverse pair count
- Yapi installation
- 常函数const的学习
- egg-ts-sequelize-CLI
- MySQL 执行失败的sql是否会计入慢查询?
- egg-sequelize JS编写
- 再获认可 | 赛宁网安连续上榜《CCSIP 2022中国网络安全产业全景图》
- Page pull-up refresh and pull-down loading
- Recursive implementation of exponential enumeration
猜你喜欢

UE4 通过按键控制物体的旋转

2、 Internationally renowned project HelloWorld

TIA botu WinCC Pro controls the display and hiding of layers through scripts

2022河南萌新联赛第(三)场:河南大学 L - 合成游戏

Is this my vs not connected to the database

【语义分割】2018-DeeplabV3+ ECCV

Spark Structured Streaming HelloWorld

Array sort 2

数组排序2

Kubernetes advanced training camp scheduler
随机推荐
Recursive implementation of exponential enumeration
Postman 导入curl 、导出成curl、导出成对应语言代码
1. If function of Excel
2022杭电多校第二场 A.Static Query on Tree(树剖)
Recognized again | saining network security has been listed in the ccsip 2022 panorama of China's network security industry
第三篇如何使用SourceTree提交代码
Array sort 3
Soft exam review and plan
常函数const的学习
How does win11 set the theme color of the status bar? Win11 method of setting theme color of status bar
9、 File upload and download
2022河南萌新联赛第(三)场:河南大学 B - 逆序对计数
Network Security Learning - permission promotion 2
计算离散点的曲率(matlab)
Optimization analysis and efficiency execution of MySQL
Weights & biases (II)
Codeforces Round #807 (Div. 2)
Rotate array minimum number
Kubernetes advanced training camp scheduler
Js手写函数之节流防抖函数