Annotation Context

Overview overview

Any visualization that assigns an identifier ("Class ID") to an instance or entity can benefit from using Annotations. By using an Annotation Context, you can associate labels and colors with a given class and then re-use that class across entities.

This is particularly useful for visualizing the output of classifications algorithms (as demonstrated by the Detect and Track Objects example), but can be used more generally for any kind of reoccurring categorization within a Rerun recording.

viewer screenshot showing various tracked objects and their class ids

Keypoints & keypoint connections keypoints--keypoint-connections

Rerun allows you to define keypoints within a class. Each keypoint can define its own properties (colors, labels, etc.) that overwrite its parent class.

A typical example usage of keypoints is annotating the joints of a skeleton within a pose detection. In that case, the entire detected pose/skeleton is assigned a Class ID and each joint within gets a Keypoint ID.

To help you more with this (and similar) use-case(s), you can also define connections between keypoints as part of your annotation class description. The Viewer will draw the connecting lines for all connected keypoints whenever that class is used. Just as with labels and colors this allows you to use the same connection information on any instance that class in your scene.

Keypoints are currently only applicable to 2D and 3D points.

keypoint shown on a 3D skeleton

Logging an annotation context logging-an-annotation-context

Annotation Context is typically logged as timeless data, but can change over time if needed.

The Annotation Context is defined as a list of Class Descriptions that define how classes are styled (as well as optional keypoint style and connection).

Annotation contexts are logged with:

import rerun as rr

# Annotation context with two classes, using two labeled classes, of which ones defines a color.
rr.log(
    "masks",  # Applies to all entities below "masks".
    rr.AnnotationContext(
        [
            rr.AnnotationInfo(id=0, label="Background"),
            rr.AnnotationInfo(id=1, label="Person", color=(255, 0, 0)),
        ],
    ),
    static=True,
)

# Annotation context with simple keypoints & keypoint connections.
rr.log(
    "detections",  # Applies to all entities below "detections".
    rr.ClassDescription(
        info=rr.AnnotationInfo(0, label="Snake"),
        keypoint_annotations=[rr.AnnotationInfo(id=i, color=(0, 255 / 9 * i, 0)) for i in range(10)],
        keypoint_connections=[(i, i + 1) for i in range(9)],
    ),
    static=True,
)

Affected entities affected-entities

Each entity that uses a Class ID component (and optionally Keypoint ID components) will look for the nearest ancestor that in the entity path hierarchy that has an Annotation Context defined.

Segmentation images segmentation-images

Segmentation images are single channel integer images/tensors where each pixel represents a class id. By default, Rerun will automatically assign colors to each class id, but by defining an Annotation Context, you can explicitly determine the color of each class.

screenshot of a segmentation image