python 批量处理图片

  • Post author:
  • Post category:python


将需要处理的图片放在同一个文件夹中

from PIL import Image
import os
source_path = "D:\\work\\test_image\\"
target_path = "D:\\work\\poly_out\\"
image_list = os.listdir(source_path)
for file in image_list:
    in_filename = source_path+file
    img = Image.open(in_filename)
    data = np.array(img).astype(np.int32)
    ## 一系列图像处理操作
    img_out = Image.fromarray(np.uint8(data)) 
    out_filename = target_path+"图片10_1366_768.png"
    print("Write", out_filename)
    img_out.save(out_filename)



版权声明:本文为summerlq原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。