Rerun C++ SDK
Loading...
Searching...
No Matches
rerun::archetypes::Image Struct Reference

Archetype: A monochrome or color image. More...

#include <rerun/archetypes/image.hpp>

Public Types

using IndicatorComponent = rerun::components::IndicatorComponent< IndicatorComponentName >
 Indicator component, used to identify the archetype when converting to a list of components.
 

Public Member Functions

 Image (Collection< uint8_t > bytes, components::ImageFormat format_)
 Construct an image from bytes and image format.
 
 Image (Collection< uint8_t > bytes, WidthHeight resolution, datatypes::PixelFormat pixel_format)
 Construct an image from resolution, pixel format and bytes.
 
 Image (Collection< uint8_t > bytes, WidthHeight resolution, datatypes::ColorModel color_model, datatypes::ChannelDatatype datatype)
 Construct an image from resolution, color model, channel datatype and bytes.
 
template<typename T >
 Image (Collection< T > elements, WidthHeight resolution, datatypes::ColorModel color_model)
 Construct an image from resolution, color model and elements, inferring the channel datatype from the element type.
 
template<typename T >
 Image (const T *elements, WidthHeight resolution, datatypes::ColorModel color_model)
 Construct an image from resolution, color model and element pointer, inferring the channel datatype from the element type.
 
 Image (Image &&other)=default
 
Image with_opacity (rerun::components::Opacity _opacity) &&
 Opacity of the image, useful for layering several images.
 
Image with_draw_order (rerun::components::DrawOrder _draw_order) &&
 An optional floating point value that specifies the 2D drawing order.
 

Static Public Member Functions

static Image from_greyscale8 (Collection< uint8_t > bytes, WidthHeight resolution)
 Assumes single channel greyscale/luminance with 8-bit per value.
 
static Image from_rgb24 (Collection< uint8_t > bytes, WidthHeight resolution)
 Assumes RGB, 8-bit per channel, packed as RGBRGBRGB….
 
static Image from_rgba32 (Collection< uint8_t > bytes, WidthHeight resolution)
 Assumes RGBA, 8-bit per channel, with separate alpha.
 

Public Attributes

rerun::components::ImageBuffer buffer
 The raw image data.
 
rerun::components::ImageFormat format
 The format of the image.
 
std::optional< rerun::components::Opacityopacity
 Opacity of the image, useful for layering several images.
 
std::optional< rerun::components::DrawOrderdraw_order
 An optional floating point value that specifies the 2D drawing order.
 

Static Public Attributes

static constexpr const char IndicatorComponentName [] = "rerun.components.ImageIndicator"
 

Detailed Description

Archetype: A monochrome or color image.

See also archetypes::DepthImage and archetypes::SegmentationImage.

Rerun also supports compressed images (JPEG, PNG, …), using archetypes::EncodedImage. For images that refer to video frames see archetypes::VideoFrameReference. Compressing images or using video data instead can save a lot of bandwidth and memory.

The raw image data is stored as a single buffer of bytes in a components::Blob. The meaning of these bytes is determined by the components::ImageFormat which specifies the resolution and the pixel format (e.g. RGB, RGBA, …).

The order of dimensions in the underlying components::Blob follows the typical row-major, interleaved-pixel image format.

Since the underlying [rerun::components::Blob] uses rerun::Collection internally, data can be passed in without a copy from raw pointers or by reference from std::vector/std::array/c-arrays. If needed, this "borrow-behavior" can be extended by defining your own rerun::CollectionAdapter.

Examples

image_simple:

image

#include <rerun.hpp>
#include <vector>
int main() {
const auto rec = rerun::RecordingStream("rerun_example_image");
rec.spawn().exit_on_failure();
// Create a synthetic image.
const int HEIGHT = 200;
const int WIDTH = 300;
std::vector<uint8_t> data(WIDTH * HEIGHT * 3, 0);
for (size_t i = 0; i <data.size(); i += 3) {
data[i] = 255;
}
for (size_t y = 50; y <150; ++y) {
for (size_t x = 50; x <150; ++x) {
data[(y * WIDTH + x) * 3 + 0] = 0;
data[(y * WIDTH + x) * 3 + 1] = 255;
data[(y * WIDTH + x) * 3 + 2] = 0;
}
}
rec.log("image", rerun::Image::from_rgb24(data, {WIDTH, HEIGHT}));
}
A RecordingStream handles everything related to logging data into Rerun.
Definition recording_stream.hpp:60

Logging images with various formats

image

#include <algorithm>
#include <cstdint>
#include <vector>
#include <rerun.hpp>
int main() {
const auto rec = rerun::RecordingStream("rerun_example_image_formats");
rec.spawn().exit_on_failure();
// Simple gradient image
std::vector<uint8_t> image(256 * 256 * 3);
for (size_t y = 0; y <256; ++y) {
for (size_t x = 0; x <256; ++x) {
image[(y * 256 + x) * 3 + 0] = static_cast<uint8_t>(x);
image[(y * 256 + x) * 3 + 1] = static_cast<uint8_t>(std::min<size_t>(255, x + y));
image[(y * 256 + x) * 3 + 2] = static_cast<uint8_t>(y);
}
}
// RGB image
rec.log("image_rgb", rerun::Image::from_rgb24(image, {256, 256}));
// Green channel only (Luminance)
std::vector<uint8_t> green_channel(256 * 256);
for (size_t i = 0; i <256 * 256; ++i) {
green_channel[i] = image[i * 3 + 1];
}
rec.log(
"image_green_only",
rerun::Image(rerun::borrow(green_channel), {256, 256}, rerun::ColorModel::L)
);
// BGR image
std::vector<uint8_t> bgr_image(256 * 256 * 3);
for (size_t i = 0; i <256 * 256; ++i) {
bgr_image[i * 3 + 0] = image[i * 3 + 2];
bgr_image[i * 3 + 1] = image[i * 3 + 1];
bgr_image[i * 3 + 2] = image[i * 3 + 0];
}
rec.log(
"image_bgr",
rerun::Image(rerun::borrow(bgr_image), {256, 256}, rerun::ColorModel::BGR)
);
// New image with Separate Y/U/V planes with 4:2:2 chroma downsampling
std::vector<uint8_t> yuv_bytes(256 * 256 + 128 * 256 * 2);
std::fill_n(yuv_bytes.begin(), 256 * 256, static_cast<uint8_t>(128)); // Fixed value for Y
size_t u_plane_offset = 256 * 256;
size_t v_plane_offset = u_plane_offset + 128 * 256;
for (size_t y = 0; y <256; ++y) {
for (size_t x = 0; x <128; ++x) {
auto coord = y * 128 + x;
yuv_bytes[u_plane_offset + coord] = static_cast<uint8_t>(x * 2); // Gradient for U
yuv_bytes[v_plane_offset + coord] = static_cast<uint8_t>(y); // Gradient for V
}
}
rec.log(
"image_yuv422",
rerun::Image(rerun::borrow(yuv_bytes), {256, 256}, rerun::PixelFormat::Y_U_V16_FullRange)
);
return 0;
}
Collection< TElement > borrow(const TElement *data, size_t num_instances=1)
Borrows binary data into a Collection from a pointer.
Definition collection.hpp:461
Archetype: A monochrome or color image.
Definition image.hpp:144

Constructor & Destructor Documentation

◆ Image() [1/5]

rerun::archetypes::Image::Image ( Collection< uint8_t >  bytes,
components::ImageFormat  format_ 
)
inline

Construct an image from bytes and image format.

Parameters
bytesThe raw image data as bytes. If the data does not outlive the image, use std::move or create the rerun::Collection explicitly ahead of time with rerun::Collection::take_ownership. The length of the data should be W * H * image_format.bytes_per_pixel.
format_How the data should be interpreted.

◆ Image() [2/5]

rerun::archetypes::Image::Image ( Collection< uint8_t >  bytes,
WidthHeight  resolution,
datatypes::PixelFormat  pixel_format 
)
inline

Construct an image from resolution, pixel format and bytes.

Parameters
bytesThe raw image data as bytes. If the data does not outlive the image, use std::move or create the rerun::Collection explicitly ahead of time with rerun::Collection::take_ownership. The length of the data should be W * H * pixel_format.bytes_per_pixel.
resolutionThe resolution of the image as {width, height}.
pixel_formatHow the data should be interpreted.

◆ Image() [3/5]

rerun::archetypes::Image::Image ( Collection< uint8_t >  bytes,
WidthHeight  resolution,
datatypes::ColorModel  color_model,
datatypes::ChannelDatatype  datatype 
)
inline

Construct an image from resolution, color model, channel datatype and bytes.

Parameters
bytesThe raw image data. If the data does not outlive the image, use std::move or create the rerun::Collection explicitly ahead of time with rerun::Collection::take_ownership. The length of the data should be W * H * datatype.bytes * color_model.num_channels.
resolutionThe resolution of the image as {width, height}.
color_modelThe color model of the pixel data.
datatypeDatatype of the individual channels of the color model.

◆ Image() [4/5]

template<typename T >
rerun::archetypes::Image::Image ( Collection< T >  elements,
WidthHeight  resolution,
datatypes::ColorModel  color_model 
)
inline

Construct an image from resolution, color model and elements, inferring the channel datatype from the element type.

Parameters
elementsPixel data as a rerun::Collection. If the data does not outlive the image, use std::move or create the rerun::Collection explicitly ahead of time with rerun::Collection::take_ownership. The length of the data should be W * H * color_model.num_channels.
resolutionThe resolution of the image as {width, height}.
color_modelThe color model of the pixel data. Each element in elements is interpreted as a single channel of the color model.

◆ Image() [5/5]

template<typename T >
rerun::archetypes::Image::Image ( const T *  elements,
WidthHeight  resolution,
datatypes::ColorModel  color_model 
)
inline

Construct an image from resolution, color model and element pointer, inferring the channel datatype from the element type.

Parameters
elementsThe raw image data. ⚠️ Does not take ownership of the data, the caller must ensure the data outlives the image. The number of elements is assumed to be W * H * color_model.num_channels.
resolutionThe resolution of the image as {width, height}.
color_modelThe color model of the pixel data. Each element in elements is interpreted as a single channel of the color model.

Member Function Documentation

◆ from_greyscale8()

static Image rerun::archetypes::Image::from_greyscale8 ( Collection< uint8_t >  bytes,
WidthHeight  resolution 
)
inlinestatic

Assumes single channel greyscale/luminance with 8-bit per value.

Parameters
bytesPixel data as a rerun::Collection. If the data does not outlive the image, use std::move or create the rerun::Collection explicitly ahead of time with rerun::Collection::take_ownership. The length of the data should be W * H.
resolutionThe resolution of the image as {width, height}.

◆ from_rgb24()

static Image rerun::archetypes::Image::from_rgb24 ( Collection< uint8_t >  bytes,
WidthHeight  resolution 
)
inlinestatic

Assumes RGB, 8-bit per channel, packed as RGBRGBRGB….

Parameters
bytesPixel data as a rerun::Collection. If the data does not outlive the image, use std::move or create the rerun::Collection explicitly ahead of time with rerun::Collection::take_ownership. The length of the data should be W * H * 3.
resolutionThe resolution of the image as {width, height}.

◆ from_rgba32()

static Image rerun::archetypes::Image::from_rgba32 ( Collection< uint8_t >  bytes,
WidthHeight  resolution 
)
inlinestatic

Assumes RGBA, 8-bit per channel, with separate alpha.

Parameters
bytesPixel data as a rerun::Collection. If the data does not outlive the image, use std::move or create the rerun::Collection explicitly ahead of time with rerun::Collection::take_ownership. The length of the data should be W * H * 4.
resolutionThe resolution of the image as {width, height}.

◆ with_opacity()

Image rerun::archetypes::Image::with_opacity ( rerun::components::Opacity  _opacity) &&
inline

Opacity of the image, useful for layering several images.

Defaults to 1.0 (fully opaque).

◆ with_draw_order()

Image rerun::archetypes::Image::with_draw_order ( rerun::components::DrawOrder  _draw_order) &&
inline

An optional floating point value that specifies the 2D drawing order.

Objects with higher values are drawn on top of those with lower values.

Member Data Documentation

◆ opacity

std::optional<rerun::components::Opacity> rerun::archetypes::Image::opacity

Opacity of the image, useful for layering several images.

Defaults to 1.0 (fully opaque).

◆ draw_order

std::optional<rerun::components::DrawOrder> rerun::archetypes::Image::draw_order

An optional floating point value that specifies the 2D drawing order.

Objects with higher values are drawn on top of those with lower values.


The documentation for this struct was generated from the following file: