box_filter.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //
  2. // Copyright 2019 Miral Shah <miralshah2211@gmail.com>
  3. //
  4. // Use, modification and distribution are subject to the Boost Software License,
  5. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. #define BOOST_TEST_MODULE test_image_processing_box_filter
  9. #include "unit_test.hpp"
  10. #include <boost/gil/image_view.hpp>
  11. #include <boost/gil/algorithm.hpp>
  12. #include <boost/gil/gray.hpp>
  13. #include <boost/gil/image_processing/filter.hpp>
  14. namespace gil = boost::gil;
  15. std::uint8_t img[] =
  16. {
  17. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  18. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  19. 0, 0, 255, 0, 0, 0, 255, 0, 0,
  20. 0, 0, 0, 255, 0, 255, 0, 0, 0,
  21. 0, 0, 0, 0, 255, 0, 0, 0, 0,
  22. 0, 0, 0, 255, 0, 255, 0, 0, 0,
  23. 0, 0, 255, 0, 0, 0, 255, 0, 0,
  24. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  25. 0, 0, 0, 0, 0, 0, 0, 0, 0
  26. };
  27. std::uint8_t output[] =
  28. {
  29. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  30. 0, 28, 28, 28, 0, 28, 28, 28, 0,
  31. 0, 28, 56, 56, 56, 56, 56, 28, 0,
  32. 0, 28, 56, 85, 85, 85, 56, 28, 0,
  33. 0, 0, 56, 85, 141, 85, 56, 0, 0,
  34. 0, 28, 56, 85, 85, 85, 56, 28, 0,
  35. 0, 28, 56, 56, 56, 56, 56, 28, 0,
  36. 0, 28, 28, 28, 0, 28, 28, 28, 0,
  37. 0, 0, 0, 0, 0, 0, 0, 0, 0
  38. };
  39. BOOST_AUTO_TEST_SUITE(filter)
  40. BOOST_AUTO_TEST_CASE(box_filter_with_default_parameters)
  41. {
  42. gil::gray8c_view_t src_view =
  43. gil::interleaved_view(9, 9, reinterpret_cast<const gil::gray8_pixel_t*>(img), 9);
  44. gil::image<gil::gray8_pixel_t> temp_img(src_view.width(), src_view.height());
  45. typename gil::image<gil::gray8_pixel_t>::view_t temp_view = view(temp_img);
  46. gil::gray8_view_t dst_view(temp_view);
  47. gil::box_filter(src_view, dst_view, 3);
  48. gil::gray8c_view_t out_view =
  49. gil::interleaved_view(9, 9, reinterpret_cast<const gil::gray8_pixel_t*>(output), 9);
  50. BOOST_TEST(gil::equal_pixels(out_view, dst_view));
  51. }
  52. BOOST_AUTO_TEST_SUITE_END()