2 // Copyright 2019 Mateusz Loskot <mateusz at loskot dot net>
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
8 #include <boost/gil.hpp>
9 #include <boost/gil/extension/numeric/convolve.hpp>
12 #include <type_traits>
14 #define BOOST_TEST_MODULE test_ext_numeric_colvolve_2d
15 #include "unit_test.hpp"
16 #include "unit_test_utility.hpp"
17 #include "test_fixture.hpp"
18 #include "core/image/test_fixture.hpp"
20 namespace gil
= boost::gil
;
21 namespace fixture
= boost::gil::test::fixture
;
23 BOOST_AUTO_TEST_SUITE(convolve_1d
)
25 BOOST_AUTO_TEST_CASE_TEMPLATE(image_1x1_kernel_1x1_identity
, Image
, fixture::image_types
)
27 auto const img
= fixture::create_image
<Image
>(1, 1, 7);
30 using pixel_t
= typename
Image::value_type
;
31 using channel_t
= typename
gil::channel_type
<pixel_t
>::type
;
32 auto const kernel
= fixture::create_kernel
<channel_t
>({1});
33 gil::detail::convolve_1d
<pixel_t
>(const_view(img_out
), kernel
, view(img_out
));
35 // 1x1 kernel reduces convolution to multiplication
36 BOOST_TEST(gil::const_view(img
).front() == gil::const_view(img_out
).front());
39 BOOST_AUTO_TEST_CASE_TEMPLATE(image_1x1_kernel_3x3_identity
, Image
, fixture::image_types
)
41 auto const img
= fixture::create_image
<Image
>(1, 1, 7);
44 using pixel_t
= typename
Image::value_type
;
45 using channel_t
= typename
gil::channel_type
<pixel_t
>::type
;
46 auto const kernel
= fixture::create_kernel
<channel_t
>({0, 0, 0, 0, 1, 0, 0, 0, 0});
47 gil::detail::convolve_1d
<pixel_t
>(const_view(img_out
), kernel
, view(img_out
));
49 BOOST_TEST(gil::const_view(img
).front() == gil::const_view(img_out
).front());
52 BOOST_AUTO_TEST_CASE_TEMPLATE(image_3x3_kernel_3x3_identity
, Image
, fixture::image_types
)
54 using pixel_t
= typename
Image::value_type
;
55 using channel_t
= typename
gil::channel_type
<pixel_t
>::type
;
56 auto const img
= fixture::generate_image
<Image
>(3, 3, fixture::random_value
<channel_t
>{});
59 auto const kernel
= fixture::create_kernel
<channel_t
>({0, 0, 0, 0, 1, 0, 0, 0, 0});
60 gil::detail::convolve_1d
<pixel_t
>(const_view(img_out
), kernel
, view(img_out
));
62 BOOST_TEST(gil::equal_pixels(gil::const_view(img
), gil::const_view(img_out
)));
65 BOOST_AUTO_TEST_CASE_TEMPLATE(image_5x5_kernel_3x3_identity
, Image
, fixture::image_types
)
67 using pixel_t
= typename
Image::value_type
;
68 using channel_t
= typename
gil::channel_type
<pixel_t
>::type
;
69 auto const img
= fixture::generate_image
<Image
>(5, 5, fixture::random_value
<channel_t
>{});
72 auto const kernel
= fixture::create_kernel
<channel_t
>({0, 0, 0, 0, 1, 0, 0, 0, 0});
73 gil::detail::convolve_1d
<pixel_t
>(const_view(img_out
), kernel
, view(img_out
));
74 // TODO: Test different boundary options
76 BOOST_TEST(gil::equal_pixels(gil::const_view(img
), gil::const_view(img_out
)));
79 BOOST_AUTO_TEST_SUITE_END()