Implementation:CARLA simulator Carla ColorConverter
| Knowledge Sources | |
|---|---|
| Domains | Image, ColorConversion |
| Last Updated | 2026-02-15 05:00 GMT |
Overview
ColorConverter is a collection of pixel color conversion functors used with Boost.GIL to transform raw sensor image data into human-interpretable formats such as depth visualization and semantic segmentation coloring.
Description
The ColorConverter class in carla::image contains four nested functor types, each implementing Boost.GIL's color conversion protocol:
LogarithmicLinear: Converts a gray32fc_pixel_t (32-bit float grayscale) source pixel to a destination pixel using a logarithmic transformation. The formula 1.0 + log(src) / 5.70378 maps the input range to [0.005, 1.0] via clamping, providing better visual contrast for depth data.
Depth: Converts an RGB pixel to a normalized grayscale depth value. It reconstructs the 24-bit depth from the red, green (x256), and blue (x65536) channels, then normalizes to [0, 1] by dividing by (256^3 - 1). The source pixel must have 1-byte channels.
LogarithmicDepth: A tag struct (no operator()) that signals ImageView::MakeColorConvertedView to chain two conversions: first Depth to produce a 32-bit float intermediate, then LogarithmicLinear to produce the final output. This provides logarithmic depth visualization.
CityScapesPalette: Converts a source pixel to a colored destination by reading the red channel as a semantic segmentation tag ID and looking up the RGB color in image::CityScapesPalette::GetColor(). The source must have 1-byte channels.
Usage
These functors are passed to ImageView::MakeColorConvertedView to create lazy color-converted views of sensor images. They are used in the Python API and client-side processing to convert raw sensor output for visualization.
Code Reference
Source Location
- Repository: CARLA
- File:
LibCarla/source/carla/image/ColorConverter.h
Signature
class ColorConverter {
public:
struct LogarithmicLinear {
template <typename DstPixelT>
void operator()(const boost::gil::gray32fc_pixel_t &src, DstPixelT &dst) const;
};
struct Depth {
template <typename SrcPixelT, typename DstPixelT>
void operator()(const SrcPixelT &src, DstPixelT &dst) const;
};
struct LogarithmicDepth {}; // tag type, no operator()
struct CityScapesPalette {
template <typename SrcPixelT, typename DstPixelT>
void operator()(const SrcPixelT &src, DstPixelT &dst) const;
};
};
Import
#include "carla/image/ColorConverter.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| src (LogarithmicLinear) | gray32fc_pixel_t | Yes | 32-bit float grayscale pixel |
| src (Depth) | SrcPixelT (RGB, 1-byte channels) | Yes | RGB pixel encoding 24-bit depth |
| src (CityScapesPalette) | SrcPixelT (RGB, 1-byte channels) | Yes | Pixel with segmentation tag in red channel |
Outputs
| Name | Type | Description |
|---|---|---|
| dst (LogarithmicLinear) | DstPixelT | Logarithmically-scaled grayscale pixel |
| dst (Depth) | DstPixelT | Normalized linear depth as grayscale pixel |
| dst (CityScapesPalette) | DstPixelT | RGB pixel colored according to CityScapes palette |
Usage Examples
// Create a color-converted view for depth visualization
auto depthView = ImageView::MakeColorConvertedView(
ImageView::MakeView(depthImage),
ColorConverter::Depth{});
// Create a logarithmic depth view
auto logDepthView = ImageView::MakeColorConvertedView(
ImageView::MakeView(depthImage),
ColorConverter::LogarithmicDepth{});
// Create a semantic segmentation colored view
auto segView = ImageView::MakeColorConvertedView(
ImageView::MakeView(segImage),
ColorConverter::CityScapesPalette{});