2 // Copyright 2019 Pranam Lashkari <plashkari628@gmail.com>
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
9 #define BOOST_TEST_MODULE test_ext_numeric_extend_boundary
10 #include "unit_test.hpp"
11 #include "unit_test_utility.hpp"
13 #include <boost/gil.hpp>
14 #include <boost/gil/extension/numeric/algorithm.hpp>
15 #include <boost/gil/extension/numeric/convolve.hpp>
17 namespace gil = boost::gil;
21 1, 2, 3, 4, 5, 6, 7, 8, 9,
22 10, 0, 0, 0, 0, 0, 0, 0, 32,
23 11, 0, 255, 0, 0, 0, 255, 0, 31,
24 12, 0, 0, 255, 0, 255, 0, 0, 30,
25 13, 0, 0, 0, 255, 0, 0, 0, 29,
26 14, 0, 0, 255, 0, 255, 0, 0, 28,
27 15, 0, 255, 0, 0, 0, 255, 0, 27,
28 16, 0, 0, 0, 0, 0, 0, 0, 26,
29 17, 18, 19, 20, 21, 22, 23, 24, 25
32 std::uint8_t row_output_constant[] =
34 1, 2, 3, 4, 5, 6, 7, 8, 9,
35 1, 2, 3, 4, 5, 6, 7, 8, 9,
36 1, 2, 3, 4, 5, 6, 7, 8, 9,
37 10, 0, 0, 0, 0, 0, 0, 0, 32,
38 11, 0, 255, 0, 0, 0, 255, 0, 31,
39 12, 0, 0, 255, 0, 255, 0, 0, 30,
40 13, 0, 0, 0, 255, 0, 0, 0, 29,
41 14, 0, 0, 255, 0, 255, 0, 0, 28,
42 15, 0, 255, 0, 0, 0, 255, 0, 27,
43 16, 0, 0, 0, 0, 0, 0, 0, 26,
44 17, 18, 19, 20, 21, 22, 23, 24, 25,
45 17, 18, 19, 20, 21, 22, 23, 24, 25,
46 17, 18, 19, 20, 21, 22, 23, 24, 25
49 std::uint8_t row_output_zero[] =
51 0, 0, 0, 0, 0, 0, 0, 0, 0,
52 0, 0, 0, 0, 0, 0, 0, 0, 0,
53 0, 0, 0, 0, 0, 0, 0, 0, 0,
54 1, 2, 3, 4, 5, 6, 7, 8, 9,
55 10, 0, 0, 0, 0, 0, 0, 0, 32,
56 11, 0, 255, 0, 0, 0, 255, 0, 31,
57 12, 0, 0, 255, 0, 255, 0, 0, 30,
58 13, 0, 0, 0, 255, 0, 0, 0, 29,
59 14, 0, 0, 255, 0, 255, 0, 0, 28,
60 15, 0, 255, 0, 0, 0, 255, 0, 27,
61 16, 0, 0, 0, 0, 0, 0, 0, 26,
62 17, 18, 19, 20, 21, 22, 23, 24, 25,
63 0, 0, 0, 0, 0, 0, 0, 0, 0,
64 0, 0, 0, 0, 0, 0, 0, 0, 0,
65 0, 0, 0, 0, 0, 0, 0, 0, 0,
68 std::uint8_t col_output_constant[] =
70 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9,
71 10, 10, 0, 0, 0, 0, 0, 0, 0, 32, 32,
72 11, 11, 0, 255, 0, 0, 0, 255, 0, 31, 31,
73 12, 12, 0, 0, 255, 0, 255, 0, 0, 30, 30,
74 13, 13, 0, 0, 0, 255, 0, 0, 0, 29, 29,
75 14, 14, 0, 0, 255, 0, 255, 0, 0, 28, 28,
76 15, 15, 0, 255, 0, 0, 0, 255, 0, 27, 27,
77 16, 16, 0, 0, 0, 0, 0, 0, 0, 26, 26,
78 17, 17, 18, 19, 20, 21, 22, 23, 24, 25, 25
81 std::uint8_t col_output_zero[] =
83 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0,
84 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0,
85 0, 0, 11, 0, 255, 0, 0, 0, 255, 0, 31, 0, 0,
86 0, 0, 12, 0, 0, 255, 0, 255, 0, 0, 30, 0, 0,
87 0, 0, 13, 0, 0, 0, 255, 0, 0, 0, 29, 0, 0,
88 0, 0, 14, 0, 0, 255, 0, 255, 0, 0, 28, 0, 0,
89 0, 0, 15, 0, 255, 0, 0, 0, 255, 0, 27, 0, 0,
90 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 26, 0, 0,
91 0, 0, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, 0
94 std::uint8_t boundary_output_constant[] =
96 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9,
97 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9,
98 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9,
99 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 32, 32, 32,
100 11, 11, 11, 0, 255, 0, 0, 0, 255, 0, 31, 31, 31,
101 12, 12, 12, 0, 0, 255, 0, 255, 0, 0, 30, 30, 30,
102 13, 13, 13, 0, 0, 0, 255, 0, 0, 0, 29, 29, 29,
103 14, 14, 14, 0, 0, 255, 0, 255, 0, 0, 28, 28, 28,
104 15, 15, 15, 0, 255, 0, 0, 0, 255, 0, 27, 27, 27,
105 16, 16, 16, 0, 0, 0, 0, 0, 0, 0, 26, 26, 26,
106 17, 17, 17, 18, 19, 20, 21, 22, 23, 24, 25, 25, 25,
107 17, 17, 17, 18, 19, 20, 21, 22, 23, 24, 25, 25, 25,
108 17, 17, 17, 18, 19, 20, 21, 22, 23, 24, 25, 25, 25
111 std::uint8_t boundary_output_zero[] =
113 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
114 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
115 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0,
116 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0,
117 0, 0, 11, 0, 255, 0, 0, 0, 255, 0, 31, 0, 0,
118 0, 0, 12, 0, 0, 255, 0, 255, 0, 0, 30, 0, 0,
119 0, 0, 13, 0, 0, 0, 255, 0, 0, 0, 29, 0, 0,
120 0, 0, 14, 0, 0, 255, 0, 255, 0, 0, 28, 0, 0,
121 0, 0, 15, 0, 255, 0, 0, 0, 255, 0, 27, 0, 0,
122 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 26, 0, 0,
123 0, 0, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, 0,
124 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
125 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
128 BOOST_AUTO_TEST_SUITE(boundary_extension)
130 BOOST_AUTO_TEST_CASE(extend_row_with_constant)
132 gil::gray8c_view_t src_view =
133 gil::interleaved_view(9, 9, reinterpret_cast<const gil::gray8_pixel_t *>(img), 9);
135 gil::gray8c_view_t out_view =
136 gil::interleaved_view(9, 13, reinterpret_cast<const gil::gray8_pixel_t *>(row_output_constant), 9);
138 auto output = gil::extend_row(src_view, 2, gil::boundary_option::extend_constant);
140 BOOST_TEST(gil::equal_pixels(out_view, gil::view(output)));
143 BOOST_AUTO_TEST_CASE(extend_row_with_zero)
145 gil::gray8c_view_t src_view =
146 gil::interleaved_view(9, 9, reinterpret_cast<const gil::gray8_pixel_t *>(img), 9);
148 gil::gray8c_view_t out_view =
149 gil::interleaved_view(9, 15, reinterpret_cast<const gil::gray8_pixel_t *>(row_output_zero), 9);
151 auto output = gil::extend_row(src_view, 3, gil::boundary_option::extend_zero);
153 BOOST_TEST(gil::equal_pixels(out_view, gil::view(output)));
156 BOOST_AUTO_TEST_CASE(extend_row_with_padded)
158 gil::gray8c_view_t src_view =
159 gil::interleaved_view(9, 9, reinterpret_cast<const gil::gray8_pixel_t *>(img), 9);
161 auto src_sub_view = gil::subimage_view(src_view, 0, 1, 9, 7);
163 auto output = gil::extend_row(src_sub_view, 1, gil::boundary_option::extend_padded);
165 BOOST_TEST(gil::equal_pixels(src_view, gil::view(output)));
168 BOOST_AUTO_TEST_CASE(extend_col_with_constant)
170 gil::gray8c_view_t src_view =
171 gil::interleaved_view(9, 9, reinterpret_cast<const gil::gray8_pixel_t *>(img), 9);
173 gil::gray8c_view_t out_view =
174 gil::interleaved_view(11, 9, reinterpret_cast<const gil::gray8_pixel_t *>(col_output_constant), 11);
176 auto output = gil::extend_col(src_view, 1, gil::boundary_option::extend_constant);
178 BOOST_TEST(gil::equal_pixels(out_view, gil::view(output)));
181 BOOST_AUTO_TEST_CASE(extend_col_with_zero)
183 gil::gray8c_view_t src_view =
184 gil::interleaved_view(9, 9, reinterpret_cast<const gil::gray8_pixel_t *>(img), 9);
186 gil::gray8c_view_t out_view =
187 gil::interleaved_view(13, 9, reinterpret_cast<const gil::gray8_pixel_t *>(col_output_zero), 13);
189 auto output = gil::extend_col(src_view, 2, gil::boundary_option::extend_zero);
191 BOOST_TEST(gil::equal_pixels(out_view, gil::view(output)));
194 BOOST_AUTO_TEST_CASE(extend_col_with_padded)
196 gil::gray8c_view_t src_view =
197 gil::interleaved_view(9, 9, reinterpret_cast<const gil::gray8_pixel_t *>(img), 9);
199 auto src_sub_view = gil::subimage_view(src_view, 1, 0, 7, 9);
201 auto output = gil::extend_col(src_sub_view, 1, gil::boundary_option::extend_padded);
203 BOOST_TEST(gil::equal_pixels(src_view, gil::view(output)));
206 BOOST_AUTO_TEST_CASE(extend_img_with_constant)
208 gil::gray8c_view_t src_view =
209 gil::interleaved_view(9, 9, reinterpret_cast<const gil::gray8_pixel_t *>(img), 9);
211 gil::gray8c_view_t out_view =
212 gil::interleaved_view(13, 13, reinterpret_cast<const gil::gray8_pixel_t *>(boundary_output_constant), 13);
214 auto output = gil::extend_boundary(src_view, 2, gil::boundary_option::extend_constant);
216 BOOST_TEST(gil::equal_pixels(out_view, gil::view(output)));
219 BOOST_AUTO_TEST_CASE(extend_img_with_zero)
221 gil::gray8c_view_t src_view =
222 gil::interleaved_view(9, 9, reinterpret_cast<const gil::gray8_pixel_t *>(img), 9);
224 gil::gray8c_view_t out_view =
225 gil::interleaved_view(13, 13, reinterpret_cast<const gil::gray8_pixel_t *>(boundary_output_zero), 13);
227 auto output = gil::extend_boundary(src_view, 2, gil::boundary_option::extend_zero);
229 BOOST_TEST(gil::equal_pixels(out_view, gil::view(output)));
232 BOOST_AUTO_TEST_CASE(extend_img_with_padded)
234 gil::gray8c_view_t src_view =
235 gil::interleaved_view(9, 9, reinterpret_cast<const gil::gray8_pixel_t *>(img), 9);
237 auto src_sub_view = gil::subimage_view(src_view, 1, 1, 7, 7);
239 auto output = gil::extend_boundary(src_sub_view, 1, gil::boundary_option::extend_padded);
241 BOOST_TEST(gil::equal_pixels(src_view, gil::view(output)));
244 BOOST_AUTO_TEST_SUITE_END()