]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/gil/test/core/image_processing/harris.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / gil / test / core / image_processing / harris.cpp
1 //
2 // Copyright 2019 Olzhas Zhumabek <anonymous.from.applecity@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 #include <boost/core/lightweight_test.hpp>
9 #include <boost/gil/image.hpp>
10 #include <boost/gil/image_view.hpp>
11 #include <boost/gil/image_processing/numeric.hpp>
12 #include <boost/gil/image_processing/harris.hpp>
13
14 namespace gil = boost::gil;
15
16 bool are_equal(gil::gray32f_view_t expected, gil::gray32f_view_t actual) {
17 if (expected.dimensions() != actual.dimensions())
18 return false;
19
20 for (long int y = 0; y < expected.height(); ++y)
21 {
22 for (long int x = 0; x < expected.width(); ++x)
23 {
24 if (expected(x, y) != actual(x, y))
25 {
26 return false;
27 }
28 }
29 }
30
31 return true;
32 }
33
34 void test_blank_image()
35 {
36 const gil::point_t dimensions(20, 20);
37 gil::gray16s_image_t dx(dimensions, gil::gray16s_pixel_t(0), 0);
38 gil::gray16s_image_t dy(dimensions, gil::gray16s_pixel_t(0), 0);
39
40 gil::gray32f_image_t m11(dimensions);
41 gil::gray32f_image_t m12_21(dimensions);
42 gil::gray32f_image_t m22(dimensions);
43 gil::gray32f_image_t expected(dimensions, gil::gray32f_pixel_t(0), 0);
44 gil::compute_tensor_entries(
45 gil::view(dx),
46 gil::view(dy),
47 gil::view(m11),
48 gil::view(m12_21),
49 gil::view(m22)
50 );
51 BOOST_TEST(are_equal(gil::view(expected), gil::view(m11)));
52 BOOST_TEST(are_equal(gil::view(expected), gil::view(m12_21)));
53 BOOST_TEST(are_equal(gil::view(expected), gil::view(m22)));
54
55 gil::gray32f_image_t harris_response(dimensions, gil::gray32f_pixel_t(0), 0);
56 auto unnormalized_mean = gil::generate_unnormalized_mean(5);
57 gil::compute_harris_responses(
58 gil::view(m11),
59 gil::view(m12_21),
60 gil::view(m22),
61 unnormalized_mean,
62 0.04f,
63 gil::view(harris_response)
64 );
65 BOOST_TEST(are_equal(gil::view(expected), gil::view(harris_response)));
66 }
67
68 int main(int argc, char* argv[])
69 {
70 test_blank_image();
71 return boost::report_errors();
72 }