当前位置:网站首页>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边栏推荐
- For loops and functions
- 105. Construct binary tree from preorder and inorder traversal sequence (medium binary tree DFS hash table binary tree)
- Sword finger offer II 066. sum of words (medium prefix tree design string)
- Common commands of NPM
- 76. Minimum coverage substring (hard sliding window hash table string)
- Winserver operation and maintenance technology stack
- Sword finger offer II 052. flatten binary search tree (simple binary search tree DFS)
- STM32 - Communication
- fatal error: io. h: No such file or directory
- JS implementation generates a random key of specified length
猜你喜欢

CMD common commands
![[connect set-top box] - use ADB command line to connect ec6108v9 Huawei Yuehe box wirelessly](/img/ab/624e9a3240416f8445c908378310ad.png)
[connect set-top box] - use ADB command line to connect ec6108v9 Huawei Yuehe box wirelessly

STM32 - interrupt overview (interrupt priority)

2022年一级建造师考试什么时候才能报名?

STM32 -- program startup process

Paddlenlp text classification based on ernir3.0: take wos dataset as an example (hierarchical classification)

What are the main functions and uses of LCR tester

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

The blueprint of flask complements openpyxl

LVS+KeepAlived高可用部署实战应用
随机推荐
Awk blank line filtering
近期bug总结
Sword finger offer II 057. the difference between the value and the subscript is within the given range (medium array bucket sort sliding window TreeSet)
775. Inverted words
Sword finger offer II 067. maximum XOR (medium prefix tree bit operation array)
SSH password free login
What are the main functions and uses of LCR tester
imx6q gpio复用
[reprint] the token token is used in the login scenario
Netease Yunxin 2022q2 product supply station, come and get your product supply plan!
AWK空行过滤
Qt+FFmpeg环境搭建
Excel-VBA 快速上手(十三、日期的常见用法)
Summary of common error types in JS
STM32 - Communication
ES6 concept
LeetCode刷题系列之-多数之和类型
The blueprint of flask complements openpyxl
770. 单词替换
Chrome encountered a problem when debugging the code. After modifying and saving the code in vscode, chrome did not update after refreshing