11#include <opencv2/core.hpp>
58 throw std::out_of_range(
59 "label_to_index: label 0 is unlabeled and has no index");
60 return static_cast<size_t>(label) - 1;
77 throw std::out_of_range(
"api_to_point_label: negative label " +
78 std::to_string(api_label) +
79 " is not the background sentinel (-1)");
80 return static_cast<uint32_t
>(api_label);
88 return static_cast<int>(point_label);
98 throw std::out_of_range(
"api_to_storage: label " +
99 std::to_string(api_label) +
" is below -1");
101 throw std::out_of_range(
102 "api_to_storage: label " + std::to_string(api_label) +
103 " exceeds maximum storable label " +
105 " (would wrap CV_16U storage)");
106 return static_cast<uint16_t
>(api_label + 1);
112 return static_cast<int>(storage_value) - 1;
125 if (storage.type() != CV_16UC1)
126 throw std::invalid_argument(
127 "storage_mat_to_api: expected CV_16UC1 storage image");
129 storage.convertTo(api, CV_32S);
142 throw std::invalid_argument(
"api_mat_to_storage: empty label image");
143 if (api.type() != CV_32SC1)
144 throw std::invalid_argument(
145 "api_mat_to_storage: expected CV_32SC1 API image");
147 double min_val = 0.0;
148 double max_val = 0.0;
149 cv::minMaxLoc(api, &min_val, &max_val);
151 throw std::out_of_range(
"api_mat_to_storage: label " +
152 std::to_string(
static_cast<int>(min_val)) +
155 throw std::out_of_range(
156 "api_mat_to_storage: label " +
157 std::to_string(
static_cast<int>(max_val)) +
158 " exceeds maximum storable label " +
160 " (would wrap CV_16U storage)");
162 cv::Mat offset = api + 1;
164 offset.convertTo(storage, CV_16U);
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