sep_labels.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:rec-attend-public 作者: renmengye 项目源码 文件源码
def get_separate_labels(label_img):
    # 64-bit encoding
    dtype = label_img.dtype
    if dtype == np.uint8:
        w = 8
    elif dtype == np.uint16:
        w = 16
    else:
        raise Exception('Unknown dtype: "{}"'.format(dtype))
    l64 = label_img.astype('uint64')
    # Single channel mapping
    if len(l64.shape) == 3:
        l64i = ((l64[:, :, 0] << 2 * w) + (l64[:, :, 1] << w) + l64[:, :, 2])
    else:
        l64i = l64
    colors = np.unique(l64i)
    segmentations = []
    colors_all = []
    for c in colors:
        if c != 0:
            segmentation = (l64i == c).astype('uint8')
            segmentations.append(segmentation)
            colors_all.append(c)
    return segmentations, colors_all
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号