Skip to content
esc
Start typing to search the docs
Navigate Open

2D

Use a 2D view to inspect images alongside points, bounding boxes, and lines. It is useful for checking detections, segmentation results, and keypoints against the source image.

See the Spatial2DView reference for properties and examples.

XY plots (Y against something other than time)

The X axis of a time series view is always a timeline. To plot Y against another value, for example a trajectory or a phase plot, log the points as Points2D or LineStrips2D and show them in a 2D view:

"""Plot Y against X (not against time) as a line strip in a 2D view."""

import numpy as np

import rerun as rr

rr.init("rerun_example_spatial2d_xy_plot", spawn=True)

x = np.linspace(-3.0, 3.0, 200)
y = np.sin(x) * x
rr.log("xy_plot", rr.LineStrips2D([np.column_stack([x, -y])]))

The 2D view has its Y axis pointing down, like images, so flip the sign of Y.

Covariance ellipses in 2D

Ellipses2D draws ellipses aligned with the X and Y axes. It has no rotation, so for a 2×2 covariance with correlation, draw the outline as a LineStrips2D:

"""Draw a 2D covariance matrix as a rotated ellipse outline."""

import numpy as np

import rerun as rr

rr.init("rerun_example_spatial2d_covariance", spawn=True)

mean = np.array([50.0, 40.0])
covariance = np.array([[30.0, 12.0], [12.0, 10.0]])
k = 2.0

eigenvalues, eigenvectors = np.linalg.eigh(covariance)
angles = np.linspace(0.0, 2.0 * np.pi, 64)
unit_circle = np.stack([np.cos(angles), np.sin(angles)])
half_axes = k * np.sqrt(eigenvalues)[:, None]
outline = mean + (eigenvectors @ (half_axes * unit_circle)).T

rr.log("estimate/covariance_2d", rr.LineStrips2D([outline]))

Labels and keypoints

For label placement, visibility, and limitations, see Text labels. For skeleton annotations shared by 2D and 3D points, see Keypoints and connections.

Segmentation images

Segmentation images are single channel integer images/tensors where each pixel represents a class id. By default, Rerun assigns colors to each class id. Define an annotation context to set the color of each class.

screenshot of a segmentation image

Overlaying annotations on images

To draw boxes, labels, points, or masks on top of an image, log them under the same parent entity as the image, and show that parent in one 2D view:

rr.log("camera/image", rr.Image(rgb))
rr.log("camera/detections", rr.Boxes2D(mins=mins, sizes=sizes, labels=labels, class_ids=class_ids))
rr.log("camera/mask", rr.SegmentationImage(mask, opacity=0.5))

Everything under camera is drawn in the same 2D coordinate space as the image, in pixel coordinates. If the image is part of a 3D scene under a Pinhole, log the 2D annotations under the pinhole entity too.

  • opacity on Image and SegmentationImage makes them translucent. A segmentation image defaults to an opacity of 0.5 when there are other images in the view.
  • draw_order on images, boxes, points, and lines sets what is drawn on top. Higher values are drawn on top of lower values.

The class IDs of the boxes and of the segmentation image use the same annotation context, so they get the same colors and labels.

Show history

By default, a 2D view shows the latest value of each entity at the time cursor. Set time_ranges on Spatial2DView to show trails or accumulate data over time. The 3D history example also applies to 2D views: replace Spatial3DView with Spatial2DView. See visible time ranges for boundary types and timeline selection.

Background and visible bounds

Set background to change the background color and visual_bounds to choose the visible region.

"""Use a blueprint to customize a Spatial2DView."""

import numpy as np

import rerun as rr
import rerun.blueprint as rrb

rr.init("rerun_example_spatial_2d", spawn=True)

# Create a spiral of points:
n = 150
angle = np.linspace(0, 10 * np.pi, n)
spiral_radius = np.linspace(0.0, 3.0, n) ** 2
positions = np.column_stack((
    np.cos(angle) * spiral_radius,
    np.sin(angle) * spiral_radius,
))
colors = np.dstack((
    np.linspace(255, 255, n),
    np.linspace(255, 0, n),
    np.linspace(0, 255, n),
))[0].astype(int)
radii = np.linspace(0.01, 0.7, n)

rr.log("points", rr.Points2D(positions, colors=colors, radii=radii))

# Create a Spatial2D view to display the points.
blueprint = rrb.Blueprint(
    rrb.Spatial2DView(
        origin="/",
        name="2D Scene",
        # Set the background color
        background=[105, 20, 105],
        # Note that this range is smaller than the range of the points,
        # so some points will not be visible.
        visual_bounds=rrb.VisualBounds2D(x_range=[-5, 5], y_range=[-5, 5]),
    ),
    collapse_panels=True,
)

rr.send_blueprint(blueprint)