]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/gil/test/extension/numeric/convolve.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / gil / test / extension / numeric / convolve.cpp
1 //
2 // Copyright 2019 Mateusz Loskot <mateusz at loskot dot net>
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 #include <boost/gil.hpp>
9 #include <boost/gil/extension/numeric/convolve.hpp>
10
11 #include <tuple>
12 #include <type_traits>
13
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"
19
20 namespace gil = boost::gil;
21 namespace fixture = boost::gil::test::fixture;
22
23 BOOST_AUTO_TEST_SUITE(convolve_1d)
24
25 BOOST_AUTO_TEST_CASE_TEMPLATE(image_1x1_kernel_1x1_identity, Image, fixture::image_types)
26 {
27 auto const img = fixture::create_image<Image>(1, 1, 7);
28 Image img_out(img);
29
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));
34
35 // 1x1 kernel reduces convolution to multiplication
36 BOOST_TEST(gil::const_view(img).front() == gil::const_view(img_out).front());
37 }
38
39 BOOST_AUTO_TEST_CASE_TEMPLATE(image_1x1_kernel_3x3_identity, Image, fixture::image_types)
40 {
41 auto const img = fixture::create_image<Image>(1, 1, 7);
42 Image img_out(img);
43
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));
48
49 BOOST_TEST(gil::const_view(img).front() == gil::const_view(img_out).front());
50 }
51
52 BOOST_AUTO_TEST_CASE_TEMPLATE(image_3x3_kernel_3x3_identity, Image, fixture::image_types)
53 {
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>{});
57 Image img_out(img);
58
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));
61
62 BOOST_TEST(gil::equal_pixels(gil::const_view(img), gil::const_view(img_out)));
63 }
64
65 BOOST_AUTO_TEST_CASE_TEMPLATE(image_5x5_kernel_3x3_identity, Image, fixture::image_types)
66 {
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>{});
70 Image img_out(img);
71
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
75
76 BOOST_TEST(gil::equal_pixels(gil::const_view(img), gil::const_view(img_out)));
77 }
78
79 BOOST_AUTO_TEST_SUITE_END()