Implementation:CARLA simulator Carla CityScapesPalette
| Knowledge Sources | |
|---|---|
| Domains | Image, SemanticSegmentation |
| Last Updated | 2026-02-15 05:00 GMT |
Overview
CityScapesPalette provides a compile-time color lookup table that maps semantic segmentation tag IDs to RGB colors following the CityScapes color convention, extended with custom CARLA-specific tags.
Description
The CityScapesPalette class in carla::image encapsulates a static constexpr palette array (CITYSCAPES_PALETTE_MAP) that maps semantic segmentation tag indices to RGB uint8_t[3] color values. The palette includes 30 entries:
CityScapes standard tags (0-19):
- 0: unlabeled (black), 1: road, 2: sidewalk, 3: building, 4: wall, 5: fence, 6: pole, 7: traffic light, 8: traffic sign, 9: vegetation, 10: terrain, 11: sky, 12: pedestrian, 13: rider, 14: car, 15: truck, 16: bus, 17: train, 18: motorcycle, 19: bicycle
CARLA custom tags (20-29):
- 20: static, 21: dynamic, 22: other, 23: water, 24: road line, 25: ground, 26: bridge, 27: rail track, 28: guard rail, 29: rock
The GetNumberOfTags() static constexpr method returns the total number of entries by dividing the array size by the element size. The GetColor(uint8_t tag) method returns the RGB array for a given tag, using modulo arithmetic to prevent out-of-bounds access if the tag exceeds the palette size.
The palette array is declared inline when compiling with C++17 or later to avoid multiple-definition issues across translation units.
Usage
This palette is used by the ColorConverter::CityScapesPalette functor to convert raw semantic segmentation sensor output (where the red channel encodes the tag ID) into human-readable color images.
Code Reference
Source Location
- Repository: CARLA
- File:
LibCarla/source/carla/image/CityScapesPalette.h
Signature
class CityScapesPalette {
public:
static constexpr auto GetNumberOfTags();
static constexpr auto GetColor(uint8_t tag);
};
Import
#include "carla/image/CityScapesPalette.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| tag | uint8_t | Yes | Semantic segmentation tag ID (0-29, wraps around via modulo) |
Outputs
| Name | Type | Description |
|---|---|---|
| GetColor() | const uint8_t[3] | RGB color array for the given tag |
| GetNumberOfTags() | size_t | Total number of palette entries (30) |
Usage Examples
// Get the RGB color for "road" (tag 1)
auto color = carla::image::CityScapesPalette::GetColor(1);
// color == {128, 64, 128}
// Get the number of available tags
auto numTags = carla::image::CityScapesPalette::GetNumberOfTags();
// numTags == 30
// Safe access with out-of-range tag (wraps around)
auto wrappedColor = carla::image::CityScapesPalette::GetColor(31);
// equivalent to GetColor(1) since 31 % 30 == 1