import os
from PIL import Image as img
i=0
# j=1399
for root, dirs, files in os.walk('D:\pro/tuu',topdown=False):
for dir in dirs:
i += 1
for file in os.listdir(os.path.join(root,dir)):
path=os.path.join(root,dir)
w=img.open(os.path.join(path,'label.png'))
x=dir.split('_')
q=x[0]+'_mask'
w.save('D:\pro\crack\新建文件夹 (2)/new5/%s.png'%(q))
#
# for root, dirs, files in os.walk('D:\pro\Positive2',topdown=False):
# for dir in dirs:
# j += 1
# for file in os.listdir(os.path.join(root,dir)):
# path=os.path.join(root,dir)
# w=img.open(os.path.join(path,'img.png'))
# w.save('D:\pro/new4/%d.png'%(j))ttiqu