11#include <opencv2/core.hpp>
55 return label > 0x7FFFFFFFu;
66 throw std::out_of_range(
67 "label_to_index: label 0 is unlabeled and has no index");
68 return static_cast<size_t>(label) - 1;
85 throw std::out_of_range(
"api_to_point_label: negative label " +
86 std::to_string(api_label) +
87 " is not the background sentinel (-1)");
88 return static_cast<uint32_t
>(api_label);
96 return static_cast<int>(point_label);
106 throw std::out_of_range(
"api_to_storage: label " +
107 std::to_string(api_label) +
" is below -1");
109 throw std::out_of_range(
110 "api_to_storage: label " + std::to_string(api_label) +
111 " exceeds maximum storable label " +
113 " (would wrap CV_16U storage)");
114 return static_cast<uint16_t
>(api_label + 1);
120 return static_cast<int>(storage_value) - 1;
133 if (storage.type() != CV_16UC1)
134 throw std::invalid_argument(
135 "storage_mat_to_api: expected CV_16UC1 storage image");
137 storage.convertTo(api, CV_32S);
150 throw std::invalid_argument(
"api_mat_to_storage: empty label image");
151 if (api.type() != CV_32SC1)
152 throw std::invalid_argument(
153 "api_mat_to_storage: expected CV_32SC1 API image");
155 double min_val = 0.0;
156 double max_val = 0.0;
157 cv::minMaxLoc(api, &min_val, &max_val);
159 throw std::out_of_range(
"api_mat_to_storage: label " +
160 std::to_string(
static_cast<int>(min_val)) +
163 throw std::out_of_range(
164 "api_mat_to_storage: label " +
165 std::to_string(
static_cast<int>(max_val)) +
166 " exceeds maximum storable label " +
168 " (would wrap CV_16U storage)");
170 cv::Mat offset = api + 1;
172 offset.convertTo(storage, CV_16U);
Wire form of one stored report PDF version — the ReportPdfVersion schema in ruxd's API contract (docs...
constexpr uint16_t kMaxStorableLabel
Largest label that can be stored in the CV_16U PNG layer.
size_t label_to_index(uint32_t label)
Convert a point label to a zero-based vector index, replacing the error-prone bare label - 1 idiom us...
uint16_t api_to_storage(int api_label)
API label (CV_32S, -1 = background) → storage value (CV_16U, 0 = bg, label + 1).
int storage_to_api(uint16_t storage_value)
Storage value (CV_16U, 0 = bg, label + 1) → API label (CV_32S, -1 = background).
cv::Mat storage_mat_to_api(const cv::Mat &storage)
Convert a storage label image (CV_16U, 0 = bg) to an API label image (CV_32S, -1 = background) by sub...
constexpr int kBackgroundApi
ProjectDB segmentation API convention: -1 marks background/unlabeled in the CV_32S label images retur...
cv::Mat api_mat_to_storage(const cv::Mat &api)
Convert an API label image (CV_32S, -1 = background) to a storage label image (CV_16U,...
uint32_t api_to_point_label(int api_label)
API (CV_32S, -1 = background) → point label (uint32_t, 0 = unlabeled).
constexpr uint32_t kUnlabeled
Point-cloud convention: 0 means "unlabeled" in every CloudL (labels, planes, rooms,...
int point_label_to_api(uint32_t point_label)
Point label (uint32_t, 0 = unlabeled) → API (CV_32S, -1 = background).
constexpr bool is_valid_label(uint32_t label) noexcept
constexpr bool is_out_of_contract_label(uint32_t label) noexcept