15 template <
typename ViewT,
typename PixelT>
19 std::unique_ptr<PixelT[]>
data;
23 template <
typename PixelT>
25 auto data = std::make_unique<PixelT[]>(
sizeof(PixelT) * width * height);
26 auto view = boost::gil::interleaved_view(
29 reinterpret_cast<PixelT*>(
data.get()),
30 static_cast<long>(
sizeof(PixelT) * width));
34 #ifndef PLATFORM_WINDOWS 41 #endif // PLATFORM_WINDOWS 47 using namespace boost::gil;
50 constexpr
auto width = 256 * 256 * 256;
51 constexpr
auto height = 1u;
53 auto img_bgra8 = MakeTestImage<bgra8_pixel_t>(width, height);
54 auto img_gray8 = MakeTestImage<gray8_pixel_t>(width, height);
56 auto depth_view = ImageView::MakeColorConvertedView(
59 auto ldepth_view = ImageView::MakeColorConvertedView(
63 auto p = *depth_view.begin();
64 static_assert(std::is_same<decltype(p), gray8_pixel_t>::value,
"Not the pixel I was looking for!");
65 auto lp = *ldepth_view.begin();
66 static_assert(std::is_same<decltype(lp), gray8_pixel_t>::value,
"Not the pixel I was looking for!");
68 ASSERT_EQ(depth_view.size(), img_bgra8.view.size());
69 ASSERT_EQ(ldepth_view.size(), img_bgra8.view.size());
72 auto it_bgra8 = img_bgra8.view.begin();
73 auto it_gray8 = img_gray8.view.begin();
75 for (
auto r = 0u; r < 256u; ++r) {
76 for (
auto g = 0u; g < 256u; ++g) {
77 for (
auto b = 0u; b < 256u; ++b) {
78 decltype(img_bgra8)::
pixel_type &p_bgra8 = *it_bgra8;
79 decltype(img_gray8)::
pixel_type &p_gray8 = *it_gray8;
80 get_color(p_bgra8, red_t()) =
static_cast<uint8_t
>(r);
81 get_color(p_bgra8, green_t()) =
static_cast<uint8_t
>(g);
82 get_color(p_bgra8, blue_t()) =
static_cast<uint8_t
>(b);
83 const float depth = r + (g * 256) + (b * 256 * 256);
84 const float normalized = depth /
static_cast<float>(256 * 256 * 256 - 1);
85 p_gray8[0] =
static_cast<uint8_t
>(255.0 * normalized);
94 auto img_copy = MakeTestImage<bgra8_pixel_t>(width, height);
95 ImageConverter::CopyPixels(img_bgra8.view, img_copy.view);
99 auto it_gray8 = img_gray8.view.begin();
100 auto it_depth = depth_view.begin();
101 auto it_ldepth = ldepth_view.begin();
102 auto it_copy = img_copy.view.begin();
104 for (
auto i = 0u; i < width; ++i) {
105 auto p_gray8 = *it_gray8;
106 auto p_depth = *it_depth;
107 auto p_ldepth = *it_ldepth;
108 auto p_copy = *it_copy;
109 ASSERT_NEAR(
int(p_depth[0]),
int(p_gray8[0]), 1)
110 <<
"at XY(" << i <<
",0)";
112 color_convert(p_ldepth, ld);
113 ASSERT_EQ(ld, p_copy)
114 <<
"at XY(" << i <<
",0)";
124 TEST(image, semantic_segmentation) {
125 using namespace boost::gil;
128 constexpr
auto width = CityScapesPalette::GetNumberOfTags();
129 constexpr
auto height = 1u;
131 auto img_bgra8 = MakeTestImage<bgra8_pixel_t>(width, height);
132 auto img_ss = MakeTestImage<rgb8_pixel_t>(width, height);
134 auto semseg_view = ImageView::MakeColorConvertedView(
138 auto p = *semseg_view.begin();
139 static_assert(std::is_same<decltype(p), bgra8_pixel_t>::value,
"Not the pixel I was looking for!");
141 ASSERT_EQ(semseg_view.size(), img_bgra8.view.size());
144 auto it_bgra8 = img_bgra8.view.begin();
145 auto it_ss = img_ss.view.begin();
147 for (
auto tag = 0u; tag < width; ++tag) {
148 decltype(img_bgra8)::
pixel_type &p_bgra8 = *it_bgra8;
149 get_color(p_bgra8, red_t()) =
static_cast<uint8_t
>(tag);
150 get_color(p_bgra8, green_t()) = 0u;
151 get_color(p_bgra8, blue_t()) = 0u;
154 get_color(p_ss, red_t()) = color[0u];
155 get_color(p_ss, green_t()) = color[1u];
156 get_color(p_ss, blue_t()) = color[2u];
162 auto img_copy = MakeTestImage<rgba8_pixel_t>(width, height);
163 ImageConverter::CopyPixels(img_bgra8.view, img_copy.view);
167 auto it_ss = img_ss.view.begin();
168 auto it_ssv = semseg_view.begin();
169 auto it_copy = img_copy.view.begin();
171 for (
auto i = 0u; i < width; ++i) {
172 auto p_ssv = *it_ssv;
173 auto p_copy = *it_copy;
175 decltype(p_ssv) p_ss;
176 color_convert(_p_ss, p_ss);
177 ASSERT_EQ(p_ssv, p_ss)
178 <<
"at XY(" << i <<
",0)";
179 decltype(p_copy) css;
180 color_convert(p_ssv, css);
181 ASSERT_EQ(p_ssv, p_copy)
182 <<
"at XY(" << i <<
",0)";
static auto MakeTestImage(size_t width, size_t height)
static void log(Args &&... args)
std::unique_ptr< PixelT[]> data
constexpr bool has_jpeg_support()
constexpr bool has_tiff_support()
static void log_info(Args &&... args)
static LaneMarking::Color GetColor(std::string str)
constexpr bool has_png_support()
TestImage(TestImage &&)=default