Commit bdf420a8 authored by David GEISSBUHLER's avatar David GEISSBUHLER

removed unused code variant.

parent 6b5ed065
......@@ -5,7 +5,6 @@ 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
from . import tan_specular_highlights as tsh
......
......@@ -2,28 +2,31 @@
* @author David Geissbuhler <andre.anjos@idiap.ch>
* @date Tue 27 Jun 15:54:00 2016
*
* Original version of the specular highlights removal code by Robby T. Tan
* Modified version of the specular highlights removal code by Robby T. Tan
* reference:
* "separating reflection components of textured surfaces using a single image"
* by Robby T. Tan, Katsushi Ikeuchi,
* IEEE Transactions on Pattern Analysis and Machine Intelligence (PAMI),
* 27(2), pp.179-193, February, 2005
*
* This is the original implementation based on the C++ code provided by Prof.
* Robby Tan but using Blitz++ arrays:
* http://tanrobby.github.io/code.html#
* http://tanrobby.github.io/code/highlight.zip
*
* This is a modified implementation based on the C++ code provided by Prof.
* Robby Tan but using Blitz++ arrays and with a modification that also
* ignores pixels marked G_DIFFUSE. This leads to a smaller number of
* iterations per epsilon value, while producing the similar results.
*
*/
#include <blitz/array.h>
#include <cmath>
#define SPECULARX 10
#define SPECULARY 11
#define DIFFUSE 12
#define BOUNDARY 13
#define NOISE 14
#define CAMERA_DARK 15
#define NOISE 14
#define CAMERA_DARK 15
void specular_free_image( blitz::Array<float ,3> &src,
blitz::Array<int,2> &src_i,
......@@ -42,11 +45,11 @@ int init( blitz::Array<float ,3> &src,
int reset_labels( blitz::Array<int,2> &src_i);
// the main function to remove highlights from a single image
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)
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)
{
// flags
int dim_x = img.shape()[2];
......@@ -160,11 +163,13 @@ void specular_free_image( blitz::Array<float ,3> &src,
}
//perform the specular-to-diffuse mechanism
float c = max_chroma(r,g,b);
float numr = max(r,g,b) * (3.0f * c - 1.0f);
float denm = c * lambdaConst;
float dI = numr / denm;
float dI;
if(denm == 0) dI = 0;
else dI = numr / denm;
float sI = (tot(r,g,b) - dI)/3.0f;
......@@ -184,7 +189,6 @@ void specular_free_image( blitz::Array<float ,3> &src,
sfi(0,y,x) = dr;
sfi(1,y,x) = dg;
sfi(2,y,x) = db;
}
}
......@@ -201,26 +205,34 @@ inline int specular_2_diffuse(int y, int x, blitz::Array<float ,3> &iro,
float numr = (m*(3.0f*c - 1.0f));
float denm = (c*(3.0f*maxChroma - 1.0f));
float dI = numr / denm;
if(fabs(denm) > 0.000000001)
{
float dI = numr / denm;
float sI = (t - dI)/3.0f;
float sI = (t - dI)/3.0f;
float nr = (iro(0,y,x) - sI);
float ng = (iro(1,y,x) - sI);
float nb = (iro(2,y,x) - sI);
float nr = (iro(0,y,x) - sI);
float ng = (iro(1,y,x) - sI);
float nb = (iro(2,y,x) - sI);
if(nr<=0 || ng<=0 || nb<=0)
{
iro_i(y,x)=NOISE;
return 1;
if(nr<=0 || ng<=0 || nb<=0)
{
iro_i(y,x)=NOISE;
return 1;
}
else
{
iro(0,y,x) = nr;
iro(1,y,x) = ng;
iro(2,y,x) = nb;
return 0;
}
}
else
{
iro(0,y,x) = nr;
iro(1,y,x) = ng;
iro(2,y,x) = nb;
return 0;
iro_i(y,x)=NOISE;
return 1;
}
}
......@@ -378,6 +390,7 @@ int init( blitz::Array<float ,3> &src,
case BOUNDARY:
case NOISE:
case CAMERA_DARK:
case DIFFUSE:
continue;
break;
}
......@@ -403,7 +416,7 @@ int init( blitz::Array<float ,3> &src,
dlogy=fabs(dlogy);
// specular in the x direction
if(dlogx > epsilon)
if(dlogx > epsilon || std::isinf(dlog_src_x) || std::isinf(dlog_sfi_x))
{
src_i(y,x) = SPECULARX;
count++;
......@@ -411,7 +424,7 @@ int init( blitz::Array<float ,3> &src,
}
//specular in the y direction
if(dlogy > epsilon)
if(dlogy > epsilon || std::isinf(dlog_src_y) || std::isinf(dlog_sfi_y))
{
src_i(y,x)= SPECULARY;
count++;
......
// 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();
}
......@@ -2,31 +2,28 @@
* @author David Geissbuhler <andre.anjos@idiap.ch>
* @date Tue 27 Jun 15:54:00 2016
*
* Modified version of the specular highlights removal code by Robby T. Tan
* Original version of the specular highlights removal code by Robby T. Tan
* reference:
* "separating reflection components of textured surfaces using a single image"
* by Robby T. Tan, Katsushi Ikeuchi,
* IEEE Transactions on Pattern Analysis and Machine Intelligence (PAMI),
* 27(2), pp.179-193, February, 2005
*
* This is the original implementation based on the C++ code provided by Prof.
* Robby Tan but using Blitz++ arrays:
* http://tanrobby.github.io/code.html#
* http://tanrobby.github.io/code/highlight.zip
*
* This is a modified implementation based on the C++ code provided by Prof.
* Robby Tan but using Blitz++ arrays and with a modification that also
* ignores pixels marked G_DIFFUSE. This leads to a smaller number of
* iterations per epsilon value, while producing the similar results.
*
*/
#include <blitz/array.h>
#include <cmath>
#define SPECULARX 10
#define SPECULARY 11
#define DIFFUSE 12
#define BOUNDARY 13
#define NOISE 14
#define CAMERA_DARK 15
#define NOISE 14
#define CAMERA_DARK 15
void specular_free_image( blitz::Array<float ,3> &src,
blitz::Array<int,2> &src_i,
......@@ -163,13 +160,11 @@ void specular_free_image( blitz::Array<float ,3> &src,
}
//perform the specular-to-diffuse mechanism
float c = max_chroma(r,g,b);
float numr = max(r,g,b) * (3.0f * c - 1.0f);
float denm = c * lambdaConst;
float dI;
if(denm == 0) dI = 0;
else dI = numr / denm;
float dI = numr / denm;
float sI = (tot(r,g,b) - dI)/3.0f;
......@@ -189,6 +184,7 @@ void specular_free_image( blitz::Array<float ,3> &src,
sfi(0,y,x) = dr;
sfi(1,y,x) = dg;
sfi(2,y,x) = db;
}
}
......@@ -205,35 +201,27 @@ inline int specular_2_diffuse(int y, int x, blitz::Array<float ,3> &iro,
float numr = (m*(3.0f*c - 1.0f));
float denm = (c*(3.0f*maxChroma - 1.0f));
if(fabs(denm) > 0.000000001)
{
float dI = numr / denm;
float dI = numr / denm;
float sI = (t - dI)/3.0f;
float sI = (t - dI)/3.0f;
float nr = (iro(0,y,x) - sI);
float ng = (iro(1,y,x) - sI);
float nb = (iro(2,y,x) - sI);
float nr = (iro(0,y,x) - sI);
float ng = (iro(1,y,x) - sI);
float nb = (iro(2,y,x) - sI);
if(nr<=0 || ng<=0 || nb<=0)
{
iro_i(y,x)=NOISE;
return 1;
}
else
{
iro(0,y,x) = nr;
iro(1,y,x) = ng;
iro(2,y,x) = nb;
return 0;
}
}
else
if(nr<=0 || ng<=0 || nb<=0)
{
iro_i(y,x)=NOISE;
return 1;
}
else
{
iro(0,y,x) = nr;
iro(1,y,x) = ng;
iro(2,y,x) = nb;
return 0;
}
}
// specular reduction mechanism
......@@ -390,7 +378,6 @@ int init( blitz::Array<float ,3> &src,
case BOUNDARY:
case NOISE:
case CAMERA_DARK:
case DIFFUSE:
continue;
break;
}
......@@ -416,7 +403,7 @@ int init( blitz::Array<float ,3> &src,
dlogy=fabs(dlogy);
// specular in the x direction
if(dlogx > epsilon || std::isinf(dlog_src_x) || std::isinf(dlog_sfi_x))
if(dlogx > epsilon)
{
src_i(y,x) = SPECULARX;
count++;
......@@ -424,7 +411,7 @@ int init( blitz::Array<float ,3> &src,
}
//specular in the y direction
if(dlogy > epsilon || std::isinf(dlog_src_y) || std::isinf(dlog_sfi_y))
if(dlogy > epsilon)
{
src_i(y,x)= SPECULARY;
count++;
......
......@@ -19,7 +19,7 @@ from . import galbally_iqm_features as iqm
from . import msu_iqa_features as iqa
from bob.io import image
from ._library_orig import remove_highlights_orig
from ._library import remove_highlights
REF_VIDEO_FILE = 'real_client001_android_SD_scene01.mp4'
......@@ -120,8 +120,8 @@ def test_remove_highlights_orig_integrity():
img2 = image.load(F('toys.ppm'))
# compute
sfi1, diff1, residue1 = remove_highlights_orig(img1.astype(np.float32), 0.5)
sfi2, diff2, residue2 = remove_highlights_orig(img2.astype(np.float32), 0.5)
sfi1, diff1, residue1 = remove_highlights(img1.astype(np.float32), 0.5)
sfi2, diff2, residue2 = remove_highlights(img2.astype(np.float32), 0.5)
#speckleImg[np.where(np.isinf(speckleImg))] = 0
#speckleImg[np.where(np.isnan(speckleImg))] = 0
......
......@@ -66,20 +66,6 @@ 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