python批处理将图片进行放大

发布时间:2022-06-28 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了python批处理将图片进行放大脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

有时候对于网络识别,将原始图片放进网络中并不能达到自己想要的效果,但是有时候如果将图片放大之后,识别率却能够达到意想不到的结果现在提供一种将文件中的图片进行批处理放大的代码:

import os
​
from PIL import Image
import 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="/"
            #获取文件名(含后缀)
            oimage_name=directory[directory.rfind(s)+1:]
            (oimage_width,oimage_height)=img.size
            new_width=oimage_width * 3
            new_height=oimage_height * 3
            out=img.resize((new_width,new_height),Image.ANTIALIAS)
            out.save("%s" %oimage_name)  #直接替换
 
 
if __name__ == '__main__':
    change_size("F:桌面\test")

python批处理将图片进行放大

脚本宝典总结

以上是脚本宝典为你收集整理的python批处理将图片进行放大全部内容,希望文章能够帮你解决python批处理将图片进行放大所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: