PIL库进行图片的resize
from PIL import Image
import os.path
import glob
def convertjpg(jpgfile,outdir,width=768,height=384):
img=Image.open(jpgfile)
new_img=img.resize((width,height),Image.BILINEAR)
new_img.save(os.path.join(outdir,os.path.basename(jpgfile)))
for jpgfile in glob.glob("./training/image_2/*.png"):
convertjpg(jpgfile,"./training_resize/image_2/")
github连接如下:
本文介绍使用Python的PIL库实现图片的resize功能。通过定义一个函数,该函数接受图片文件路径、输出目录及目标宽度和高度作为参数,并利用PIL库对图片进行等比缩放,最终保存为指定尺寸的图片。
1686

被折叠的 条评论
为什么被折叠?



