当前位置:网站首页>Pictures are named in batches in order (change size /jpg to PNG) [tips]
Pictures are named in batches in order (change size /jpg to PNG) [tips]
2022-07-28 22:41:00 【It's too simple】
explain : The name after sorting comes from the one-to-one correspondence between the truth graph and the original graph in the segmentation test task , To calculate the segmentation effect . Standard naming (eg:000,010,200) Also for the source program sort() Use of functions .
Use :tot_path Write the folder address to be named in batch ,new_tot_path Write the folder address to be transferred after naming .
Be careful :.sort() The sorting method of functions and natsorted() The sorting of functions is different , Can pass print() Check the sorting rules and make a good judgment .
import os
from PIL import Image
from glob import glob
from natsort import natsorted, ns
tot_path = ''
new_tot_path = ''
os.makedirs(new_tot_path,exist_ok=True)
# path = glob(os.path.join(tot_path,'*.jpg'))
path = os.listdir(tot_path)
path.sort()
# pat = natsorted(path, alg=ns.PATH)
i = 1
for pho in path:
# print(pho)
os.chdir(tot_path)
img = Image.open('./' + pho)
# img2 = img.resize((32 , 32))
if i < 10: # 0-9
newname = "00" + str(i)
elif i > 9 and i < 100: # 10-100
newname = "0" + str(i)
elif i > 99 and i < 1000: # 100-1000
newname = str(i)
img.save(new_tot_path + '/' + newname + '.png')
i = i + 1边栏推荐
- 6K6w5LiA5qyh5pS75Ye75YiG5p6Q
- Mysql8.0 cannot authorize users or prompt you are not allowed to create a user with grant
- 776. String shift inclusion problem
- Jianzhi offer II 062. implement prefix tree (medium design dictionary tree prefix tree string)
- Sword finger offer II 052. flatten binary search tree (simple binary search tree DFS)
- Sword finger offer II 053. Medium order successor in binary search tree (medium binary search tree DFS)
- Sword finger offer II 056. Sum of two nodes in a binary search tree (simple binary search tree DFS hash table double pointer iterator)
- 842. 排列数字
- There will be a black line on the border when the button in the wechat applet is clicked
- STM32CUBEIDE(10)----ADC在DMA模式下扫描多个通道
猜你喜欢
![[Ruiji takeout project]day4 - dish management](/img/2a/2d9deb7a583aa37b38a67ef2c74ee7.png)
[Ruiji takeout project]day4 - dish management

imx6q gpio复用

Solve Jupiter: the term 'Jupiter' is not recognized as the name of a cmdlet, function, script file

微信小程序剪切图片的功能

Vscode ROS configuration GDB debugging error record

c语言实现字符串逆序排列

6K6w5LiA5qyh5pS75Ye75YiG5p6Q

Att & CK preliminary understanding

Idea generate class diagram plug-in UML (super detailed)

Static details of static members
随机推荐
The function of wechat applet to cut pictures
NPM switch Taobao source (NPM source)
Sword finger offer II 052. flatten binary search tree (simple binary search tree DFS)
96. Different binary search trees (medium binary search tree dynamic planning)
redis相关
Binary source code, inverse code, complement code
Sword finger offer II 064. magic Dictionary (medium dictionary tree string design)
微信小程序使用canvas绘图,圆形头像,网络背景图,文字,虚线,直线
Sword finger offer II 066. sum of words (medium prefix tree design string)
Container configuration starts redis cluster single machine 6 nodes 3 Master 3 slave
PaddleNLP基于ERNIR3.0文本分类以CAIL2018-SMALL数据集罪名预测任务为例【多标签】
PaddleNLP基于ERNIR3.0文本分类以中医疗搜索检索词意图分类(KUAKE-QIC)为例【多分类(单标签)】
Awk blank line filtering
32. Longest valid bracket (difficult stack string)
76. Minimum coverage substring (hard sliding window hash table string)
Win11 how to open software notification
770. 单词替换
Solve various problems of sudo rosdep init and rosdep update
STM32CUBEIDE(10)----ADC在DMA模式下扫描多个通道
20-09-27项目迁移到阿里折腾记录(网卡顺序导致服务无法通过haproxy连接到db)