1//
2// Copyright 2019-2020 Mateusz Loskot <mateusz at loskot dot net>
3// Copyright 2021 Pranam Lashkari <plashkari628@gmail.com>
4//
5// Distributed under the Boost Software License, Version 1.0
6// See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt
8//
9#include <boost/gil.hpp>
10#include <boost/gil/image_processing/convolve.hpp>
11
12#include <boost/core/lightweight_test.hpp>
13
14#include <tuple>
15#include <type_traits>
16
17#include "test_fixture.hpp"
18#include "core/image/test_fixture.hpp"
19
20namespace gil = boost::gil;
21namespace fixture = boost::gil::test::fixture;
22
23struct test_image_1x1_kernel_1x1_identity
24{
25 template <typename Image>
26 void operator()(Image const&)
27 {
28 using image_t = Image;
29 auto const img = fixture::create_image<image_t>(1, 1, 7);
30 auto img_out = fixture::create_image<image_t>(1, 1, 0);
31
32 using pixel_t = typename image_t::value_type;
33 using channel_t = typename gil::channel_type<pixel_t>::type;
34 auto const kernel = fixture::create_kernel<channel_t>({1});
35 gil::convolve_cols<pixel_t>(const_view(img), kernel, view(img_out));
36
37 // 1x1 kernel reduces convolution to multiplication
38 BOOST_TEST(gil::const_view(img).front() == gil::const_view(img_out).front());
39 }
40 static void run()
41 {
42 boost::mp11::mp_for_each<fixture::image_types>(f: test_image_1x1_kernel_1x1_identity{});
43 }
44};
45
46struct test_image_1x1_kernel_3x3_identity
47{
48 template <typename Image>
49 void operator()(Image const&)
50 {
51 using image_t = Image;
52 auto const img = fixture::create_image<image_t>(1, 1, 7);
53 auto img_out = fixture::create_image<image_t>(1, 1, 0);
54
55 using pixel_t = typename image_t::value_type;
56 using channel_t = typename gil::channel_type<pixel_t>::type;
57 auto const kernel = fixture::create_kernel<channel_t>({0, 0, 0, 0, 1, 0, 0, 0, 0});
58 gil::convolve_cols<pixel_t>(const_view(img), kernel, view(img_out));
59
60 BOOST_TEST(gil::const_view(img).front() == gil::const_view(img_out).front());
61 }
62 static void run()
63 {
64 boost::mp11::mp_for_each<fixture::image_types>(f: test_image_1x1_kernel_3x3_identity{});
65 }
66};
67
68int main()
69{
70 test_image_1x1_kernel_1x1_identity::run();
71 test_image_1x1_kernel_3x3_identity::run();
72
73 return ::boost::report_errors();
74}
75

source code of boost/libs/gil/test/core/image_processing/convolve_cols.cpp