from PIL import Image
import glob
import os
# 对图片解码
def decode_mask(path):
out_base_path = '...../KITTI-tracking/decode_mask' #输出文件夹
folders = sorted(glob.glob(os.path.join(path, '*')))
for folder in folders:
temp_1 = folder.split('/')
samples = []
samples.extend(sorted(glob.glob(os.path.join(folder, '*.png'))))
out_path = os.path.join(out_base_path, '{}'.format(temp_1[-1]))
os.makedirs(out_path, exist_ok=True)
for sample in samples:
temp_2 = sample.split('/')
mask = Image.open(sample)
mask_8bits = mask.convert('L')
out = os.path.join(out_path, temp_2[-1])
mask_8bits.save(os.path.join(out_path,out))
decode_mask(#路径#)