54 using namespace boost::gil;
57 constexpr auto width = 256 * 256 * 256;
58 constexpr auto height = 1u;
60 auto img_bgra8 = MakeTestImage<bgra8_pixel_t>(width, height);
62 auto img_gray8 = MakeTestImage<gray8_pixel_t>(width, height);
64 auto depth_view = ImageView::MakeColorConvertedView(
68 auto ldepth_view = ImageView::MakeColorConvertedView(
72 auto p = *depth_view.begin();
74 static_assert(std::is_same<
decltype(p), gray8_pixel_t>::value,
"Not the pixel I was looking for!");
76 auto lp = *ldepth_view.begin();
78 static_assert(std::is_same<
decltype(lp), gray8_pixel_t>::value,
"Not the pixel I was looking for!");
80 ASSERT_EQ(depth_view.size(), img_bgra8.view.size());
82 ASSERT_EQ(ldepth_view.size(), img_bgra8.view.size());
85 auto it_bgra8 = img_bgra8.view.begin();
86 auto it_gray8 = img_gray8.view.begin();
88 for (
auto r = 0u; r < 256u; ++r) {
89 for (
auto g = 0u; g < 256u; ++g) {
90 for (
auto b = 0u; b < 256u; ++b) {
92 decltype(img_bgra8)::pixel_type &p_bgra8 = *it_bgra8;
94 decltype(img_gray8)::pixel_type &p_gray8 = *it_gray8;
96 get_color(p_bgra8, red_t()) =
static_cast<uint8_t
>(r);
98 get_color(p_bgra8, green_t()) =
static_cast<uint8_t
>(g);
100 get_color(p_bgra8, blue_t()) =
static_cast<uint8_t
>(b);
102 const float depth = r + (g * 256) + (b * 256 * 256);
104 const float normalized = depth /
static_cast<float>(256 * 256 * 256 - 1);
106 p_gray8[0] =
static_cast<uint8_t
>(255.0 * normalized);
115 auto img_copy = MakeTestImage<bgra8_pixel_t>(width, height);
117 ImageConverter::CopyPixels(img_bgra8.view, img_copy.view);
123 auto it_gray8 = img_gray8.view.begin();
124 auto it_depth = depth_view.begin();
125 auto it_ldepth = ldepth_view.begin();
126 auto it_copy = img_copy.view.begin();
128 for (
auto i = 0u; i < width; ++i) {
129 auto p_gray8 = *it_gray8;
130 auto p_depth = *it_depth;
131 auto p_ldepth = *it_ldepth;
132 auto p_copy = *it_copy;
134 ASSERT_NEAR(
int(p_depth[0]),
int(p_gray8[0]), 1)
135 <<
"at XY(" << i <<
",0)";
137 color_convert(p_ldepth, ld);
139 ASSERT_EQ(ld, p_copy)
140 <<
"at XY(" << i <<
",0)";
150TEST(image, semantic_segmentation) {
151 using namespace boost::gil;
154 constexpr auto width = CityScapesPalette::GetNumberOfTags();
155 constexpr auto height = 1u;
157 auto img_bgra8 = MakeTestImage<bgra8_pixel_t>(width, height);
159 auto img_ss = MakeTestImage<rgb8_pixel_t>(width, height);
161 auto semseg_view = ImageView::MakeColorConvertedView(
165 auto p = *semseg_view.begin();
167 static_assert(std::is_same<
decltype(p), bgra8_pixel_t>::value,
"Not the pixel I was looking for!");
169 ASSERT_EQ(semseg_view.size(), img_bgra8.view.size());
172 auto it_bgra8 = img_bgra8.view.begin();
173 auto it_ss = img_ss.view.begin();
175 for (
auto tag = 0u; tag < width; ++tag) {
176 decltype(img_bgra8)::pixel_type &p_bgra8 = *it_bgra8;
177 get_color(p_bgra8, red_t()) =
static_cast<uint8_t
>(tag);
178 get_color(p_bgra8, green_t()) = 0u;
179 get_color(p_bgra8, blue_t()) = 0u;
180 decltype(img_ss)::pixel_type &p_ss = *it_ss;
181 auto color = CityScapesPalette::GetColor(
static_cast<uint8_t
>(tag));
182 get_color(p_ss, red_t()) = color[0u];
183 get_color(p_ss, green_t()) = color[1u];
184 get_color(p_ss, blue_t()) = color[2u];
190 auto img_copy = MakeTestImage<rgba8_pixel_t>(width, height);
192 ImageConverter::CopyPixels(img_bgra8.view, img_copy.view);
197 auto it_ss = img_ss.view.begin();
198 auto it_ssv = semseg_view.begin();
199 auto it_copy = img_copy.view.begin();
201 for (
auto i = 0u; i < width; ++i) {
202 auto p_ssv = *it_ssv;
203 auto p_copy = *it_copy;
205 decltype(p_ssv) p_ss;
206 color_convert(_p_ss, p_ss);
208 ASSERT_EQ(p_ssv, p_ss)
209 <<
"at XY(" << i <<
",0)";
210 decltype(p_copy) css;
211 color_convert(p_ssv, css);
213 ASSERT_EQ(p_ssv, p_copy)
214 <<
"at XY(" << i <<
",0)";