allow reading and writing rgb-alpha images in Python (#2925)

pull/2929/head
Adrià Arrufat 7 months ago committed by GitHub
parent d45f534d68
commit d5909ed977
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -262,6 +262,7 @@ namespace dlib
else if (is_image<float>(src)) assign_image(dest, numpy_image<float>(src)); else if (is_image<float>(src)) assign_image(dest, numpy_image<float>(src));
else if (is_image<double>(src)) assign_image(dest, numpy_image<double>(src)); else if (is_image<double>(src)) assign_image(dest, numpy_image<double>(src));
else if (is_image<rgb_pixel>(src)) assign_image(dest, numpy_image<rgb_pixel>(src)); else if (is_image<rgb_pixel>(src)) assign_image(dest, numpy_image<rgb_pixel>(src));
else if (is_image<rgb_alpha_pixel>(src)) assign_image(dest, numpy_image<rgb_alpha_pixel>(src));
else DLIB_CASSERT(false, "Unsupported pixel type used in assign_image()."); else DLIB_CASSERT(false, "Unsupported pixel type used in assign_image().");
} }

@ -20,6 +20,13 @@ numpy_image<rgb_pixel> load_rgb_image (const std::string &path)
return img; return img;
} }
numpy_image<rgb_pixel> load_rgb_alpha_image (const std::string &path)
{
numpy_image<rgb_alpha_pixel> img;
load_image(img, path);
return img;
}
numpy_image<unsigned char> load_grayscale_image (const std::string &path) numpy_image<unsigned char> load_grayscale_image (const std::string &path)
{ {
numpy_image<unsigned char> img; numpy_image<unsigned char> img;
@ -168,6 +175,10 @@ void bind_numpy_returns(py::module &m)
"Saves the given image to the specified path. Determines the file type from the file extension specified in the path", "Saves the given image to the specified path. Determines the file type from the file extension specified in the path",
py::arg("img"), py::arg("filename"), py::arg("quality") = 75 py::arg("img"), py::arg("filename"), py::arg("quality") = 75
); );
m.def("save_image", &save_image<rgb_alpha_pixel>,
"Saves the given image to the specified path. Determines the file type from the file extension specified in the path",
py::arg("img"), py::arg("filename"), py::arg("quality") = 75
);
m.def("save_image", &save_image<unsigned char>, m.def("save_image", &save_image<unsigned char>,
"Saves the given image to the specified path. Determines the file type from the file extension specified in the path", "Saves the given image to the specified path. Determines the file type from the file extension specified in the path",
py::arg("img"), py::arg("filename"), py::arg("quality") = 75 py::arg("img"), py::arg("filename"), py::arg("quality") = 75

Loading…
Cancel
Save