Python 代码:合并多个文件夹的图像并生成新图像
import os from PIL import Image
path1 = r'D:\论文代码\spectrograms' path2 = r'D:\论文代码\语谱图' path3 = r'D:\论文代码\MFCC' new_path = r'D:\论文代码\new'
for root, dirs, files in os.walk(path1): for file in files: if file.endswith('.png'): img1 = Image.open(os.path.join(root, file)) img2 = Image.open(os.path.join(path2, root.split('\')[-1], file)) img3 = Image.open(os.path.join(path3, root.split('\')[-1], file)) new_img = Image.blend(img1, img2, 0.5) new_img = Image.blend(new_img, img3, 0.5) new_dir = os.path.join(new_path, root.split('\')[-1]) if not os.path.exists(new_dir): os.makedirs(new_dir) new_img.save(os.path.join(new_dir, file))
原文地址: http://www.cveoy.top/t/topic/nI8q 著作权归作者所有。请勿转载和采集!