]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/gil/test/core/image_processing/simple_kernels.cpp
2 // Copyright 2019 Olzhas Zhumabek <anonymous.from.applecity@gmail.com>
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)
8 #include <boost/gil/image_processing/numeric.hpp>
9 #include <boost/gil/image.hpp>
10 #include <boost/gil/image_view.hpp>
11 #include <boost/gil/typedefs.hpp>
12 #include <boost/core/lightweight_test.hpp>
14 namespace gil
= boost::gil
;
16 void test_normalized_mean_generation()
18 auto kernel
= gil::generate_normalized_mean(5);
19 for (const auto& cell
: kernel
)
21 const auto expected_value
= static_cast<float>(1 / 25.f
);
22 BOOST_TEST(cell
== expected_value
);
26 void test_unnormalized_mean_generation()
28 auto kernel
= gil::generate_unnormalized_mean(5);
29 for (const auto& cell
: kernel
)
31 BOOST_TEST(cell
== 1.0f
);
35 void test_gaussian_kernel_generation()
37 auto kernel
= boost::gil::generate_gaussian_kernel(7, 0.84089642);
38 const float expected_values
[7][7] =
40 {0.00000067f
, 0.00002292f
, 0.00019117f
, 0.00038771f
, 0.00019117f
, 0.00002292f
, 0.00000067f
},
41 {0.00002292f
, 0.00078633f
, 0.00655965f
, 0.01330373f
, 0.00655965f
, 0.00078633f
, 0.00002292f
},
42 {0.00019117f
, 0.00655965f
, 0.05472157f
, 0.11098164f
, 0.05472157f
, 0.00655965f
, 0.00019117f
},
43 {0.00038771f
, 0.01330373f
, 0.11098164f
, 0.25508352f
, 0.11098164f
, 0.01330373f
, 0.00038711f
},
44 {0.00019117f
, 0.00655965f
, 0.05472157f
, 0.11098164f
, 0.05472157f
, 0.00655965f
, 0.00019117f
},
45 {0.00002292f
, 0.00078633f
, 0.00655965f
, 0.01330373f
, 0.00655965f
, 0.00078633f
, 0.00002292f
},
46 {0.00000067f
, 0.00002292f
, 0.00019117f
, 0.00038771f
, 0.00019117f
, 0.00002292f
, 0.00000067f
}
49 for (gil::gray32f_view_t::coord_t y
= 0; static_cast<std::size_t>(y
) < kernel
.size(); ++y
)
51 for (gil::gray32f_view_t::coord_t x
= 0; static_cast<std::size_t>(x
) < kernel
.size(); ++x
)
53 auto output
= kernel
.at(static_cast<std::size_t>(x
), static_cast<std::size_t>(y
));
54 auto expected
= expected_values
[y
][x
];
55 auto percent_difference
= std::ceil(std::abs(expected
- output
) / expected
);
56 BOOST_TEST(percent_difference
< 5);
63 test_normalized_mean_generation();
64 test_unnormalized_mean_generation();
65 test_gaussian_kernel_generation();
66 return boost::report_errors();