| 2172 | } |
| 2173 | |
| 2174 | void test_partition_pixels() |
| 2175 | { |
| 2176 | matrix<unsigned char> img(4,7); |
| 2177 | |
| 2178 | dlib::rand rnd; |
| 2179 | for (int round = 0; round < 100; ++round) |
| 2180 | { |
| 2181 | print_spinner(); |
| 2182 | for (auto& p : img) |
| 2183 | p = rnd.get_random_8bit_number(); |
| 2184 | |
| 2185 | DLIB_TEST(simple_partition_pixels(img) == partition_pixels(img)); |
| 2186 | unsigned char thresh; |
| 2187 | impl::partition_pixels_float(img,thresh); |
| 2188 | DLIB_TEST(simple_partition_pixels(img) == thresh); |
| 2189 | |
| 2190 | matrix<float> fimg = matrix_cast<float>(img); |
| 2191 | DLIB_TEST(simple_partition_pixels(img) == partition_pixels(fimg)); |
| 2192 | |
| 2193 | |
| 2194 | std::vector<unsigned char> tmp; |
| 2195 | for (auto& v : img) |
| 2196 | if (v >= thresh) |
| 2197 | tmp.push_back(v); |
| 2198 | matrix<unsigned char> img2 = mat(tmp); |
| 2199 | unsigned char thresh2; |
| 2200 | impl::partition_pixels_float(img,thresh, thresh2); |
| 2201 | DLIB_TEST(simple_partition_pixels(img) == thresh); |
| 2202 | DLIB_TEST(simple_partition_pixels(img2) == thresh2); |
| 2203 | |
| 2204 | partition_pixels(img,thresh, thresh2); |
| 2205 | DLIB_TEST(simple_partition_pixels(img) == thresh); |
| 2206 | DLIB_TEST(simple_partition_pixels(img2) == thresh2); |
| 2207 | |
| 2208 | |
| 2209 | |
| 2210 | std::vector<float> ftmp; |
| 2211 | for (auto& v : fimg) |
| 2212 | if (v >= thresh) |
| 2213 | ftmp.push_back(v); |
| 2214 | matrix<float> fimg2 = mat(ftmp); |
| 2215 | float fthresh, fthresh2; |
| 2216 | partition_pixels(fimg,fthresh, fthresh2); |
| 2217 | DLIB_TEST(simple_partition_pixels(img) == fthresh); |
| 2218 | DLIB_TEST(simple_partition_pixels(img2) == fthresh2); |
| 2219 | } |
| 2220 | |
| 2221 | |
| 2222 | img.set_size(245,123); |
| 2223 | for (int round = 0; round < 100; ++round) |
| 2224 | { |
| 2225 | print_spinner(); |
| 2226 | for (auto& p : img) |
| 2227 | p = rnd.get_random_8bit_number(); |
| 2228 | |
| 2229 | DLIB_TEST(simple_partition_pixels(img) == partition_pixels(img)); |
| 2230 | unsigned char thresh; |
| 2231 | impl::partition_pixels_float(img,thresh); |
no test coverage detected