convolve_cols.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. #include <tuple>
  11. #include <type_traits>
  12. #define BOOST_TEST_MODULE test_ext_numeric_colvolve_cols
  13. #include "unit_test.hpp"
  14. #include "unit_test_utility.hpp"
  15. #include "test_fixture.hpp"
  16. #include "core/image/test_fixture.hpp"
  17. namespace gil = boost::gil;
  18. namespace fixture = boost::gil::test::fixture;
  19. BOOST_AUTO_TEST_SUITE(convolve_cols)
  20. BOOST_AUTO_TEST_CASE_TEMPLATE(image_1x1_kernel_1x1_identity, Image, fixture::image_types)
  21. {
  22. auto const img = fixture::create_image<Image>(1, 1, 7);
  23. auto img_out = fixture::create_image<Image>(1, 1, 0);
  24. using pixel_t = typename Image::value_type;
  25. using channel_t = typename gil::channel_type<pixel_t>::type;
  26. auto const kernel = fixture::create_kernel<channel_t>({1});
  27. gil::convolve_cols<pixel_t>(const_view(img), kernel, view(img_out));
  28. // 1x1 kernel reduces convolution to multiplication
  29. BOOST_TEST(gil::const_view(img).front() == gil::const_view(img_out).front());
  30. }
  31. BOOST_AUTO_TEST_CASE_TEMPLATE(image_1x1_kernel_3x3_identity, Image, fixture::image_types)
  32. {
  33. auto const img = fixture::create_image<Image>(1, 1, 7);
  34. auto img_out = fixture::create_image<Image>(1, 1, 0);
  35. using pixel_t = typename Image::value_type;
  36. using channel_t = typename gil::channel_type<pixel_t>::type;
  37. auto const kernel = fixture::create_kernel<channel_t>({0, 0, 0, 0, 1, 0, 0, 0, 0});
  38. gil::convolve_cols<pixel_t>(const_view(img), kernel, view(img_out));
  39. BOOST_TEST(gil::const_view(img).front() == gil::const_view(img_out).front());
  40. }
  41. BOOST_AUTO_TEST_SUITE_END()