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)

你可能感兴趣的:(python,python,开发语言)