安装PIL
pip install pillow
修改JPG格式为PGM格式
import os
from PIL import Image
file_src_path = "../frame/" # store jpg images
file_des_path = "../pgm/" # storing pgm format
def jpg2pgm(file_src_path, file_des_path):
images = os.listdir(file_src_path)
for image in images:
current_image = image[:-3] + "pgm" # pgm2jpg:convert pgm to jpg
print("Writing jpg image to pgm file: %s" % current_image)
Image.open(file_src_path+image).save(file_des_path+current_image)
if __name__ == "__main__":
jpg2pgm(file_src_path, file_des_path)
(最近更新:2010年01月09日)
本文介绍如何使用Python的PIL库安装Pillow模块,并提供了将JPG格式图片批量转换为PGM格式的代码示例。通过简单的脚本,可以实现图片格式的快速转换。
1250

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



