当前位置:网站首页>Batch convert ppm format pictures to JPG format
Batch convert ppm format pictures to JPG format
2022-07-26 04:38:00 【TBYourHero】
Close test available
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:
# Path of each class
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)
边栏推荐
- How to build an automated testing framework?
- Compiled by egg serialize TS
- Postman 导入curl 、导出成curl、导出成对应语言代码
- 旋转数组最小数字
- AWS Support Plan
- 第三篇如何使用SourceTree提交代码
- The auxiliary role of rational cognitive educational robot in teaching and entertainment
- 嵌入式实操----基于RT1170 FreeRTOS实现CPU使用率统计(二十四)
- UE4 通过按键控制物体的旋转
- How does win11 change the power mode? Win11 method of changing power mode
猜你喜欢

常函数const的学习

数组排序2

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

How does win11 change the power mode? Win11 method of changing power mode

Embedded practice -- CPU utilization statistics based on rt1170 FreeRTOS (24)

ES6 modularization +commonjs

【语义分割】2018-DeeplabV3+ ECCV

"Game engine light in light out" 4. shader

7、 Restful

1. If function of Excel
随机推荐
补位,稍后补上
2022杭电多校第二场 A.Static Query on Tree(树剖)
Yapi installation
[300 + selected interview questions from big companies continued to share] big data operation and maintenance sharp knife interview question column (VIII)
Codeforces Round #807 (Div. 2)
Bsdiff and bspatch incremental updates
2022 Henan Mengxin League game (3): Henan University B - reverse pair count
UE4 displays text when it is close to the object, and disappears when it is far away
Weights & biases (II)
数组排序3
Postman imports curl, exports curl, and exports corresponding language codes
ES6 modularization +commonjs
UE4 靠近物体时显示文字,远离时文字消失
Comparison of the relationship between the number of partitions and the number of reducetask in MapReduce
MySQL only checks the reasons for the slow execution of one line statements
2022 Henan Mengxin League game (3): Henan University a - corn cannon
二、国际知名项目-HelloWorld
Array sort 2
Several methods of realizing high-low byte or high-low word exchange in TIA botu s7-1200
SwiftUI一日速成