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 (const Image &other)=default
 
Imageoperator= (const Image &other)=default
 
Imageoperator= (Image &&other)=default
 
Image with_buffer (const rerun::components::ImageBuffer &_buffer) &&
 The raw image data.
 
Image with_many_buffer (const Collection< rerun::components::ImageBuffer > &_buffer) &&
 This method makes it possible to pack multiple buffer in a single component batch.
 
Image with_format (const rerun::components::ImageFormat &_format) &&
 The format of the image.
 
Image with_many_format (const Collection< rerun::components::ImageFormat > &_format) &&
 This method makes it possible to pack multiple format in a single component batch.
 
Image with_opacity (const rerun::components::Opacity &_opacity) &&
 Opacity of the image, useful for layering several images.
 
Image with_many_opacity (const Collection< rerun::components::Opacity > &_opacity) &&
 This method makes it possible to pack multiple opacity in a single component batch.
 
Image with_draw_order (const rerun::components::DrawOrder &_draw_order) &&
 An optional floating point value that specifies the 2D drawing order.
 
Image with_many_draw_order (const Collection< rerun::components::DrawOrder > &_draw_order) &&
 This method makes it possible to pack multiple draw_order in a single component batch.
 
Collection< ComponentColumncolumns (const Collection< uint32_t > &lengths_)
 Partitions the component data into multiple sub-batches.
 
Collection< ComponentColumncolumns ()
 Partitions the component data into unit-length sub-batches.
 

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.
 
static Image update_fields ()
 Update only some specific fields of a Image.
 
static Image clear_fields ()
 Clear all the fields of a Image.
 

Public Attributes

std::optional< ComponentBatchbuffer
 The raw image data.
 
std::optional< ComponentBatchformat
 The format of the image.
 
std::optional< ComponentBatchopacity
 Opacity of the image, useful for layering several images.
 
std::optional< ComponentBatchdraw_order
 An optional floating point value that specifies the 2D drawing order.
 

Static Public Attributes

static constexpr const char IndicatorComponentName [] = "rerun.components.ImageIndicator"
 
static constexpr const char ArchetypeName [] = "rerun.archetypes.Image"
 The name of the archetype as used in ComponentDescriptors.
 
static constexpr auto Descriptor_buffer
 ComponentDescriptor for the buffer field.
 
static constexpr auto Descriptor_format
 ComponentDescriptor for the format field.
 
static constexpr auto Descriptor_opacity
 ComponentDescriptor for the opacity field.
 
static constexpr auto Descriptor_draw_order
 ComponentDescriptor for the draw_order field.
 

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:462
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_many_buffer()

Image rerun::archetypes::Image::with_many_buffer ( const Collection< rerun::components::ImageBuffer > &  _buffer) &&
inline

This method makes it possible to pack multiple buffer in a single component batch.

This only makes sense when used in conjunction with columns. with_buffer should be used when logging a single row's worth of data.

◆ with_many_format()

Image rerun::archetypes::Image::with_many_format ( const Collection< rerun::components::ImageFormat > &  _format) &&
inline

This method makes it possible to pack multiple format in a single component batch.

This only makes sense when used in conjunction with columns. with_format should be used when logging a single row's worth of data.

◆ with_opacity()

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

Opacity of the image, useful for layering several images.

Defaults to 1.0 (fully opaque).

◆ with_many_opacity()

Image rerun::archetypes::Image::with_many_opacity ( const Collection< rerun::components::Opacity > &  _opacity) &&
inline

This method makes it possible to pack multiple opacity in a single component batch.

This only makes sense when used in conjunction with columns. with_opacity should be used when logging a single row's worth of data.

◆ with_draw_order()

Image rerun::archetypes::Image::with_draw_order ( const 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.

◆ with_many_draw_order()

Image rerun::archetypes::Image::with_many_draw_order ( const Collection< rerun::components::DrawOrder > &  _draw_order) &&
inline

This method makes it possible to pack multiple draw_order in a single component batch.

This only makes sense when used in conjunction with columns. with_draw_order should be used when logging a single row's worth of data.

◆ columns() [1/2]

Collection< ComponentColumn > rerun::archetypes::Image::columns ( const Collection< uint32_t > &  lengths_)

Partitions the component data into multiple sub-batches.

Specifically, this transforms the existing ComponentBatch data into ComponentColumns instead, via ComponentBatch::partitioned.

This makes it possible to use RecordingStream::send_columns to send columnar data directly into Rerun.

The specified lengths must sum to the total length of the component batch.

◆ columns() [2/2]

Collection< ComponentColumn > rerun::archetypes::Image::columns ( )

Partitions the component data into unit-length sub-batches.

This is semantically similar to calling columns with std::vector<uint32_t>(n, 1), where n is automatically guessed.

Member Data Documentation

◆ opacity

std::optional<ComponentBatch> rerun::archetypes::Image::opacity

Opacity of the image, useful for layering several images.

Defaults to 1.0 (fully opaque).

◆ draw_order

std::optional<ComponentBatch> 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.

◆ Descriptor_buffer

constexpr auto rerun::archetypes::Image::Descriptor_buffer
staticconstexpr
Initial value:
= ComponentDescriptor(
ArchetypeName, "buffer",
Loggable<rerun::components::ImageBuffer>::Descriptor.component_name
)
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition image.hpp:167

ComponentDescriptor for the buffer field.

◆ Descriptor_format

constexpr auto rerun::archetypes::Image::Descriptor_format
staticconstexpr
Initial value:
= ComponentDescriptor(
ArchetypeName, "format",
Loggable<rerun::components::ImageFormat>::Descriptor.component_name
)

ComponentDescriptor for the format field.

◆ Descriptor_opacity

constexpr auto rerun::archetypes::Image::Descriptor_opacity
staticconstexpr
Initial value:
= ComponentDescriptor(
ArchetypeName, "opacity",
Loggable<rerun::components::Opacity>::Descriptor.component_name
)

ComponentDescriptor for the opacity field.

◆ Descriptor_draw_order

constexpr auto rerun::archetypes::Image::Descriptor_draw_order
staticconstexpr
Initial value:
= ComponentDescriptor(
ArchetypeName, "draw_order",
Loggable<rerun::components::DrawOrder>::Descriptor.component_name
)

ComponentDescriptor for the draw_order field.


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