最近处理一些规格不一的照片,需要修改成指定尺寸便于打印,本篇文章主要给大伙介绍关于Python批量处理将图片进行放大的相关资料,文中通过实例代码介绍的非常详细,需要的伙伴们可以参考下。
python批处理图片放大
有时候对于网络识别,将原始图片放进网络中并不能达到自己想要的效果,但是有时候如果将图片放大之后,识别率却能够达到意想不到的结果,现在提供一种将文件中的图片进行批处理放大的代码:
import osfrom PIL import Imageimport sys
#获取path目录下的所有文件def get_imlist(path):
return[os.path.join(path,f)
for f in os.listdir(path)] def change_size(path):
directorys=get_imlist(path)
for directory in directorys:
#不是图片文件就跳过
print(directory)
if not(directory.endswith('.jpg') or directory.endswith('.png') or directory.endswith('.bmp')):
#
#b pass
else:
img=Image.open(directory)
s="/"
#获取文件名(含后缀)