import numpy as np
import imageio
from PIL import Image
import os.path
import PIL
import glob
'''
文件夹需要提前创建好
'''
def rename(path):
map_path = [str(path) + str(x) for x in os.listdir(path) if os.path.isfile(str(path) + str(x))]
for idx, folder in enumerate(map_path):
image = np.array(PIL.Image.open(folder))
imageio.imwrite('E:/三类图片/狗_标签化/' + '2' + '_' + str(idx) + '.jpg', image) # 要保存的标签化地址
def convertjpg(jpgfile, outdir, width=64, height=64):
img = Image.open(jpgfile)
try:
new_image = img.resize((width, height), Image.BILINEAR)
new_image.save(os.path.join(outdir, os.path.basename(jpgfile)))
except Exception as e:
print(e)
def resize(path):
for jpgfile in glob.glob("E:/三类图片/狗/*.jpg"):
convertjpg(jpgfile, path)
if __name__ == '__main__':
path = r"E:/三类图片/狗_尺寸化/"
resize(path) # 先进行尺寸的调整
rename(path) # 再进行有标签重命名