Implementation:CARLA simulator Carla ImageView
| Knowledge Sources | |
|---|---|
| Domains | Image, ColorConversion |
| Last Updated | 2026-02-15 05:00 GMT |
Overview
ImageView provides factory methods for creating Boost.GIL image views from CARLA sensor images and for applying color conversion transformations to those views.
Description
The ImageView class in carla::image acts as a factory for Boost.GIL views over CARLA sensor image data. It provides two categories of static methods:
MakeView overloads:
- Generic template: Wraps any GIL-compatible image with boost::gil::view().
- CARLA Color image specializations: For ImageTmpl<Color> (mutable and const), creates interleaved views by reinterpreting the CARLA sensor::data::Color pixel data as boost::gil::bgra8_pixel_t or bgra8c_pixel_t (BGRA 8-bit pixel layout). The row stride is calculated as sizeof(Color) * width.
MakeColorConvertedView overloads:
These create lazy (on-demand) color-converted views using Boost.GIL's deferred color conversion mechanism:
- Generic converter: Accepts any CC functor and produces a view with DstPixelT output pixels.
- Depth converter: Specialization for ColorConverter::Depth that defaults to gray pixel output matching the source channel type.
- LogarithmicDepth converter: Chains two conversions: first Depth to gray32f_pixel_t intermediate, then LogarithmicLinear to the final output pixel type.
- CityScapesPalette converter: Specialization that defaults the output pixel type to match the source view's value type.
Internally, the _MakeColorConvertedView private method uses a color_converted_type helper struct that wraps GIL's color_convert_deref_fn to create a deref-adapting view with the custom color converter.
Usage
Use ImageView::MakeView to create GIL views over sensor images, then apply MakeColorConvertedView with the appropriate ColorConverter functor to transform the pixel data for visualization or further processing.
Code Reference
Source Location
- Repository: CARLA
- File:
LibCarla/source/carla/image/ImageView.h
Signature
class ImageView {
public:
// Create a GIL view from a generic image
template <typename ImageT>
static auto MakeView(ImageT &image);
// Create a GIL view from a CARLA Color sensor image
static auto MakeView(sensor::data::ImageTmpl<sensor::data::Color> &image);
static auto MakeView(const sensor::data::ImageTmpl<sensor::data::Color> &image);
// Color-converted views
template <typename SrcViewT, typename DstPixelT, typename CC>
static auto MakeColorConvertedView(const SrcViewT &src, CC cc);
template <typename SrcViewT, typename DstPixelT = GrayPixelLayout<SrcViewT>>
static auto MakeColorConvertedView(const SrcViewT &src, ColorConverter::Depth cc);
template <typename SrcViewT, typename DstPixelT = GrayPixelLayout<SrcViewT>>
static auto MakeColorConvertedView(const SrcViewT &src, ColorConverter::LogarithmicDepth);
template <typename SrcViewT, typename DstPixelT = typename SrcViewT::value_type>
static auto MakeColorConvertedView(const SrcViewT &src, ColorConverter::CityScapesPalette cc);
};
Import
#include "carla/image/ImageView.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| image | ImageT& or ImageTmpl<Color>& | Yes (MakeView) | Source image to create a view over |
| src | SrcViewT | Yes (MakeColorConvertedView) | Source GIL view to apply color conversion to |
| cc | ColorConverter functor | Yes (MakeColorConvertedView) | Color conversion functor (Depth, LogarithmicDepth, CityScapesPalette, or custom) |
Outputs
| Name | Type | Description |
|---|---|---|
| MakeView() | GIL view type | A Boost.GIL interleaved view over the image data |
| MakeColorConvertedView() | deferred GIL view | A lazy color-converted view that transforms pixels on access |
Usage Examples
// Create a view from a CARLA sensor image
auto view = ImageView::MakeView(sensorImage);
// Create a depth-converted grayscale view
auto depthView = ImageView::MakeColorConvertedView(
view, ColorConverter::Depth{});
// Create a logarithmic depth view
auto logView = ImageView::MakeColorConvertedView(
view, ColorConverter::LogarithmicDepth{});
// Create a semantic segmentation colored view
auto segView = ImageView::MakeColorConvertedView(
view, ColorConverter::CityScapesPalette{});
// Use with Boost.GIL algorithms
boost::gil::png_write_view("output.png", segView);