python如何保存源文件_在python中,如何将处理后的图像保存到一个文件夹中的不同文件夹中?...

我有代码,通过一个文件夹'图像'和然后子文件夹和处理所有这些图像。在

我现在需要将这些图像保存到一个并行目录中,即一个名为“已处理图像”的文件夹(与“images”文件夹位于同一目录中),然后保存到该文件夹中的子文件夹中-这些子文件夹的名称与“images”中的子文件夹的名称相同-图像应保存到与其来源相同的子文件夹中。在

我可以将图像保存到“已处理图像”,但不能保存其中的子文件夹。在path = ("...\\Images")

for dirName, subdirList, fileList, in os.walk(path):

for file in fileList:

full_file_path = os.path.join(dirName, file)

if file.endswith((".jpg")):

image_file = Image.open(full_file_path)

image_file = image_file.convert('L')

image_file = PIL.ImageOps.invert(image_file)

image_file = image_file.resize((28, 28))

new_filename = file.split('.jpg')[0] + 'new.png'

path2 = ("...\\Processed Images")

image_file.save(os.path.join(path2, new_filename))

else: continue

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值