Commit 5f16fde6 authored by David GEISSBUHLER's avatar David GEISSBUHLER

added modified c++ algorithm

parent 1c6e8ce0
......@@ -5,6 +5,7 @@ from .galbally_iqm_features import compute_quality_features
from .msu_iqa_features import compute_msu_iqa_features
from ._library import remove_highlights
from ._library_orig import remove_highlights_orig
def get_config():
......
......@@ -9,13 +9,12 @@
#include <bob.extension/documentation.h>
// declare C++ functions
void remove_highlights_orig( blitz::Array<float ,3> &img,
blitz::Array<float ,3> &diff,
blitz::Array<float ,3> &sfi,
blitz::Array<float ,3> &residue,
float epsilon);
// declare C++ function
void remove_highlights( blitz::Array<float ,3> &img,
blitz::Array<float ,3> &diff,
blitz::Array<float ,3> &sfi,
blitz::Array<float ,3> &residue,
float epsilon);
// declare the function
static PyObject* PyRemoveHighlights(PyObject*, PyObject* args, PyObject* kwargs) {
......@@ -26,7 +25,7 @@ static PyObject* PyRemoveHighlights(PyObject*, PyObject* args, PyObject* kwargs)
static char** kwlist = const_cast<char**>(const_kwlist);
PyBlitzArrayObject* array;
double epsilon = 0.5f;
double epsilon = 0.5f;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|d", kwlist,
&PyBlitzArray_Converter, &array,
......@@ -55,7 +54,7 @@ static PyObject* PyRemoveHighlights(PyObject*, PyObject* args, PyObject* kwargs)
speckle_img = 0;
// call the C++ function
remove_highlights_orig(img, diffuse_img, speckle_free_img, speckle_img, (float)epsilon);
remove_highlights(img, diffuse_img, speckle_free_img, speckle_img, (float)epsilon);
// convert the blitz array back to numpy and return it
PyObject *ret_tuple = PyTuple_New(3);
......
// include directly and indirectly dependent libraries
#ifdef NO_IMPORT_ARRAY
#undef NO_IMPORT_ARRAY
#endif
#include <bob.blitz/cppapi.h>
#include <bob.blitz/cleanup.h>
#include <bob.extension/documentation.h>
// declare C++ function
void remove_highlights_orig( blitz::Array<float ,3> &img,
blitz::Array<float ,3> &diff,
blitz::Array<float ,3> &sfi,
blitz::Array<float ,3> &residue,
float epsilon);
// declare the function
static PyObject* PyRemoveHighlightsOrig(PyObject*, PyObject* args, PyObject* kwargs) {
BOB_TRY
static const char* const_kwlist[] = {"array", "startEps", 0};
static char** kwlist = const_cast<char**>(const_kwlist);
PyBlitzArrayObject* array;
double epsilon = 0.5f;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&|d", kwlist,
&PyBlitzArray_Converter, &array,
&epsilon)) return 0;
// check that the array has the expected properties
if (array->type_num != NPY_FLOAT32|| array->ndim != 3){
PyErr_Format(PyExc_TypeError,
"remove_highlights : Only 3D arrays of type float32 are allowed");
return 0;
}
// extract the actual blitz array from the Python type
blitz::Array<float ,3> img = *PyBlitzArrayCxx_AsBlitz<float , 3>(array);
// results
int dim_x = img.shape()[2];
int dim_y = img.shape()[1];
blitz::Array<float ,3> diffuse_img(3, dim_y, dim_x);
blitz::Array<float ,3> speckle_free_img(3, dim_y, dim_x);
blitz::Array<float ,3> speckle_img(3, dim_y, dim_x);
diffuse_img = 0;
speckle_free_img = 0;
speckle_img = 0;
// call the C++ function
remove_highlights_orig(img, diffuse_img, speckle_free_img, speckle_img, (float)epsilon);
// convert the blitz array back to numpy and return it
PyObject *ret_tuple = PyTuple_New(3);
PyTuple_SetItem(ret_tuple, 0, PyBlitzArrayCxx_AsNumpy(speckle_free_img));
PyTuple_SetItem(ret_tuple, 1, PyBlitzArrayCxx_AsNumpy(diffuse_img));
PyTuple_SetItem(ret_tuple, 2, PyBlitzArrayCxx_AsNumpy(speckle_img));
return ret_tuple;
// handle exceptions that occurred in this function
BOB_CATCH_FUNCTION("remove_highlights_orig", 0)
}
//////////////////////////////////////////////////////////////////////////
/////// Python module declaration ////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// module-wide methods
static PyMethodDef module_methods[] = {
{
"remove_highlights_orig",
(PyCFunction)PyRemoveHighlightsOrig,
METH_VARARGS|METH_KEYWORDS,
"remove_highlights [doc]"
},
{NULL} // Sentinel
};
// module documentation
PyDoc_STRVAR(module_docstr, "Exemplary Python Bindings");
// module definition
#if PY_VERSION_HEX >= 0x03000000
static PyModuleDef module_definition = {
PyModuleDef_HEAD_INIT,
BOB_EXT_MODULE_NAME,
module_docstr,
-1,
module_methods,
0, 0, 0, 0
};
#endif
// create the module
static PyObject* create_module (void) {
# if PY_VERSION_HEX >= 0x03000000
PyObject* module = PyModule_Create(&module_definition);
auto module_ = make_xsafe(module);
const char* ret = "O";
# else
PyObject* module = Py_InitModule3(BOB_EXT_MODULE_NAME, module_methods, module_docstr);
const char* ret = "N";
# endif
if (!module) return 0;
if (PyModule_AddStringConstant(module, "__version__", BOB_EXT_MODULE_VERSION) < 0) return 0;
/* imports bob.blitz C-API + dependencies */
if (import_bob_blitz() < 0) return 0;
return Py_BuildValue(ret, module);
}
PyMODINIT_FUNC BOB_EXT_ENTRY_NAME (void) {
# if PY_VERSION_HEX >= 0x03000000
return
# endif
create_module();
}
......@@ -13,7 +13,7 @@ import argparse
import bob.io.base
import numpy as np
from bob.ip.qualitymeasure import remove_highlights
from bob.ip.qualitymeasure import remove_highlights_orig
def main(command_line_parameters=None):
"""Remove the specular component of the input image and write result to
......@@ -51,7 +51,7 @@ def main(command_line_parameters=None):
# 2. compute
print("Extracting diffuse component...")
sfi, diff, residue = remove_highlights(img.astype(np.float32), 0.5)
sfi, diff, residue = remove_highlights_orig(img.astype(np.float32), 0.5)
# 1. save output image
print("Saving output file: %s" % args.outImg)
......
This diff is collapsed.
......@@ -58,7 +58,7 @@ setup(
# list of files compiled into this extension
[
# the pure C++ code
"bob/ip/qualitymeasure/tan_specular_highlights_orig.cpp",
"bob/ip/qualitymeasure/tan_specular_highlights.cpp",
# the Python bindings
"bob/ip/qualitymeasure/main.cpp",
],
......@@ -66,6 +66,20 @@ setup(
version = version,
bob_packages = bob_packages,
),
# The second extension contains the actual C++ code and the Python bindings
Extension("bob.ip.qualitymeasure._library_orig",
# list of files compiled into this extension
[
# the pure C++ code
"bob/ip/qualitymeasure/tan_specular_highlights_orig.cpp",
# the Python bindings
"bob/ip/qualitymeasure/main_orig.cpp",
],
# additional parameters, see Extension documentation
version = version,
bob_packages = bob_packages,
),
],
# Important! We need to tell setuptools that we want the extension to be
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment