| 254 | // ---------------------------------------------------------------------------------------- |
| 255 | |
| 256 | void bind_image_classes(py::module& m) |
| 257 | { |
| 258 | |
| 259 | |
| 260 | |
| 261 | py::class_<rgb_pixel>(m, "rgb_pixel") |
| 262 | .def(py::init<unsigned char,unsigned char,unsigned char>(), py::arg("red"), py::arg("green"), py::arg("blue")) |
| 263 | .def("__str__", &print_rgb_pixel_str) |
| 264 | .def("__repr__", &print_rgb_pixel_repr) |
| 265 | .def_readwrite("red", &rgb_pixel::red) |
| 266 | .def_readwrite("green", &rgb_pixel::green) |
| 267 | .def_readwrite("blue", &rgb_pixel::blue); |
| 268 | |
| 269 | const char* docs = "Thresholds img and returns the result. Pixels in img with grayscale values >= partition_pixels(img) \n" |
| 270 | "have an output value of 255 and all others have a value of 0."; |
| 271 | m.def("threshold_image", &py_threshold_image<unsigned char>, py::arg("img") ); |
| 272 | m.def("threshold_image", &py_threshold_image<uint16_t>, py::arg("img") ); |
| 273 | m.def("threshold_image", &py_threshold_image<uint32_t>, py::arg("img") ); |
| 274 | m.def("threshold_image", &py_threshold_image<float>, py::arg("img") ); |
| 275 | m.def("threshold_image", &py_threshold_image<double>, py::arg("img") ); |
| 276 | m.def("threshold_image", &py_threshold_image<rgb_pixel>,docs, py::arg("img") ); |
| 277 | |
| 278 | docs = "Thresholds img and returns the result. Pixels in img with grayscale values >= thresh \n" |
| 279 | "have an output value of 255 and all others have a value of 0."; |
| 280 | m.def("threshold_image", &py_threshold_image2<unsigned char>, py::arg("img"), py::arg("thresh") ); |
| 281 | m.def("threshold_image", &py_threshold_image2<uint16_t>, py::arg("img"), py::arg("thresh") ); |
| 282 | m.def("threshold_image", &py_threshold_image2<uint32_t>, py::arg("img"), py::arg("thresh") ); |
| 283 | m.def("threshold_image", &py_threshold_image2<float>, py::arg("img"), py::arg("thresh") ); |
| 284 | m.def("threshold_image", &py_threshold_image2<double>, py::arg("img"), py::arg("thresh") ); |
| 285 | m.def("threshold_image", &py_threshold_image2<rgb_pixel>,docs, py::arg("img"), py::arg("thresh") ); |
| 286 | |
| 287 | |
| 288 | docs = |
| 289 | "Finds a threshold value that would be reasonable to use with \n\ |
| 290 | threshold_image(img, threshold). It does this by finding the threshold that \n\ |
| 291 | partitions the pixels in img into two groups such that the sum of absolute \n\ |
| 292 | deviations between each pixel and the mean of its group is minimized."; |
| 293 | m.def("partition_pixels", &py_partition_pixels<rgb_pixel>, py::arg("img") ); |
| 294 | m.def("partition_pixels", &py_partition_pixels<unsigned char>, py::arg("img") ); |
| 295 | m.def("partition_pixels", &py_partition_pixels<uint16_t>, py::arg("img") ); |
| 296 | m.def("partition_pixels", &py_partition_pixels<uint32_t>, py::arg("img") ); |
| 297 | m.def("partition_pixels", &py_partition_pixels<float>, py::arg("img") ); |
| 298 | m.def("partition_pixels", &py_partition_pixels<double>,docs, py::arg("img") ); |
| 299 | |
| 300 | docs = |
| 301 | "This version of partition_pixels() finds multiple partitions rather than just \n\ |
| 302 | one partition. It does this by first partitioning the pixels just as the \n\ |
| 303 | above partition_pixels(img) does. Then it forms a new image with only pixels \n\ |
| 304 | >= that first partition value and recursively partitions this new image. \n\ |
| 305 | However, the recursion is implemented in an efficient way which is faster than \n\ |
| 306 | explicitly forming these images and calling partition_pixels(), but the \n\ |
| 307 | output is the same as if you did. For example, suppose you called \n\ |
| 308 | [t1,t2,t2] = partition_pixels(img,3). Then we would have: \n\ |
| 309 | - t1 == partition_pixels(img) \n\ |
| 310 | - t2 == partition_pixels(an image with only pixels with values >= t1 in it) \n\ |
| 311 | - t3 == partition_pixels(an image with only pixels with values >= t2 in it)" ; |
| 312 | m.def("partition_pixels", &py_partition_pixels2<rgb_pixel>, py::arg("img"), py::arg("num_thresholds") ); |
| 313 | m.def("partition_pixels", &py_partition_pixels2<unsigned char>, py::arg("img"), py::arg("num_thresholds") ); |
no test coverage detected