| 374 | // ---------------------------------------------------------------------------------------- |
| 375 | |
| 376 | void bind_image_classes3(py::module& m) |
| 377 | { |
| 378 | const char* docs; |
| 379 | |
| 380 | docs = |
| 381 | "requires \n\ |
| 382 | - thresh > 0 \n\ |
| 383 | ensures \n\ |
| 384 | - Converts an image to a target pixel type. dtype must be a string containing one of the following: \n\ |
| 385 | uint8, int8, uint16, int16, uint32, int32, uint64, int64, float32, float, float64, double, or rgb_pixel \n\ |
| 386 | \n\ |
| 387 | The contents of img will be scaled to fit the dynamic range of the target \n\ |
| 388 | pixel type. The thresh parameter is used to filter source pixel values which \n\ |
| 389 | are outliers. These outliers will saturate at the edge of the destination \n\ |
| 390 | image's dynamic range. \n\ |
| 391 | - Specifically, for all valid r and c: \n\ |
| 392 | - We scale img[r][c] into the dynamic range of the target pixel type. This \n\ |
| 393 | is done using the mean and standard deviation of img. Call the mean M and \n\ |
| 394 | the standard deviation D. Then the scaling from source to destination is \n\ |
| 395 | performed using the following mapping: \n\ |
| 396 | let SRC_UPPER = min(M + thresh*D, max(img)) \n\ |
| 397 | let SRC_LOWER = max(M - thresh*D, min(img)) \n\ |
| 398 | let DEST_UPPER = max value possible for the selected dtype. \n\ |
| 399 | let DEST_LOWER = min value possible for the selected dtype. \n\ |
| 400 | \n\ |
| 401 | MAPPING: [SRC_LOWER, SRC_UPPER] -> [DEST_LOWER, DEST_UPPER] \n\ |
| 402 | \n\ |
| 403 | Where this mapping is a linear mapping of values from the left range \n\ |
| 404 | into the right range of values. Source pixel values outside the left \n\ |
| 405 | range are modified to be at the appropriate end of the range."; |
| 406 | /*! |
| 407 | requires |
| 408 | - thresh > 0 |
| 409 | ensures |
| 410 | - Converts an image to a target pixel type. dtype must be a string containing one of the following: |
| 411 | uint8, int8, uint16, int16, uint32, int32, uint64, int64, float32, float, float64, double, or rgb_pixel |
| 412 | |
| 413 | The contents of img will be scaled to fit the dynamic range of the target |
| 414 | pixel type. The thresh parameter is used to filter source pixel values which |
| 415 | are outliers. These outliers will saturate at the edge of the destination |
| 416 | image's dynamic range. |
| 417 | - Specifically, for all valid r and c: |
| 418 | - We scale img[r][c] into the dynamic range of the target pixel type. This |
| 419 | is done using the mean and standard deviation of img. Call the mean M and |
| 420 | the standard deviation D. Then the scaling from source to destination is |
| 421 | performed using the following mapping: |
| 422 | let SRC_UPPER = min(M + thresh*D, max(img)) |
| 423 | let SRC_LOWER = max(M - thresh*D, min(img)) |
| 424 | let DEST_UPPER = max value possible for the selected dtype. |
| 425 | let DEST_LOWER = min value possible for the selected dtype. |
| 426 | |
| 427 | MAPPING: [SRC_LOWER, SRC_UPPER] -> [DEST_LOWER, DEST_UPPER] |
| 428 | |
| 429 | Where this mapping is a linear mapping of values from the left range |
| 430 | into the right range of values. Source pixel values outside the left |
| 431 | range are modified to be at the appropriate end of the range. |
| 432 | !*/ |
| 433 | m.def("convert_image_scaled", convert_image_scaled<uint8_t>, py::arg("img"), py::arg("dtype"), py::arg("thresh")=4); |