Skip to content

Commit d5909ed

Browse files
authored
allow reading and writing rgb-alpha images in Python (#2925)
1 parent d45f534 commit d5909ed

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

dlib/python/numpy_image.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ namespace dlib
262262
else if (is_image<float>(src)) assign_image(dest, numpy_image<float>(src));
263263
else if (is_image<double>(src)) assign_image(dest, numpy_image<double>(src));
264264
else if (is_image<rgb_pixel>(src)) assign_image(dest, numpy_image<rgb_pixel>(src));
265+
else if (is_image<rgb_alpha_pixel>(src)) assign_image(dest, numpy_image<rgb_alpha_pixel>(src));
265266
else DLIB_CASSERT(false, "Unsupported pixel type used in assign_image().");
266267
}
267268

tools/python/src/numpy_returns.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ numpy_image<rgb_pixel> load_rgb_image (const std::string &path)
2020
return img;
2121
}
2222

23+
numpy_image<rgb_pixel> load_rgb_alpha_image (const std::string &path)
24+
{
25+
numpy_image<rgb_alpha_pixel> img;
26+
load_image(img, path);
27+
return img;
28+
}
29+
2330
numpy_image<unsigned char> load_grayscale_image (const std::string &path)
2431
{
2532
numpy_image<unsigned char> img;
@@ -168,6 +175,10 @@ void bind_numpy_returns(py::module &m)
168175
"Saves the given image to the specified path. Determines the file type from the file extension specified in the path",
169176
py::arg("img"), py::arg("filename"), py::arg("quality") = 75
170177
);
178+
m.def("save_image", &save_image<rgb_alpha_pixel>,
179+
"Saves the given image to the specified path. Determines the file type from the file extension specified in the path",
180+
py::arg("img"), py::arg("filename"), py::arg("quality") = 75
181+
);
171182
m.def("save_image", &save_image<unsigned char>,
172183
"Saves the given image to the specified path. Determines the file type from the file extension specified in the path",
173184
py::arg("img"), py::arg("filename"), py::arg("quality") = 75

0 commit comments

Comments
 (0)