|
1 | 1 | //
|
2 | 2 | // Copyright 2019-2020 Mateusz Loskot <mateusz at loskot dot net>
|
3 | 3 | // Copyright 2021 Pranam Lashkari <[email protected]>
|
| 4 | +// Copyright 2021 Prathamesh Tagore <[email protected]> |
4 | 5 | //
|
5 | 6 | // Distributed under the Boost Software License, Version 1.0
|
6 | 7 | // See accompanying file LICENSE_1_0.txt or copy at
|
@@ -111,12 +112,81 @@ struct test_image_5x5_kernel_3x3_identity
|
111 | 112 | }
|
112 | 113 | };
|
113 | 114 |
|
| 115 | +struct test_image_5x5_kernel_1x9_boundary_extend_reflection |
| 116 | +{ |
| 117 | + template <typename Image> |
| 118 | + void operator()(Image const&) |
| 119 | + { |
| 120 | + using image_t = Image; |
| 121 | + using pixel_t = typename image_t::value_type; |
| 122 | + using channel_t = typename gil::channel_type<pixel_t>::type; |
| 123 | + auto img = fixture::generate_image<image_t>(5, 5, fixture::random_value<channel_t>{}); |
| 124 | + auto img_view = gil::view(img); |
| 125 | + image_t img_out_up_left_offset(img), img_expected_row_up_offset(img); |
| 126 | + image_t img_expected_col_left_offset(img), img_out_down_right_offset(img); |
| 127 | + image_t img_expected_row_down_offset(img), img_expected_col_right_offset(img); |
| 128 | + int kernel_shift_up_left_offset = 2, kernel_shift_down_right_offset = -2; |
| 129 | + |
| 130 | + fixture::row_conv1D_offset_img_generator(img_view, gil::view(img_expected_row_up_offset), |
| 131 | + kernel_shift_up_left_offset); |
| 132 | + fixture::row_conv1D_offset_img_generator(img_view, gil::view(img_expected_row_up_offset), |
| 133 | + -1, 0, 1, img_view.height(), 1); |
| 134 | + fixture::row_conv1D_offset_img_generator(img_view, gil::view(img_expected_row_up_offset), |
| 135 | + 1, 0, 0, img_view.height(), 2); |
| 136 | + |
| 137 | + fixture::col_conv1D_offset_img_generator(gil::view(img_expected_row_up_offset), |
| 138 | + gil::view(img_expected_col_left_offset), kernel_shift_up_left_offset); |
| 139 | + fixture::col_conv1D_offset_img_generator(gil::view(img_expected_row_up_offset), |
| 140 | + gil::view(img_expected_col_left_offset), -1, 1, 0, 1, img_view.width()); |
| 141 | + fixture::col_conv1D_offset_img_generator(gil::view(img_expected_row_up_offset), |
| 142 | + gil::view(img_expected_col_left_offset), 1, 0, 0, 2, img_view.width()); |
| 143 | + |
| 144 | + fixture::row_conv1D_offset_img_generator(img_view, gil::view(img_expected_row_down_offset), |
| 145 | + kernel_shift_down_right_offset, 0, 2, img_view.height(), img_view.width()); |
| 146 | + fixture::row_conv1D_offset_img_generator(img_view, gil::view(img_expected_row_down_offset), |
| 147 | + -1, 0, img_view.width() - 1, img_view.height(), img_view.width()); |
| 148 | + fixture::row_conv1D_offset_img_generator(img_view, gil::view(img_expected_row_down_offset), |
| 149 | + 1, 0, img_view.width() - 2, img_view.height(), img_view.width()); |
| 150 | + |
| 151 | + fixture::col_conv1D_offset_img_generator(gil::view(img_expected_row_down_offset), |
| 152 | + gil::view(img_expected_col_right_offset), kernel_shift_down_right_offset, 2, 0, |
| 153 | + img_view.height(), img_view.width()); |
| 154 | + fixture::col_conv1D_offset_img_generator(gil::view(img_expected_row_down_offset), |
| 155 | + gil::view(img_expected_col_right_offset), -1, img_view.height() - 1, 0, |
| 156 | + img_view.height(), img_view.width()); |
| 157 | + fixture::col_conv1D_offset_img_generator(gil::view(img_expected_row_down_offset), |
| 158 | + gil::view(img_expected_col_right_offset), 1, img_view.height() - 2, 0, |
| 159 | + img_view.height(), img_view.width()); |
| 160 | + |
| 161 | + auto const kernel_up_left_offset = fixture::create_kernel<channel_t>( |
| 162 | + {0, 0, 0, 0, 0, 0, 1, 0, 0}); |
| 163 | + gil::detail::convolve_1d<pixel_t>(gil::const_view(img), kernel_up_left_offset, |
| 164 | + gil::view(img_out_up_left_offset), gil::boundary_option::extend_reflection); |
| 165 | + |
| 166 | + auto const kernel_down_right_offset = fixture::create_kernel<channel_t>( |
| 167 | + {0, 0, 1, 0, 0, 0, 0, 0, 0}); |
| 168 | + gil::detail::convolve_1d<pixel_t>(gil::const_view(img), kernel_down_right_offset, |
| 169 | + gil::view(img_out_down_right_offset), gil::boundary_option::extend_reflection); |
| 170 | + |
| 171 | + BOOST_TEST(gil::equal_pixels(gil::const_view(img_out_up_left_offset), |
| 172 | + gil::const_view(img_expected_col_left_offset))); |
| 173 | + BOOST_TEST(gil::equal_pixels(gil::const_view(img_out_down_right_offset), |
| 174 | + gil::const_view(img_expected_col_right_offset))); |
| 175 | + } |
| 176 | + static void run() |
| 177 | + { |
| 178 | + boost::mp11::mp_for_each<fixture::image_types>( |
| 179 | + test_image_5x5_kernel_1x9_boundary_extend_reflection{}); |
| 180 | + } |
| 181 | +}; |
| 182 | + |
114 | 183 | int main()
|
115 | 184 | {
|
116 | 185 | test_image_1x1_kernel_1x1_identity::run();
|
117 | 186 | test_image_1x1_kernel_3x3_identity::run();
|
118 | 187 | test_image_3x3_kernel_3x3_identity::run();
|
119 | 188 | test_image_5x5_kernel_3x3_identity::run();
|
120 | 189 |
|
| 190 | + test_image_5x5_kernel_1x9_boundary_extend_reflection::run(); |
121 | 191 | return ::boost::report_errors();
|
122 | 192 | }
|
0 commit comments