#12939·rerun

对于类 ID > 128,分段类 ID 颜色查找偏移了一位

作者: efreidun创建于 2026年9月18日更新于 2026年9月18日
标签🪳 bug👀 needs triage

import numpy as np import rerun as rr

SEGMENTATION_CLASSES = { 0: ("black", (0, 0, 0)), 1: ("red", (255, 0, 0)), 2: ("yellow", (255, 255, 0)), 64: ("light_blue", (0, 128, 255)), 126: ("light_green", (128, 255, 0)), 127: ("magenta", (255, 0, 255)), 128: ("blue", (0, 0, 255)), 129: ("grey", (128, 128, 128)), 130: ("orange", (255, 128, 0)), 131: ("purple", (128, 0, 128)), 132: ("green", (0, 255, 0)), }

def main(): rr.init("test", spawn=True)

rr.log(
    "segmentation_mask",
    rr.AnnotationContext([
        (class_id, name, color)
        for class_id, (name, color) in SEGMENTATION_CLASSES.items()
    ]),
    static=True,
)

# Test mask: one equal-width vertical band per class, in ascending class id order.
class_ids = sorted(SEGMENTATION_CLASSES)
band_width = 8
mask = np.zeros((8, band_width * len(class_ids)), dtype=np.uint8)
for i, class_id in enumerate(class_ids):
    mask[:, i * band_width:(i + 1) * band_width] = class_id

rr.log("segmentation_mask", rr.SegmentationImage(mask))

if name == "main": main()