当前位置:网站首页>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边栏推荐
- Ultra detailed visual studio 2019 running littlevgl (lvgl) simulator
- Closure, prototype and original link
- For loops and functions
- 软考网络工程师
- Solve Jupiter: the term 'Jupiter' is not recognized as the name of a cmdlet, function, script file
- Sword finger offer II 056. Sum of two nodes in a binary search tree (simple binary search tree DFS hash table double pointer iterator)
- 二进制的原码、反码、补码
- The function of wechat applet to cut pictures
- 微信小程序剪切图片的功能
- 静态成员static详解
猜你喜欢

Using PCL to batch display PCD point cloud data flow

How about the actual use effect of common source oscilloscope

JMeter installs third-party plug-ins plugins Manager

Vscode ROS configuration GDB debugging error record

842. Arrange numbers

使用PCL批量将点云.bin文件转.pcd

The function of wechat applet to cut pictures

php二维数组如何删除去除第一行元素

The blueprint of flask complements openpyxl

C language to realize string reverse order arrangement
随机推荐
winform跳转第二个窗体案例
Detection and tracking evaluation index
Sword finger offer II 063. replacement word (medium prefix tree string)
Container configuration starts redis cluster single machine 6 nodes 3 Master 3 slave
Soft exam network engineer
静态成员static详解
Binary source code, inverse code, complement code
LVS+KeepAlived高可用部署实战应用
mysql8.0无法给用户授权或提示You are not allowed to create a user with GRANT的问题
STM32 - interrupt overview (interrupt priority)
STM32CUBEIDE(10)----ADC在DMA模式下扫描多个通道
PHP库neo4j怎么安装及使用
使用PCL批量将点云.bin文件转.pcd
JS convert numbers to letters
Research cup element recognition multi label classification task based on ernie-3.0 cail2019 method
(翻译)图技术简明历史
Sword finger offer II 054. Sum of all values greater than or equal to nodes (medium binary search tree DFS)
Baidu map usage
Att & CK Threat Intelligence
[get mobile information] - get mobile information through ADB command