extend_boundary.cpp 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. //
  2. // Copyright 2019 Pranam Lashkari <plashkari628@gmail.com>
  3. //
  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
  7. //
  8. #define BOOST_TEST_MODULE test_ext_numeric_extend_boundary
  9. #include "unit_test.hpp"
  10. #include "unit_test_utility.hpp"
  11. #include <boost/gil.hpp>
  12. #include <boost/gil/extension/numeric/algorithm.hpp>
  13. #include <boost/gil/extension/numeric/convolve.hpp>
  14. namespace gil = boost::gil;
  15. std::uint8_t img[] =
  16. {
  17. 1, 2, 3, 4, 5, 6, 7, 8, 9,
  18. 10, 0, 0, 0, 0, 0, 0, 0, 32,
  19. 11, 0, 255, 0, 0, 0, 255, 0, 31,
  20. 12, 0, 0, 255, 0, 255, 0, 0, 30,
  21. 13, 0, 0, 0, 255, 0, 0, 0, 29,
  22. 14, 0, 0, 255, 0, 255, 0, 0, 28,
  23. 15, 0, 255, 0, 0, 0, 255, 0, 27,
  24. 16, 0, 0, 0, 0, 0, 0, 0, 26,
  25. 17, 18, 19, 20, 21, 22, 23, 24, 25
  26. };
  27. std::uint8_t row_output_constant[] =
  28. {
  29. 1, 2, 3, 4, 5, 6, 7, 8, 9,
  30. 1, 2, 3, 4, 5, 6, 7, 8, 9,
  31. 1, 2, 3, 4, 5, 6, 7, 8, 9,
  32. 10, 0, 0, 0, 0, 0, 0, 0, 32,
  33. 11, 0, 255, 0, 0, 0, 255, 0, 31,
  34. 12, 0, 0, 255, 0, 255, 0, 0, 30,
  35. 13, 0, 0, 0, 255, 0, 0, 0, 29,
  36. 14, 0, 0, 255, 0, 255, 0, 0, 28,
  37. 15, 0, 255, 0, 0, 0, 255, 0, 27,
  38. 16, 0, 0, 0, 0, 0, 0, 0, 26,
  39. 17, 18, 19, 20, 21, 22, 23, 24, 25,
  40. 17, 18, 19, 20, 21, 22, 23, 24, 25,
  41. 17, 18, 19, 20, 21, 22, 23, 24, 25
  42. };
  43. std::uint8_t row_output_zero[] =
  44. {
  45. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  46. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  47. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  48. 1, 2, 3, 4, 5, 6, 7, 8, 9,
  49. 10, 0, 0, 0, 0, 0, 0, 0, 32,
  50. 11, 0, 255, 0, 0, 0, 255, 0, 31,
  51. 12, 0, 0, 255, 0, 255, 0, 0, 30,
  52. 13, 0, 0, 0, 255, 0, 0, 0, 29,
  53. 14, 0, 0, 255, 0, 255, 0, 0, 28,
  54. 15, 0, 255, 0, 0, 0, 255, 0, 27,
  55. 16, 0, 0, 0, 0, 0, 0, 0, 26,
  56. 17, 18, 19, 20, 21, 22, 23, 24, 25,
  57. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  58. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  59. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  60. };
  61. std::uint8_t col_output_constant[] =
  62. {
  63. 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9,
  64. 10, 10, 0, 0, 0, 0, 0, 0, 0, 32, 32,
  65. 11, 11, 0, 255, 0, 0, 0, 255, 0, 31, 31,
  66. 12, 12, 0, 0, 255, 0, 255, 0, 0, 30, 30,
  67. 13, 13, 0, 0, 0, 255, 0, 0, 0, 29, 29,
  68. 14, 14, 0, 0, 255, 0, 255, 0, 0, 28, 28,
  69. 15, 15, 0, 255, 0, 0, 0, 255, 0, 27, 27,
  70. 16, 16, 0, 0, 0, 0, 0, 0, 0, 26, 26,
  71. 17, 17, 18, 19, 20, 21, 22, 23, 24, 25, 25
  72. };
  73. std::uint8_t col_output_zero[] =
  74. {
  75. 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0,
  76. 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0,
  77. 0, 0, 11, 0, 255, 0, 0, 0, 255, 0, 31, 0, 0,
  78. 0, 0, 12, 0, 0, 255, 0, 255, 0, 0, 30, 0, 0,
  79. 0, 0, 13, 0, 0, 0, 255, 0, 0, 0, 29, 0, 0,
  80. 0, 0, 14, 0, 0, 255, 0, 255, 0, 0, 28, 0, 0,
  81. 0, 0, 15, 0, 255, 0, 0, 0, 255, 0, 27, 0, 0,
  82. 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 26, 0, 0,
  83. 0, 0, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, 0
  84. };
  85. std::uint8_t boundary_output_constant[] =
  86. {
  87. 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9,
  88. 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9,
  89. 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9,
  90. 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 32, 32, 32,
  91. 11, 11, 11, 0, 255, 0, 0, 0, 255, 0, 31, 31, 31,
  92. 12, 12, 12, 0, 0, 255, 0, 255, 0, 0, 30, 30, 30,
  93. 13, 13, 13, 0, 0, 0, 255, 0, 0, 0, 29, 29, 29,
  94. 14, 14, 14, 0, 0, 255, 0, 255, 0, 0, 28, 28, 28,
  95. 15, 15, 15, 0, 255, 0, 0, 0, 255, 0, 27, 27, 27,
  96. 16, 16, 16, 0, 0, 0, 0, 0, 0, 0, 26, 26, 26,
  97. 17, 17, 17, 18, 19, 20, 21, 22, 23, 24, 25, 25, 25,
  98. 17, 17, 17, 18, 19, 20, 21, 22, 23, 24, 25, 25, 25,
  99. 17, 17, 17, 18, 19, 20, 21, 22, 23, 24, 25, 25, 25
  100. };
  101. std::uint8_t boundary_output_zero[] =
  102. {
  103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  105. 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0,
  106. 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0,
  107. 0, 0, 11, 0, 255, 0, 0, 0, 255, 0, 31, 0, 0,
  108. 0, 0, 12, 0, 0, 255, 0, 255, 0, 0, 30, 0, 0,
  109. 0, 0, 13, 0, 0, 0, 255, 0, 0, 0, 29, 0, 0,
  110. 0, 0, 14, 0, 0, 255, 0, 255, 0, 0, 28, 0, 0,
  111. 0, 0, 15, 0, 255, 0, 0, 0, 255, 0, 27, 0, 0,
  112. 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 26, 0, 0,
  113. 0, 0, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, 0,
  114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  116. };
  117. BOOST_AUTO_TEST_SUITE(boundary_extension)
  118. BOOST_AUTO_TEST_CASE(extend_row_with_constant)
  119. {
  120. gil::gray8c_view_t src_view =
  121. gil::interleaved_view(9, 9, reinterpret_cast<const gil::gray8_pixel_t *>(img), 9);
  122. gil::gray8c_view_t out_view =
  123. gil::interleaved_view(9, 13, reinterpret_cast<const gil::gray8_pixel_t *>(row_output_constant), 9);
  124. auto output = gil::extend_row(src_view, 2, gil::boundary_option::extend_constant);
  125. BOOST_TEST(gil::equal_pixels(out_view, gil::view(output)));
  126. }
  127. BOOST_AUTO_TEST_CASE(extend_row_with_zero)
  128. {
  129. gil::gray8c_view_t src_view =
  130. gil::interleaved_view(9, 9, reinterpret_cast<const gil::gray8_pixel_t *>(img), 9);
  131. gil::gray8c_view_t out_view =
  132. gil::interleaved_view(9, 15, reinterpret_cast<const gil::gray8_pixel_t *>(row_output_zero), 9);
  133. auto output = gil::extend_row(src_view, 3, gil::boundary_option::extend_zero);
  134. BOOST_TEST(gil::equal_pixels(out_view, gil::view(output)));
  135. }
  136. BOOST_AUTO_TEST_CASE(extend_row_with_padded)
  137. {
  138. gil::gray8c_view_t src_view =
  139. gil::interleaved_view(9, 9, reinterpret_cast<const gil::gray8_pixel_t *>(img), 9);
  140. auto src_sub_view = gil::subimage_view(src_view, 0, 1, 9, 7);
  141. auto output = gil::extend_row(src_sub_view, 1, gil::boundary_option::extend_padded);
  142. BOOST_TEST(gil::equal_pixels(src_view, gil::view(output)));
  143. }
  144. BOOST_AUTO_TEST_CASE(extend_col_with_constant)
  145. {
  146. gil::gray8c_view_t src_view =
  147. 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(11, 9, reinterpret_cast<const gil::gray8_pixel_t *>(col_output_constant), 11);
  150. auto output = gil::extend_col(src_view, 1, gil::boundary_option::extend_constant);
  151. BOOST_TEST(gil::equal_pixels(out_view, gil::view(output)));
  152. }
  153. BOOST_AUTO_TEST_CASE(extend_col_with_zero)
  154. {
  155. gil::gray8c_view_t src_view =
  156. gil::interleaved_view(9, 9, reinterpret_cast<const gil::gray8_pixel_t *>(img), 9);
  157. gil::gray8c_view_t out_view =
  158. gil::interleaved_view(13, 9, reinterpret_cast<const gil::gray8_pixel_t *>(col_output_zero), 13);
  159. auto output = gil::extend_col(src_view, 2, gil::boundary_option::extend_zero);
  160. BOOST_TEST(gil::equal_pixels(out_view, gil::view(output)));
  161. }
  162. BOOST_AUTO_TEST_CASE(extend_col_with_padded)
  163. {
  164. gil::gray8c_view_t src_view =
  165. gil::interleaved_view(9, 9, reinterpret_cast<const gil::gray8_pixel_t *>(img), 9);
  166. auto src_sub_view = gil::subimage_view(src_view, 1, 0, 7, 9);
  167. auto output = gil::extend_col(src_sub_view, 1, gil::boundary_option::extend_padded);
  168. BOOST_TEST(gil::equal_pixels(src_view, gil::view(output)));
  169. }
  170. BOOST_AUTO_TEST_CASE(extend_img_with_constant)
  171. {
  172. gil::gray8c_view_t src_view =
  173. gil::interleaved_view(9, 9, reinterpret_cast<const gil::gray8_pixel_t *>(img), 9);
  174. gil::gray8c_view_t out_view =
  175. gil::interleaved_view(13, 13, reinterpret_cast<const gil::gray8_pixel_t *>(boundary_output_constant), 13);
  176. auto output = gil::extend_boundary(src_view, 2, gil::boundary_option::extend_constant);
  177. BOOST_TEST(gil::equal_pixels(out_view, gil::view(output)));
  178. }
  179. BOOST_AUTO_TEST_CASE(extend_img_with_zero)
  180. {
  181. gil::gray8c_view_t src_view =
  182. gil::interleaved_view(9, 9, reinterpret_cast<const gil::gray8_pixel_t *>(img), 9);
  183. gil::gray8c_view_t out_view =
  184. gil::interleaved_view(13, 13, reinterpret_cast<const gil::gray8_pixel_t *>(boundary_output_zero), 13);
  185. auto output = gil::extend_boundary(src_view, 2, gil::boundary_option::extend_zero);
  186. BOOST_TEST(gil::equal_pixels(out_view, gil::view(output)));
  187. }
  188. BOOST_AUTO_TEST_CASE(extend_img_with_padded)
  189. {
  190. gil::gray8c_view_t src_view =
  191. gil::interleaved_view(9, 9, reinterpret_cast<const gil::gray8_pixel_t *>(img), 9);
  192. auto src_sub_view = gil::subimage_view(src_view, 1, 1, 7, 7);
  193. auto output = gil::extend_boundary(src_sub_view, 1, gil::boundary_option::extend_padded);
  194. BOOST_TEST(gil::equal_pixels(src_view, gil::view(output)));
  195. }
  196. BOOST_AUTO_TEST_SUITE_END()