当前位置:网站首页>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)
边栏推荐
- The difference between positive samples, negative samples, simple samples and difficult samples in deep learning (simple and easy to understand)
- 常函数const的学习
- 1、 Basic introduction
- Codeforces Round #807 (Div. 2)
- What if win11 cannot wake up from sleep? Solution of win11 unable to wake up during sleep
- Scroll view pull-down refresh and pull-up load (bottom)
- 11、 Exception handler
- UE4 switching of control rights of multiple roles
- 2022杭电多校第二场 A.Static Query on Tree(树剖)
- 数据库启动报:ORA-29702: error occurred in Cluster Group Service
猜你喜欢

Creative design principle of youth maker Education
![[semantic segmentation] 2018-deeplabv3+ ECCV](/img/c9/d1e2d7e63df8db2a7fa2bde31b10f7.png)
[semantic segmentation] 2018-deeplabv3+ ECCV

QT compilation error sorting and remote module Download

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

Offline installation of idea plug-in (continuous update)

Threadpooltaskexecutor and ThreadPoolExecutor

UE4 displays text when it is close to the object, and disappears when it is far away

1. If function of Excel

What if win11 cannot wake up from sleep? Solution of win11 unable to wake up during sleep

How to build an automated testing framework?
随机推荐
FFmpeg 视频编码
2022 a.static query on tree (tree section)
Keil V5 installation and use
Credit card fraud detection based on machine learning
Integrated architecture of performance and cost: modular architecture
Rotate array minimum number
Embedded practice -- CPU utilization statistics based on rt1170 FreeRTOS (24)
UE4 switching of control rights of multiple roles
UE4 获取玩家控制权的两种方式
Calculate the curvature of discrete points (matlab)
C language lseek() function: move the read and write location of the file
SQL encryption and decryption injection details
Tutorial on using the one click upgrade function of the rtsp/onvif protocol video platform easynvr service
Add watermark to ffmpeg video
MySQL - multi table query - Cartesian product sum, correct multi table query, equivalent connection and unequal connection, inner connection and outer connection
The auxiliary role of rational cognitive educational robot in teaching and entertainment
idea插件离线安装(持续更新)
MapReduce中分区数与ReduceTask个数关系比较
Fill in the vacancy, and fill in later
Array sort 3