Added equalize_histogram() and resize_image() to the Python API.

This commit is contained in:
Davis King 2018-05-20 22:34:49 -04:00
parent 1df5227e3e
commit a190a1c242
3 changed files with 67 additions and 0 deletions

View File

@ -61,6 +61,7 @@ set(python_srcs
src/sequence_segmenter.cpp
src/svm_struct.cpp
src/image.cpp
src/image2.cpp
src/rectangles.cpp
src/object_detection.cpp
src/shape_predictor.cpp

View File

@ -19,6 +19,7 @@ void bind_cca(py::module& m);
void bind_sequence_segmenter(py::module& m);
void bind_svm_struct(py::module& m);
void bind_image_classes(py::module& m);
void bind_image_classes2(py::module& m);
void bind_rectangles(py::module& m);
void bind_object_detection(py::module& m);
void bind_shape_predictors(py::module& m);
@ -91,6 +92,7 @@ PYBIND11_MODULE(dlib, m)
bind_sequence_segmenter(m);
bind_svm_struct(m);
bind_image_classes(m);
bind_image_classes2(m);
bind_rectangles(m);
bind_object_detection(m);
bind_shape_predictors(m);

View File

@ -0,0 +1,64 @@
#include "opaque_types.h"
#include <dlib/python.h>
#include "dlib/pixel.h"
#include <dlib/image_transforms.h>
#include <dlib/image_processing.h>
using namespace dlib;
using namespace std;
namespace py = pybind11;
// ----------------------------------------------------------------------------------------
template <typename T>
numpy_image<T> py_resize_image (
const numpy_image<T>& img,
unsigned long rows,
unsigned long cols
)
{
numpy_image<T> out;
set_image_size(out, rows, cols);
resize_image(img, out);
return out;
}
// ----------------------------------------------------------------------------------------
template <typename T>
numpy_image<T> py_equalize_histogram (
const numpy_image<T>& img
)
{
numpy_image<T> out;
equalize_histogram(img,out);
return out;
}
// ----------------------------------------------------------------------------------------
void bind_image_classes2(py::module& m)
{
const char* docs = "Resizes img, using bilinear interpolation, to have the indicated number of rows and columns.";
m.def("resize_image", &py_resize_image<uint8_t>, py::arg("img"), py::arg("rows"), py::arg("cols"));
m.def("resize_image", &py_resize_image<uint16_t>, py::arg("img"), py::arg("rows"), py::arg("cols"));
m.def("resize_image", &py_resize_image<uint32_t>, py::arg("img"), py::arg("rows"), py::arg("cols"));
m.def("resize_image", &py_resize_image<uint64_t>, py::arg("img"), py::arg("rows"), py::arg("cols"));
m.def("resize_image", &py_resize_image<int8_t>, py::arg("img"), py::arg("rows"), py::arg("cols"));
m.def("resize_image", &py_resize_image<int16_t>, py::arg("img"), py::arg("rows"), py::arg("cols"));
m.def("resize_image", &py_resize_image<int32_t>, py::arg("img"), py::arg("rows"), py::arg("cols"));
m.def("resize_image", &py_resize_image<int64_t>, py::arg("img"), py::arg("rows"), py::arg("cols"));
m.def("resize_image", &py_resize_image<float>, py::arg("img"), py::arg("rows"), py::arg("cols"));
m.def("resize_image", &py_resize_image<double>, docs, py::arg("img"), py::arg("rows"), py::arg("cols"));
docs = "Returns a histogram equalized version of img.";
m.def("equalize_histogram", &py_equalize_histogram<uint8_t>, py::arg("img"));
m.def("equalize_histogram", &py_equalize_histogram<uint16_t>, docs, py::arg("img"));
}