From 0249bcb9dec85b582b7af69a7922dd22242bb16b Mon Sep 17 00:00:00 2001 From: Davis King Date: Sun, 27 May 2018 11:05:20 -0400 Subject: [PATCH] Added get_histogram() to the python API. Also added more overloads of label_connected_blobs(). --- tools/python/src/image.cpp | 15 ++++++++++++--- tools/python/src/image2.cpp | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/tools/python/src/image.cpp b/tools/python/src/image.cpp index 1e10f30e7..927639f80 100644 --- a/tools/python/src/image.cpp +++ b/tools/python/src/image.cpp @@ -820,9 +820,18 @@ ensures \n\ - blob labels are contiguous, therefore, the number returned by this function is the number of blobs in the image (including the background blob). !*/ - m.def("label_connected_blobs", py_label_connected_blobs, py::arg("img"),py::arg("zero_pixels_are_background")=true,py::arg("neighborhood_connectivity")=8,py::arg("connected_if_both_not_zero")=false); - m.def("label_connected_blobs", py_label_connected_blobs, py::arg("img"),py::arg("zero_pixels_are_background")=true,py::arg("neighborhood_connectivity")=8,py::arg("connected_if_both_not_zero")=false); - m.def("label_connected_blobs", py_label_connected_blobs, docs, py::arg("img"),py::arg("zero_pixels_are_background")=true,py::arg("neighborhood_connectivity")=8,py::arg("connected_if_both_not_zero")=false); + m.def("label_connected_blobs", py_label_connected_blobs, + py::arg("img"),py::arg("zero_pixels_are_background")=true,py::arg("neighborhood_connectivity")=8,py::arg("connected_if_both_not_zero")=false); + m.def("label_connected_blobs", py_label_connected_blobs, + py::arg("img"),py::arg("zero_pixels_are_background")=true,py::arg("neighborhood_connectivity")=8,py::arg("connected_if_both_not_zero")=false); + m.def("label_connected_blobs", py_label_connected_blobs, + py::arg("img"),py::arg("zero_pixels_are_background")=true,py::arg("neighborhood_connectivity")=8,py::arg("connected_if_both_not_zero")=false); + m.def("label_connected_blobs", py_label_connected_blobs, + py::arg("img"),py::arg("zero_pixels_are_background")=true,py::arg("neighborhood_connectivity")=8,py::arg("connected_if_both_not_zero")=false); + m.def("label_connected_blobs", py_label_connected_blobs, + py::arg("img"),py::arg("zero_pixels_are_background")=true,py::arg("neighborhood_connectivity")=8,py::arg("connected_if_both_not_zero")=false); + m.def("label_connected_blobs", py_label_connected_blobs, docs, + py::arg("img"),py::arg("zero_pixels_are_background")=true,py::arg("neighborhood_connectivity")=8,py::arg("connected_if_both_not_zero")=false); docs = diff --git a/tools/python/src/image2.cpp b/tools/python/src/image2.cpp index 2cb53820b..a65666dd5 100644 --- a/tools/python/src/image2.cpp +++ b/tools/python/src/image2.cpp @@ -940,6 +940,20 @@ py::array py_tile_images ( // ---------------------------------------------------------------------------------------- +template +py::array_t py_get_histogram ( + const numpy_image& img, + size_t hist_size +) +{ + matrix hist; + get_histogram(img,hist,hist_size); + + return numpy_image(std::move(hist)).squeeze(); +} + +// ---------------------------------------------------------------------------------------- + void bind_image_classes2(py::module& m) { @@ -960,6 +974,27 @@ void bind_image_classes2(py::module& m) register_extract_image_chip(m); + m.def("get_histogram", &py_get_histogram, py::arg("img"), py::arg("hist_size")); + m.def("get_histogram", &py_get_histogram, py::arg("img"), py::arg("hist_size")); + m.def("get_histogram", &py_get_histogram, py::arg("img"), py::arg("hist_size")); + m.def("get_histogram", &py_get_histogram, py::arg("img"), py::arg("hist_size"), +"ensures \n\ + - Returns a numpy array, HIST, that contains a histogram of the pixels in img. \n\ + In particular, we will have: \n\ + - len(HIST) == hist_size \n\ + - for all valid i: \n\ + - HIST[i] == the number of times a pixel with intensity i appears in img." + /*! + ensures + - Returns a numpy array, HIST, that contains a histogram of the pixels in img. + In particular, we will have: + - len(HIST) == hist_size + - for all valid i: + - HIST[i] == the number of times a pixel with intensity i appears in img. + !*/ + ); + + m.def("tile_images", py_tile_images, py::arg("images"), "requires \n\ - images is a list of numpy arrays that can be interpreted as images. They \n\