]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/gil/test/core/image_processing/threshold_binary.cpp
2 // Copyright 2019 Miral Shah <miralshah2211@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/threshold.hpp>
9 #include <boost/gil/image_view.hpp>
10 #include <boost/gil/algorithm.hpp>
11 #include <boost/gil/gray.hpp>
12 #include <boost/core/lightweight_test.hpp>
15 namespace gil
= boost::gil
;
20 gil::gray8_image_t
original_gray(width
, height
), threshold_gray(width
, height
),
21 expected_gray(width
, height
);
23 gil::rgb8_image_t
original_rgb(width
, height
), threshold_rgb(width
, height
),
24 expected_rgb(width
, height
);
27 void fill_original_gray()
29 //filling original_gray view's upper half part with gray pixels of value 50
30 //filling original_gray view's lower half part with gray pixels of value 150
31 gil::fill_pixels(gil::subimage_view(gil::view(original_gray
), 0, 0, original_gray
.width(),
32 original_gray
.height() / 2), gil::gray8_pixel_t(50));
33 gil::fill_pixels(gil::subimage_view(gil::view(original_gray
), 0, original_gray
.height() / 2,
34 original_gray
.width(), original_gray
.height() / 2), gil::gray8_pixel_t(150));
37 void fill_original_rgb()
39 //filling original_rgb view's upper half part with rgb pixels of value 50, 155, 115
40 //filling original_rgb view's lower half part with rgb pixels of value 203, 9, 60
41 gil::fill_pixels(gil::subimage_view(gil::view(original_rgb
), 0, 0, original_rgb
.width(),
42 original_rgb
.height() / 2), gil::rgb8_pixel_t(50, 155, 115));
43 gil::fill_pixels(gil::subimage_view(gil::view(original_rgb
), 0, original_rgb
.height() / 2,
44 original_rgb
.width(), original_rgb
.height() / 2), gil::rgb8_pixel_t(203, 9, 60));
47 void binary_gray_to_gray()
49 //expected_gray view after thresholding of the original_gray view with threshold_gray value of 100
50 //filling expected_gray view's upper half part with gray pixels of value 0
51 //filling expected_gray view's lower half part with gray pixels of value 255
52 gil::fill_pixels(gil::subimage_view(gil::view(expected_gray
), 0, 0, original_gray
.width(),
53 original_gray
.height() / 2), gil::gray8_pixel_t(0));
54 gil::fill_pixels(gil::subimage_view(gil::view(expected_gray
), 0, original_gray
.height() / 2,
55 original_gray
.width(), original_gray
.height() / 2), gil::gray8_pixel_t(255));
57 gil::threshold_binary(gil::view(original_gray
), gil::view(threshold_gray
), 100);
59 //comparing threshold_gray view generated by the function with the expected_gray view
60 BOOST_TEST(gil::equal_pixels(gil::view(threshold_gray
), gil::view(expected_gray
)));
63 void binary_inverse_gray_to_gray()
65 //expected_gray view after thresholding of the original_gray view with threshold_gray value of 100
66 //filling expected_gray view's upper half part with gray pixels of value 200
67 //filling expected_gray view's lower half part with gray pixels of value 0
68 gil::fill_pixels(gil::subimage_view(gil::view(expected_gray
), 0, 0, original_gray
.width(),
69 original_gray
.height() / 2), gil::gray8_pixel_t(200));
70 gil::fill_pixels(gil::subimage_view(gil::view(expected_gray
), 0, original_gray
.height() / 2,
71 original_gray
.width(), original_gray
.height() / 2), gil::gray8_pixel_t(0));
75 gil::view(original_gray
),
76 gil::view(threshold_gray
),
79 gil::threshold_direction::inverse
82 //comparing threshold_gray view generated by the function with the expected_gray view
83 BOOST_TEST(gil::equal_pixels(gil::view(threshold_gray
), gil::view(expected_gray
)));
86 void binary_rgb_to_rgb()
88 //expected_rgb view after thresholding of the original_rgb view with threshold value of 100
89 //filling expected_rgb view's upper half part with rgb pixels of value 0, 165, 165
90 //filling expected_rgb view's lower half part with rgb pixels of value 165, 0, 0
91 gil::fill_pixels(gil::subimage_view(gil::view(expected_rgb
), 0, 0, original_rgb
.width(),
92 original_rgb
.height() / 2), gil::rgb8_pixel_t(0, 165, 165));
93 gil::fill_pixels(gil::subimage_view(gil::view(expected_rgb
), 0, original_rgb
.height() / 2,
94 original_rgb
.width(), original_rgb
.height() / 2), gil::rgb8_pixel_t(165, 0, 0));
96 gil::threshold_binary(gil::view(original_rgb
), gil::view(threshold_rgb
), 100, 165);
98 //comparing threshold_rgb view generated by the function with the expected_rgb view
99 BOOST_TEST(gil::equal_pixels(gil::view(threshold_rgb
), gil::view(expected_rgb
)));
102 void binary_inverse_rgb_to_rgb()
104 //expected_rgb view after thresholding of the original_rgb view with threshold value of 100
105 //filling expected_rgb view's upper half part with rgb pixels of value 90, 0, 0
106 //filling expected_rgb view's lower half part with rgb pixels of value 0, 90, 90
107 gil::fill_pixels(gil::subimage_view(gil::view(expected_rgb
), 0, 0, original_rgb
.width(),
108 original_rgb
.height() / 2), gil::rgb8_pixel_t(90, 0, 0));
109 gil::fill_pixels(gil::subimage_view(gil::view(expected_rgb
), 0, original_rgb
.height() / 2,
110 original_rgb
.width(), original_rgb
.height() / 2), gil::rgb8_pixel_t(0, 90, 90));
112 gil::threshold_binary
114 gil::view(original_rgb
),
115 gil::view(threshold_rgb
),
118 gil::threshold_direction::inverse
121 //comparing threshold_rgb view generated by the function with the expected_rgb view
122 BOOST_TEST(gil::equal_pixels(gil::view(threshold_rgb
), gil::view(expected_rgb
)));
128 fill_original_gray();
131 binary_gray_to_gray();
132 binary_inverse_gray_to_gray();
134 binary_inverse_rgb_to_rgb();
136 return boost::report_errors();