From c1f5f32b2a6e8cae263a60609391858608269cbd Mon Sep 17 00:00:00 2001 From: Davis King Date: Thu, 24 May 2018 20:59:45 -0400 Subject: [PATCH] Renamed convert_rgb_to_grayscale() to as_grayscale() and made it take any numpy array as input. --- tools/python/src/image.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/tools/python/src/image.cpp b/tools/python/src/image.cpp index 1bda47956..75e6bbfdb 100644 --- a/tools/python/src/image.cpp +++ b/tools/python/src/image.cpp @@ -225,13 +225,20 @@ py::array convert_image ( "uint8, int8, uint16, int16, uint32, int32, uint64, int64, float32, float, float64, double, or rgb_pixel"); } -numpy_image convert_rgb_to_grayscale( - const numpy_image& img +py::array as_grayscale( + const py::array& img ) { - numpy_image out; - assign_image(out, img); - return out; + if (is_image(img)) + { + numpy_image out; + assign_image(out, numpy_image(img)); + return out; + } + else + { + return img; + } } // ---------------------------------------------------------------------------------------- @@ -1067,8 +1074,8 @@ than 0 are converted to 0."; m.def("convert_image", convert_image, py::arg("img"), py::arg("dtype")); m.def("convert_image", convert_image, docs, py::arg("img"), py::arg("dtype")); - m.def("convert_rgb_to_grayscale", &convert_rgb_to_grayscale, - "Convert a RGB image to a uint8 grayscale image.", py::arg("img")); + m.def("as_grayscale", &as_grayscale, + "Convert an image to 8bit grayscale. If it's already a grayscale image do nothing and just return img.", py::arg("img")); docs = "requires \n\