def METHOD_NAME(maskpath, out_mask_dir, is_train):
    mask = np.array(Image.open(maskpath))
    mask_copy = mask.copy()
    for clsID, trID in clsID_to_trID.items():
        mask_copy[mask == clsID] = trID
    seg_filename = osp.join(out_mask_dir, 'train2017',
                            osp.basename(maskpath)) if is_train else osp.join(
                                out_mask_dir, 'val2017',
                                osp.basename(maskpath))
    Image.fromarray(mask_copy).save(seg_filename, 'PNG')