@@ -17,12 +17,21 @@ namespace gil = boost::gil;
17
17
int height = 4 ;
18
18
int width = 4 ;
19
19
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);
22
23
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);
25
27
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);
26
35
27
36
void fill_original_gray ()
28
37
{
@@ -44,6 +53,26 @@ void fill_original_rgb()
44
53
original_rgb.width (), original_rgb.height () / 2 ), gil::rgb8_pixel_t (203 , 9 , 60 ));
45
54
}
46
55
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
+
47
76
void binary_gray_to_gray ()
48
77
{
49
78
// 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()
122
151
BOOST_TEST (gil::equal_pixels (gil::view (threshold_rgb), gil::view (expected_rgb)));
123
152
}
124
153
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
+ }
125
185
126
186
int main ()
127
187
{
128
188
fill_original_gray ();
129
189
fill_original_rgb ();
190
+ fill_original_rgbs ();
191
+ fill_original_gray32f ();
130
192
131
193
binary_gray_to_gray ();
132
194
binary_inverse_gray_to_gray ();
133
195
binary_rgb_to_rgb ();
196
+ binary_rgbs_to_rgbs ();
134
197
binary_inverse_rgb_to_rgb ();
198
+ binary_gray32f_to_gray32f ();
135
199
136
200
return boost::report_errors ();
137
201
}
0 commit comments