|
| 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.
|
|
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:
#include <rerun.hpp>
#include <vector>
int main() {
rec.spawn().exit_on_failure();
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
#include <algorithm>
#include <cstdint>
#include <vector>
#include <rerun.hpp>
int main() {
rec.spawn().exit_on_failure();
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);
}
}
rec.log("image_rgb", rerun::Image::from_rgb24(image, {256, 256}));
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",
);
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",
);
std::vector<uint8_t> yuv_bytes(256 * 256 + 128 * 256 * 2);
std::fill_n(yuv_bytes.begin(), 256 * 256, static_cast<uint8_t>(128));
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);
yuv_bytes[v_plane_offset + coord] = static_cast<uint8_t>(y);
}
}
rec.log(
"image_yuv422",
);
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