median_filter.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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_median_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. 183, 128, 181, 86, 34, 55, 134, 164, 15,
  18. 90, 59, 94, 158, 202, 0, 106, 120, 255,
  19. 65, 48, 4, 21, 21, 38, 50, 37, 228,
  20. 27, 245, 254, 164, 135, 192, 17, 241, 19,
  21. 56, 165, 253, 169, 24, 200, 249, 70, 199,
  22. 59, 84, 41, 96, 70, 58, 24, 20, 218,
  23. 235, 180, 12, 168, 224, 204, 166, 153, 1,
  24. 181, 213, 232, 178, 165, 253, 93, 214, 72,
  25. 171, 50, 20, 65, 67, 133, 249, 157, 105
  26. };
  27. std::uint8_t output[] =
  28. {
  29. 128, 128, 128, 94, 55, 55, 120, 134, 120,
  30. 90, 90, 86, 86, 38, 50, 55, 120, 164,
  31. 65, 65, 94, 135, 135, 50, 50, 106, 228,
  32. 56, 65, 165, 135, 135, 50, 70, 70, 199,
  33. 59, 84, 165, 135, 135, 70, 70, 70, 199,
  34. 84, 84, 165, 96, 168, 166, 153, 153, 153,
  35. 181, 180, 168, 165, 168, 165, 153, 93, 72,
  36. 181, 180, 168, 165, 168, 166, 166, 153, 105,
  37. 171, 171, 65, 67, 133, 133, 157, 157, 105
  38. };
  39. BOOST_AUTO_TEST_SUITE(filter)
  40. BOOST_AUTO_TEST_CASE(median_filter_with_kernel_size_3)
  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::median_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()