@@ -17,12 +17,21 @@ namespace gil = boost::gil;
1717int height = 4 ;
1818int width = 4 ;
1919
20- gil::gray8_image_t original_gray (width, height), threshold_gray(width, height),
21- expected_gray(width, height);
20+ gil::gray8_image_t original_gray (width, height);
21+ gil::gray8_image_t threshold_gray (width, height);
22+ gil::gray8_image_t expected_gray (width, height);
2223
23- gil::rgb8_image_t original_rgb (width, height), threshold_rgb(width, height),
24- expected_rgb(width, height);
24+ gil::rgb8_image_t original_rgb (width, height);
25+ gil::rgb8_image_t threshold_rgb (width, height);
26+ gil::rgb8_image_t expected_rgb (width, height);
2527
28+ gil::rgb8s_image_t original_rgbs (width, height);
29+ gil::rgb8s_image_t threshold_rgbs (width, height);
30+ gil::rgb8s_image_t expected_rgbs (width, height);
31+
32+ gil::gray32f_image_t original_gray32f (width, height);
33+ gil::gray32f_image_t threshold_gray32f (width, height);
34+ gil::gray32f_image_t expected_gray32f (width, height);
2635
2736void fill_original_gray ()
2837{
@@ -44,6 +53,26 @@ void fill_original_rgb()
4453 original_rgb.width (), original_rgb.height () / 2 ), gil::rgb8_pixel_t (203 , 9 , 60 ));
4554}
4655
56+ void fill_original_rgbs ()
57+ {
58+ // filling original_rgb view's upper half part with rgbs pixels of value 50, 155, 115
59+ // filling original_rgb view's lower half part with rgbs pixels of value 203, 9, 60
60+ gil::fill_pixels (gil::subimage_view (gil::view (original_rgbs), 0 , 0 , original_rgbs.width (),
61+ original_rgbs.height () / 2 ), gil::rgb8s_pixel_t (-42 , 80 , 83 ));
62+ gil::fill_pixels (gil::subimage_view (gil::view (original_rgbs), 0 , original_rgbs.height () / 2 ,
63+ original_rgbs.width (), original_rgbs.height () / 2 ), gil::rgb8s_pixel_t (95 , -50 , 42 ));
64+ }
65+
66+ void fill_original_gray32f ()
67+ {
68+ // filling original_gray view's upper half part with gray pixels of value 0.3
69+ // filling original_gray view's lower half part with gray pixels of value 0.7
70+ gil::fill_pixels (gil::subimage_view (gil::view (original_gray32f), 0 , 0 , original_gray32f.width (),
71+ original_gray32f.height () / 2 ), gil::gray32f_pixel_t (0 .3f ));
72+ gil::fill_pixels (gil::subimage_view (gil::view (original_gray32f), 0 , original_gray32f.height () / 2 ,
73+ original_gray32f.width (), original_gray32f.height () / 2 ), gil::gray32f_pixel_t (0 .7f ));
74+ }
75+
4776void binary_gray_to_gray ()
4877{
4978 // expected_gray view after thresholding of the original_gray view with threshold_gray value of 100
@@ -122,16 +151,51 @@ void binary_inverse_rgb_to_rgb()
122151 BOOST_TEST (gil::equal_pixels (gil::view (threshold_rgb), gil::view (expected_rgb)));
123152}
124153
154+ void binary_rgbs_to_rgbs ()
155+ {
156+ // expected_rgbs view after thresholding of the original_rgbs view with threshold value of 70
157+ // filling expected_rgb view's upper half part with rgb pixels of value -128, 127, 127
158+ // filling expected_rgb view's lower half part with rgb pixels of value 127, -128, -128
159+ gil::fill_pixels (gil::subimage_view (gil::view (expected_rgbs), 0 , 0 , original_rgbs.width (),
160+ original_rgbs.height () / 2 ), gil::rgb8s_pixel_t (-128 , 95 , 95 ));
161+ gil::fill_pixels (gil::subimage_view (gil::view (expected_rgbs), 0 , original_rgbs.height () / 2 ,
162+ original_rgbs.width (), original_rgbs.height () / 2 ), gil::rgb8s_pixel_t (95 , -128 , -128 ));
163+
164+ gil::threshold_binary (gil::view (original_rgbs), gil::view (threshold_rgbs), 70 , 95 );
165+
166+ // comparing threshold_rgb view generated by the function with the expected_rgb view
167+ BOOST_TEST (gil::equal_pixels (gil::view (threshold_rgb), gil::view (expected_rgb)));
168+ }
169+
170+ void binary_gray32f_to_gray32f ()
171+ {
172+ // expected_gray view after thresholding of the original_gray view with threshold_gray value of 0.5f
173+ // filling expected_gray view's upper half part with gray pixels of value 0.0
174+ // filling expected_gray view's lower half part with gray pixels of value 1.0f
175+ gil::fill_pixels (gil::subimage_view (gil::view (expected_gray32f), 0 , 0 , original_gray32f.width (),
176+ original_gray32f.height () / 2 ), gil::gray32f_pixel_t (0 .0f ));
177+ gil::fill_pixels (gil::subimage_view (gil::view (expected_gray32f), 0 , original_gray32f.height () / 2 ,
178+ original_gray32f.width (), original_gray32f.height () / 2 ), gil::gray32f_pixel_t (1 .0f ));
179+
180+ gil::threshold_binary (gil::view (original_gray32f), gil::view (threshold_gray32f), 0.5 );
181+
182+ // comparing threshold_gray view generated by the function with the expected_gray view
183+ BOOST_TEST (gil::equal_pixels (gil::view (threshold_gray32f), gil::view (expected_gray32f)));
184+ }
125185
126186int main ()
127187{
128188 fill_original_gray ();
129189 fill_original_rgb ();
190+ fill_original_rgbs ();
191+ fill_original_gray32f ();
130192
131193 binary_gray_to_gray ();
132194 binary_inverse_gray_to_gray ();
133195 binary_rgb_to_rgb ();
196+ binary_rgbs_to_rgbs ();
134197 binary_inverse_rgb_to_rgb ();
198+ binary_gray32f_to_gray32f ();
135199
136200 return boost::report_errors ();
137201}
0 commit comments