Generated by Cython 0.27.3
Yellow lines hint at Python interaction.
Click on a line that starts with a "+
" to see the C code that Cython generated for it.
Raw output: QF_utilities.c
+001: #cython: boundscheck=False, wraparound=False, nonecheck=False
__pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+002: __author__ = 'Jiranun.J'
if (PyDict_SetItem(__pyx_d, __pyx_n_s_author, __pyx_kp_s_Jiranun_J) < 0) __PYX_ERR(0, 2, __pyx_L1_error)
+003: import numpy as np
__pyx_t_1 = __Pyx_Import(__pyx_n_s_numpy, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_np, __pyx_t_1) < 0) __PYX_ERR(0, 3, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
004: cimport numpy as np
005: cimport cython
006: from libc.math cimport sqrt
007: from libc.math cimport exp
008:
009: @cython.boundscheck(False)
010: @cython.wraparound(False)
011:
012: #
013: # "ctypedef" assigns a corresponding compile-time type to np.uint8_t. For
014: # every type in the np module there's a corresponding compile-time
015: # type with a _t-suffix.
+016: cpdef float distance(int x1, int y1, int x2, int y2):
static PyObject *__pyx_pw_12QF_utilities_1distance(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static float __pyx_f_12QF_utilities_distance(int __pyx_v_x1, int __pyx_v_y1, int __pyx_v_x2, int __pyx_v_y2, CYTHON_UNUSED int __pyx_skip_dispatch) { float __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("distance", 0); /* … */ /* function exit code */ __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_pw_12QF_utilities_1distance(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyObject *__pyx_pw_12QF_utilities_1distance(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { int __pyx_v_x1; int __pyx_v_y1; int __pyx_v_x2; int __pyx_v_y2; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("distance (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_x1,&__pyx_n_s_y1,&__pyx_n_s_x2,&__pyx_n_s_y2,0}; PyObject* values[4] = {0,0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); CYTHON_FALLTHROUGH; case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_x1)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_y1)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("distance", 1, 4, 4, 1); __PYX_ERR(0, 16, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_x2)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("distance", 1, 4, 4, 2); __PYX_ERR(0, 16, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 3: if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_y2)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("distance", 1, 4, 4, 3); __PYX_ERR(0, 16, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "distance") < 0)) __PYX_ERR(0, 16, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 4) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); values[2] = PyTuple_GET_ITEM(__pyx_args, 2); values[3] = PyTuple_GET_ITEM(__pyx_args, 3); } __pyx_v_x1 = __Pyx_PyInt_As_int(values[0]); if (unlikely((__pyx_v_x1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 16, __pyx_L3_error) __pyx_v_y1 = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_y1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 16, __pyx_L3_error) __pyx_v_x2 = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_x2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 16, __pyx_L3_error) __pyx_v_y2 = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_y2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 16, __pyx_L3_error) } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("distance", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 16, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("QF_utilities.distance", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_12QF_utilities_distance(__pyx_self, __pyx_v_x1, __pyx_v_y1, __pyx_v_x2, __pyx_v_y2); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_12QF_utilities_distance(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_x1, int __pyx_v_y1, int __pyx_v_x2, int __pyx_v_y2) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("distance", 0); __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyFloat_FromDouble(__pyx_f_12QF_utilities_distance(__pyx_v_x1, __pyx_v_y1, __pyx_v_x2, __pyx_v_y2, 0)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 16, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("QF_utilities.distance", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
+017: return sqrt((x1-x2)**2+(y1-y2)**2)
__pyx_r = sqrt((__Pyx_pow_long(((long)(__pyx_v_x1 - __pyx_v_x2)), 2) + __Pyx_pow_long(((long)(__pyx_v_y1 - __pyx_v_y2)), 2))); goto __pyx_L0;
018:
019:
+020: def get_avg_fold_int16(np.ndarray[np.uint16_t, ndim=3] quadrants, int nQuadrant, int fold_height, int fold_width, double threshold):
/* Python wrapper */ static PyObject *__pyx_pw_12QF_utilities_3get_avg_fold_int16(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyMethodDef __pyx_mdef_12QF_utilities_3get_avg_fold_int16 = {"get_avg_fold_int16", (PyCFunction)__pyx_pw_12QF_utilities_3get_avg_fold_int16, METH_VARARGS|METH_KEYWORDS, 0}; static PyObject *__pyx_pw_12QF_utilities_3get_avg_fold_int16(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyArrayObject *__pyx_v_quadrants = 0; int __pyx_v_nQuadrant; int __pyx_v_fold_height; int __pyx_v_fold_width; double __pyx_v_threshold; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("get_avg_fold_int16 (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_quadrants,&__pyx_n_s_nQuadrant,&__pyx_n_s_fold_height,&__pyx_n_s_fold_width,&__pyx_n_s_threshold,0}; PyObject* values[5] = {0,0,0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); CYTHON_FALLTHROUGH; case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); CYTHON_FALLTHROUGH; case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_quadrants)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_nQuadrant)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("get_avg_fold_int16", 1, 5, 5, 1); __PYX_ERR(0, 20, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_fold_height)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("get_avg_fold_int16", 1, 5, 5, 2); __PYX_ERR(0, 20, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 3: if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_fold_width)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("get_avg_fold_int16", 1, 5, 5, 3); __PYX_ERR(0, 20, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 4: if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_threshold)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("get_avg_fold_int16", 1, 5, 5, 4); __PYX_ERR(0, 20, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_avg_fold_int16") < 0)) __PYX_ERR(0, 20, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 5) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); values[2] = PyTuple_GET_ITEM(__pyx_args, 2); values[3] = PyTuple_GET_ITEM(__pyx_args, 3); values[4] = PyTuple_GET_ITEM(__pyx_args, 4); } __pyx_v_quadrants = ((PyArrayObject *)values[0]); __pyx_v_nQuadrant = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_nQuadrant == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 20, __pyx_L3_error) __pyx_v_fold_height = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_fold_height == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 20, __pyx_L3_error) __pyx_v_fold_width = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_fold_width == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 20, __pyx_L3_error) __pyx_v_threshold = __pyx_PyFloat_AsDouble(values[4]); if (unlikely((__pyx_v_threshold == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 20, __pyx_L3_error) } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("get_avg_fold_int16", 1, 5, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 20, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("QF_utilities.get_avg_fold_int16", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_quadrants), __pyx_ptype_5numpy_ndarray, 1, "quadrants", 0))) __PYX_ERR(0, 20, __pyx_L1_error) __pyx_r = __pyx_pf_12QF_utilities_2get_avg_fold_int16(__pyx_self, __pyx_v_quadrants, __pyx_v_nQuadrant, __pyx_v_fold_height, __pyx_v_fold_width, __pyx_v_threshold); /* function exit code */ goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_12QF_utilities_2get_avg_fold_int16(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_quadrants, int __pyx_v_nQuadrant, int __pyx_v_fold_height, int __pyx_v_fold_width, double __pyx_v_threshold) { PyArrayObject *__pyx_v_result = 0; Py_ssize_t __pyx_v_x; Py_ssize_t __pyx_v_y; Py_ssize_t __pyx_v_n_fold; Py_ssize_t __pyx_v_i; double __pyx_v_sum_val; PyArrayObject *__pyx_v_fold = 0; __Pyx_LocalBuf_ND __pyx_pybuffernd_fold; __Pyx_Buffer __pyx_pybuffer_fold; __Pyx_LocalBuf_ND __pyx_pybuffernd_quadrants; __Pyx_Buffer __pyx_pybuffer_quadrants; __Pyx_LocalBuf_ND __pyx_pybuffernd_result; __Pyx_Buffer __pyx_pybuffer_result; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("get_avg_fold_int16", 0); __pyx_pybuffer_result.pybuffer.buf = NULL; __pyx_pybuffer_result.refcount = 0; __pyx_pybuffernd_result.data = NULL; __pyx_pybuffernd_result.rcbuffer = &__pyx_pybuffer_result; __pyx_pybuffer_fold.pybuffer.buf = NULL; __pyx_pybuffer_fold.refcount = 0; __pyx_pybuffernd_fold.data = NULL; __pyx_pybuffernd_fold.rcbuffer = &__pyx_pybuffer_fold; __pyx_pybuffer_quadrants.pybuffer.buf = NULL; __pyx_pybuffer_quadrants.refcount = 0; __pyx_pybuffernd_quadrants.data = NULL; __pyx_pybuffernd_quadrants.rcbuffer = &__pyx_pybuffer_quadrants; { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_quadrants.rcbuffer->pybuffer, (PyObject*)__pyx_v_quadrants, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint16_t, PyBUF_FORMAT| PyBUF_STRIDES, 3, 0, __pyx_stack) == -1)) __PYX_ERR(0, 20, __pyx_L1_error) } __pyx_pybuffernd_quadrants.diminfo[0].strides = __pyx_pybuffernd_quadrants.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_quadrants.diminfo[0].shape = __pyx_pybuffernd_quadrants.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_quadrants.diminfo[1].strides = __pyx_pybuffernd_quadrants.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_quadrants.diminfo[1].shape = __pyx_pybuffernd_quadrants.rcbuffer->pybuffer.shape[1]; __pyx_pybuffernd_quadrants.diminfo[2].strides = __pyx_pybuffernd_quadrants.rcbuffer->pybuffer.strides[2]; __pyx_pybuffernd_quadrants.diminfo[2].shape = __pyx_pybuffernd_quadrants.rcbuffer->pybuffer.shape[2]; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; __Pyx_PyThreadState_declare __Pyx_PyThreadState_assign __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fold.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_quadrants.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_result.rcbuffer->pybuffer); __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} __Pyx_AddTraceback("QF_utilities.get_avg_fold_int16", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; goto __pyx_L2; __pyx_L0:; __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fold.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_quadrants.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_result.rcbuffer->pybuffer); __pyx_L2:; __Pyx_XDECREF((PyObject *)__pyx_v_result); __Pyx_XDECREF((PyObject *)__pyx_v_fold); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_tuple__10 = PyTuple_Pack(12, __pyx_n_s_quadrants, __pyx_n_s_nQuadrant, __pyx_n_s_fold_height, __pyx_n_s_fold_width, __pyx_n_s_threshold, __pyx_n_s_result, __pyx_n_s_x, __pyx_n_s_y, __pyx_n_s_n_fold, __pyx_n_s_i, __pyx_n_s_sum_val, __pyx_n_s_fold); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(0, 20, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__10); __Pyx_GIVEREF(__pyx_tuple__10); /* … */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_12QF_utilities_3get_avg_fold_int16, NULL, __pyx_n_s_QF_utilities); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 20, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_avg_fold_int16, __pyx_t_1) < 0) __PYX_ERR(0, 20, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_codeobj__11 = (PyObject*)__Pyx_PyCode_New(5, 0, 12, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__10, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_QF_utilities_pyx, __pyx_n_s_get_avg_fold_int16, 20, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__11)) __PYX_ERR(0, 20, __pyx_L1_error)
+021: cdef np.ndarray[double, ndim=2] result = np.zeros((fold_height, fold_width))
__pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 21, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_zeros); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 21, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_fold_height); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 21, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_fold_width); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 21, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 21, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_4); __pyx_t_2 = 0; __pyx_t_4 = 0; __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); if (likely(__pyx_t_4)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_3, function); } } if (!__pyx_t_4) { __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 21, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_1); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_5}; __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 21, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } else #endif #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_5}; __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 21, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } else #endif { __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 21, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4); __pyx_t_4 = NULL; __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_t_5); __pyx_t_5 = 0; __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 21, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 21, __pyx_L1_error) __pyx_t_6 = ((PyArrayObject *)__pyx_t_1); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_result.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_double, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) { __pyx_v_result = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_result.rcbuffer->pybuffer.buf = NULL; __PYX_ERR(0, 21, __pyx_L1_error) } else {__pyx_pybuffernd_result.diminfo[0].strides = __pyx_pybuffernd_result.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_result.diminfo[0].shape = __pyx_pybuffernd_result.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_result.diminfo[1].strides = __pyx_pybuffernd_result.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_result.diminfo[1].shape = __pyx_pybuffernd_result.rcbuffer->pybuffer.shape[1]; } } __pyx_t_6 = 0; __pyx_v_result = ((PyArrayObject *)__pyx_t_1); __pyx_t_1 = 0;
022: cdef Py_ssize_t x, y, n_fold, i
023: cdef double sum_val
024: cdef np.ndarray[np.uint16_t, ndim=2] fold
025:
026: # cdef int end = center_y + box_width
+027: if nQuadrant > 0:
__pyx_t_7 = ((__pyx_v_nQuadrant > 0) != 0); if (__pyx_t_7) { /* … */ }
+028: for x in range(fold_width):
__pyx_t_8 = __pyx_v_fold_width; for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_8; __pyx_t_9+=1) { __pyx_v_x = __pyx_t_9;
+029: for y in range(fold_height):
__pyx_t_10 = __pyx_v_fold_height; for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_10; __pyx_t_11+=1) { __pyx_v_y = __pyx_t_11;
+030: sum_val = 0.0
__pyx_v_sum_val = 0.0;
+031: n_fold = 0
__pyx_v_n_fold = 0;
+032: for i in range(nQuadrant):
__pyx_t_12 = __pyx_v_nQuadrant; for (__pyx_t_13 = 0; __pyx_t_13 < __pyx_t_12; __pyx_t_13+=1) { __pyx_v_i = __pyx_t_13;
+033: fold = quadrants[i]
__pyx_t_1 = __Pyx_GetItemInt(((PyObject *)__pyx_v_quadrants), __pyx_v_i, Py_ssize_t, 1, PyInt_FromSsize_t, 0, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 33, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 33, __pyx_L1_error) __pyx_t_14 = ((PyArrayObject *)__pyx_t_1); { __Pyx_BufFmt_StackElem __pyx_stack[1]; __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fold.rcbuffer->pybuffer); __pyx_t_15 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_fold.rcbuffer->pybuffer, (PyObject*)__pyx_t_14, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint16_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack); if (unlikely(__pyx_t_15 < 0)) { PyErr_Fetch(&__pyx_t_16, &__pyx_t_17, &__pyx_t_18); if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_fold.rcbuffer->pybuffer, (PyObject*)__pyx_v_fold, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint16_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) { Py_XDECREF(__pyx_t_16); Py_XDECREF(__pyx_t_17); Py_XDECREF(__pyx_t_18); __Pyx_RaiseBufferFallbackError(); } else { PyErr_Restore(__pyx_t_16, __pyx_t_17, __pyx_t_18); } __pyx_t_16 = __pyx_t_17 = __pyx_t_18 = 0; } __pyx_pybuffernd_fold.diminfo[0].strides = __pyx_pybuffernd_fold.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_fold.diminfo[0].shape = __pyx_pybuffernd_fold.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_fold.diminfo[1].strides = __pyx_pybuffernd_fold.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_fold.diminfo[1].shape = __pyx_pybuffernd_fold.rcbuffer->pybuffer.shape[1]; if (unlikely(__pyx_t_15 < 0)) __PYX_ERR(0, 33, __pyx_L1_error) } __pyx_t_14 = 0; __Pyx_XDECREF_SET(__pyx_v_fold, ((PyArrayObject *)__pyx_t_1)); __pyx_t_1 = 0;
+034: if fold[y,x] > threshold :
__pyx_t_19 = __pyx_v_y; __pyx_t_20 = __pyx_v_x; __pyx_t_7 = (((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_uint16_t *, __pyx_pybuffernd_fold.rcbuffer->pybuffer.buf, __pyx_t_19, __pyx_pybuffernd_fold.diminfo[0].strides, __pyx_t_20, __pyx_pybuffernd_fold.diminfo[1].strides)) > __pyx_v_threshold) != 0); if (__pyx_t_7) { /* … */ } }
+035: sum_val += fold[y,x]
__pyx_t_21 = __pyx_v_y; __pyx_t_22 = __pyx_v_x; __pyx_v_sum_val = (__pyx_v_sum_val + (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_uint16_t *, __pyx_pybuffernd_fold.rcbuffer->pybuffer.buf, __pyx_t_21, __pyx_pybuffernd_fold.diminfo[0].strides, __pyx_t_22, __pyx_pybuffernd_fold.diminfo[1].strides)));
+036: n_fold += 1
__pyx_v_n_fold = (__pyx_v_n_fold + 1);
+037: if n_fold == 0 :
__pyx_t_7 = ((__pyx_v_n_fold == 0) != 0); if (__pyx_t_7) { /* … */ goto __pyx_L11; }
+038: result[y,x] = 0
__pyx_t_23 = __pyx_v_y; __pyx_t_24 = __pyx_v_x; *__Pyx_BufPtrStrided2d(double *, __pyx_pybuffernd_result.rcbuffer->pybuffer.buf, __pyx_t_23, __pyx_pybuffernd_result.diminfo[0].strides, __pyx_t_24, __pyx_pybuffernd_result.diminfo[1].strides) = 0.0;
039: else:
+040: result[y,x] = sum_val/n_fold
/*else*/ { if (unlikely(__pyx_v_n_fold == 0)) { PyErr_SetString(PyExc_ZeroDivisionError, "float division"); __PYX_ERR(0, 40, __pyx_L1_error) } __pyx_t_25 = __pyx_v_y; __pyx_t_26 = __pyx_v_x; *__Pyx_BufPtrStrided2d(double *, __pyx_pybuffernd_result.rcbuffer->pybuffer.buf, __pyx_t_25, __pyx_pybuffernd_result.diminfo[0].strides, __pyx_t_26, __pyx_pybuffernd_result.diminfo[1].strides) = (__pyx_v_sum_val / __pyx_v_n_fold); } __pyx_L11:; } }
+041: return result
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_result)); __pyx_r = ((PyObject *)__pyx_v_result); goto __pyx_L0;
042:
+043: def get_avg_fold_int8(np.ndarray[np.uint8_t, ndim=3] quadrants, int nQuadrant, int fold_height, int fold_width, int threshold):
/* Python wrapper */ static PyObject *__pyx_pw_12QF_utilities_5get_avg_fold_int8(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyMethodDef __pyx_mdef_12QF_utilities_5get_avg_fold_int8 = {"get_avg_fold_int8", (PyCFunction)__pyx_pw_12QF_utilities_5get_avg_fold_int8, METH_VARARGS|METH_KEYWORDS, 0}; static PyObject *__pyx_pw_12QF_utilities_5get_avg_fold_int8(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyArrayObject *__pyx_v_quadrants = 0; int __pyx_v_nQuadrant; int __pyx_v_fold_height; int __pyx_v_fold_width; int __pyx_v_threshold; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("get_avg_fold_int8 (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_quadrants,&__pyx_n_s_nQuadrant,&__pyx_n_s_fold_height,&__pyx_n_s_fold_width,&__pyx_n_s_threshold,0}; PyObject* values[5] = {0,0,0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); CYTHON_FALLTHROUGH; case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); CYTHON_FALLTHROUGH; case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_quadrants)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_nQuadrant)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("get_avg_fold_int8", 1, 5, 5, 1); __PYX_ERR(0, 43, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_fold_height)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("get_avg_fold_int8", 1, 5, 5, 2); __PYX_ERR(0, 43, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 3: if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_fold_width)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("get_avg_fold_int8", 1, 5, 5, 3); __PYX_ERR(0, 43, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 4: if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_threshold)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("get_avg_fold_int8", 1, 5, 5, 4); __PYX_ERR(0, 43, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_avg_fold_int8") < 0)) __PYX_ERR(0, 43, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 5) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); values[2] = PyTuple_GET_ITEM(__pyx_args, 2); values[3] = PyTuple_GET_ITEM(__pyx_args, 3); values[4] = PyTuple_GET_ITEM(__pyx_args, 4); } __pyx_v_quadrants = ((PyArrayObject *)values[0]); __pyx_v_nQuadrant = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_nQuadrant == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 43, __pyx_L3_error) __pyx_v_fold_height = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_fold_height == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 43, __pyx_L3_error) __pyx_v_fold_width = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_fold_width == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 43, __pyx_L3_error) __pyx_v_threshold = __Pyx_PyInt_As_int(values[4]); if (unlikely((__pyx_v_threshold == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 43, __pyx_L3_error) } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("get_avg_fold_int8", 1, 5, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 43, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("QF_utilities.get_avg_fold_int8", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_quadrants), __pyx_ptype_5numpy_ndarray, 1, "quadrants", 0))) __PYX_ERR(0, 43, __pyx_L1_error) __pyx_r = __pyx_pf_12QF_utilities_4get_avg_fold_int8(__pyx_self, __pyx_v_quadrants, __pyx_v_nQuadrant, __pyx_v_fold_height, __pyx_v_fold_width, __pyx_v_threshold); /* function exit code */ goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_12QF_utilities_4get_avg_fold_int8(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_quadrants, int __pyx_v_nQuadrant, int __pyx_v_fold_height, int __pyx_v_fold_width, int __pyx_v_threshold) { PyArrayObject *__pyx_v_result = 0; Py_ssize_t __pyx_v_x; Py_ssize_t __pyx_v_y; Py_ssize_t __pyx_v_n_fold; Py_ssize_t __pyx_v_i; double __pyx_v_sum_val; PyArrayObject *__pyx_v_fold = 0; __Pyx_LocalBuf_ND __pyx_pybuffernd_fold; __Pyx_Buffer __pyx_pybuffer_fold; __Pyx_LocalBuf_ND __pyx_pybuffernd_quadrants; __Pyx_Buffer __pyx_pybuffer_quadrants; __Pyx_LocalBuf_ND __pyx_pybuffernd_result; __Pyx_Buffer __pyx_pybuffer_result; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("get_avg_fold_int8", 0); __pyx_pybuffer_result.pybuffer.buf = NULL; __pyx_pybuffer_result.refcount = 0; __pyx_pybuffernd_result.data = NULL; __pyx_pybuffernd_result.rcbuffer = &__pyx_pybuffer_result; __pyx_pybuffer_fold.pybuffer.buf = NULL; __pyx_pybuffer_fold.refcount = 0; __pyx_pybuffernd_fold.data = NULL; __pyx_pybuffernd_fold.rcbuffer = &__pyx_pybuffer_fold; __pyx_pybuffer_quadrants.pybuffer.buf = NULL; __pyx_pybuffer_quadrants.refcount = 0; __pyx_pybuffernd_quadrants.data = NULL; __pyx_pybuffernd_quadrants.rcbuffer = &__pyx_pybuffer_quadrants; { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_quadrants.rcbuffer->pybuffer, (PyObject*)__pyx_v_quadrants, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES, 3, 0, __pyx_stack) == -1)) __PYX_ERR(0, 43, __pyx_L1_error) } __pyx_pybuffernd_quadrants.diminfo[0].strides = __pyx_pybuffernd_quadrants.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_quadrants.diminfo[0].shape = __pyx_pybuffernd_quadrants.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_quadrants.diminfo[1].strides = __pyx_pybuffernd_quadrants.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_quadrants.diminfo[1].shape = __pyx_pybuffernd_quadrants.rcbuffer->pybuffer.shape[1]; __pyx_pybuffernd_quadrants.diminfo[2].strides = __pyx_pybuffernd_quadrants.rcbuffer->pybuffer.strides[2]; __pyx_pybuffernd_quadrants.diminfo[2].shape = __pyx_pybuffernd_quadrants.rcbuffer->pybuffer.shape[2]; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; __Pyx_PyThreadState_declare __Pyx_PyThreadState_assign __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fold.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_quadrants.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_result.rcbuffer->pybuffer); __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} __Pyx_AddTraceback("QF_utilities.get_avg_fold_int8", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; goto __pyx_L2; __pyx_L0:; __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fold.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_quadrants.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_result.rcbuffer->pybuffer); __pyx_L2:; __Pyx_XDECREF((PyObject *)__pyx_v_result); __Pyx_XDECREF((PyObject *)__pyx_v_fold); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_tuple__12 = PyTuple_Pack(12, __pyx_n_s_quadrants, __pyx_n_s_nQuadrant, __pyx_n_s_fold_height, __pyx_n_s_fold_width, __pyx_n_s_threshold, __pyx_n_s_result, __pyx_n_s_x, __pyx_n_s_y, __pyx_n_s_n_fold, __pyx_n_s_i, __pyx_n_s_sum_val, __pyx_n_s_fold); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(0, 43, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__12); __Pyx_GIVEREF(__pyx_tuple__12); /* … */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_12QF_utilities_5get_avg_fold_int8, NULL, __pyx_n_s_QF_utilities); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 43, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_avg_fold_int8, __pyx_t_1) < 0) __PYX_ERR(0, 43, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_codeobj__13 = (PyObject*)__Pyx_PyCode_New(5, 0, 12, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__12, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_QF_utilities_pyx, __pyx_n_s_get_avg_fold_int8, 43, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__13)) __PYX_ERR(0, 43, __pyx_L1_error)
+044: cdef np.ndarray[double, ndim=2] result = np.zeros((fold_height, fold_width))
__pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 44, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_zeros); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 44, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_fold_height); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 44, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_fold_width); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 44, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 44, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_4); __pyx_t_2 = 0; __pyx_t_4 = 0; __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); if (likely(__pyx_t_4)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_3, function); } } if (!__pyx_t_4) { __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 44, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_1); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_5}; __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 44, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } else #endif #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_5}; __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 44, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } else #endif { __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 44, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4); __pyx_t_4 = NULL; __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_t_5); __pyx_t_5 = 0; __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 44, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 44, __pyx_L1_error) __pyx_t_6 = ((PyArrayObject *)__pyx_t_1); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_result.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_double, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) { __pyx_v_result = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_result.rcbuffer->pybuffer.buf = NULL; __PYX_ERR(0, 44, __pyx_L1_error) } else {__pyx_pybuffernd_result.diminfo[0].strides = __pyx_pybuffernd_result.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_result.diminfo[0].shape = __pyx_pybuffernd_result.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_result.diminfo[1].strides = __pyx_pybuffernd_result.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_result.diminfo[1].shape = __pyx_pybuffernd_result.rcbuffer->pybuffer.shape[1]; } } __pyx_t_6 = 0; __pyx_v_result = ((PyArrayObject *)__pyx_t_1); __pyx_t_1 = 0;
045: cdef Py_ssize_t x, y, n_fold, i
046: cdef double sum_val
047: cdef np.ndarray[np.uint8_t, ndim=2] fold
048:
049: # cdef int end = center_y + box_width
+050: if nQuadrant > 0:
__pyx_t_7 = ((__pyx_v_nQuadrant > 0) != 0); if (__pyx_t_7) { /* … */ }
+051: for x in range(fold_width):
__pyx_t_8 = __pyx_v_fold_width; for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_8; __pyx_t_9+=1) { __pyx_v_x = __pyx_t_9;
+052: for y in range(fold_height):
__pyx_t_10 = __pyx_v_fold_height; for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_10; __pyx_t_11+=1) { __pyx_v_y = __pyx_t_11;
+053: sum_val = 0.0
__pyx_v_sum_val = 0.0;
+054: n_fold = 0
__pyx_v_n_fold = 0;
+055: for i in range(nQuadrant):
__pyx_t_12 = __pyx_v_nQuadrant; for (__pyx_t_13 = 0; __pyx_t_13 < __pyx_t_12; __pyx_t_13+=1) { __pyx_v_i = __pyx_t_13;
+056: fold = quadrants[i]
__pyx_t_1 = __Pyx_GetItemInt(((PyObject *)__pyx_v_quadrants), __pyx_v_i, Py_ssize_t, 1, PyInt_FromSsize_t, 0, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 56, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 56, __pyx_L1_error) __pyx_t_14 = ((PyArrayObject *)__pyx_t_1); { __Pyx_BufFmt_StackElem __pyx_stack[1]; __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fold.rcbuffer->pybuffer); __pyx_t_15 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_fold.rcbuffer->pybuffer, (PyObject*)__pyx_t_14, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack); if (unlikely(__pyx_t_15 < 0)) { PyErr_Fetch(&__pyx_t_16, &__pyx_t_17, &__pyx_t_18); if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_fold.rcbuffer->pybuffer, (PyObject*)__pyx_v_fold, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) { Py_XDECREF(__pyx_t_16); Py_XDECREF(__pyx_t_17); Py_XDECREF(__pyx_t_18); __Pyx_RaiseBufferFallbackError(); } else { PyErr_Restore(__pyx_t_16, __pyx_t_17, __pyx_t_18); } __pyx_t_16 = __pyx_t_17 = __pyx_t_18 = 0; } __pyx_pybuffernd_fold.diminfo[0].strides = __pyx_pybuffernd_fold.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_fold.diminfo[0].shape = __pyx_pybuffernd_fold.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_fold.diminfo[1].strides = __pyx_pybuffernd_fold.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_fold.diminfo[1].shape = __pyx_pybuffernd_fold.rcbuffer->pybuffer.shape[1]; if (unlikely(__pyx_t_15 < 0)) __PYX_ERR(0, 56, __pyx_L1_error) } __pyx_t_14 = 0; __Pyx_XDECREF_SET(__pyx_v_fold, ((PyArrayObject *)__pyx_t_1)); __pyx_t_1 = 0;
+057: if fold[y,x] > threshold :
__pyx_t_19 = __pyx_v_y; __pyx_t_20 = __pyx_v_x; __pyx_t_7 = (((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_fold.rcbuffer->pybuffer.buf, __pyx_t_19, __pyx_pybuffernd_fold.diminfo[0].strides, __pyx_t_20, __pyx_pybuffernd_fold.diminfo[1].strides)) > __pyx_v_threshold) != 0); if (__pyx_t_7) { /* … */ } }
+058: sum_val += fold[y,x]
__pyx_t_21 = __pyx_v_y; __pyx_t_22 = __pyx_v_x; __pyx_v_sum_val = (__pyx_v_sum_val + (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_fold.rcbuffer->pybuffer.buf, __pyx_t_21, __pyx_pybuffernd_fold.diminfo[0].strides, __pyx_t_22, __pyx_pybuffernd_fold.diminfo[1].strides)));
+059: n_fold += 1
__pyx_v_n_fold = (__pyx_v_n_fold + 1);
+060: if n_fold == 0 :
__pyx_t_7 = ((__pyx_v_n_fold == 0) != 0); if (__pyx_t_7) { /* … */ goto __pyx_L11; }
+061: result[y,x] = 0
__pyx_t_23 = __pyx_v_y; __pyx_t_24 = __pyx_v_x; *__Pyx_BufPtrStrided2d(double *, __pyx_pybuffernd_result.rcbuffer->pybuffer.buf, __pyx_t_23, __pyx_pybuffernd_result.diminfo[0].strides, __pyx_t_24, __pyx_pybuffernd_result.diminfo[1].strides) = 0.0;
062: else:
+063: result[y,x] = sum_val/n_fold
/*else*/ { if (unlikely(__pyx_v_n_fold == 0)) { PyErr_SetString(PyExc_ZeroDivisionError, "float division"); __PYX_ERR(0, 63, __pyx_L1_error) } __pyx_t_25 = __pyx_v_y; __pyx_t_26 = __pyx_v_x; *__Pyx_BufPtrStrided2d(double *, __pyx_pybuffernd_result.rcbuffer->pybuffer.buf, __pyx_t_25, __pyx_pybuffernd_result.diminfo[0].strides, __pyx_t_26, __pyx_pybuffernd_result.diminfo[1].strides) = (__pyx_v_sum_val / __pyx_v_n_fold); } __pyx_L11:; } }
+064: return result
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_result)); __pyx_r = ((PyObject *)__pyx_v_result); goto __pyx_L0;
065:
+066: def get_avg_fold_float32(np.ndarray[np.float32_t, ndim=3] quadrants, int nQuadrant, int fold_height, int fold_width, np.float32_t threshold):
/* Python wrapper */ static PyObject *__pyx_pw_12QF_utilities_7get_avg_fold_float32(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyMethodDef __pyx_mdef_12QF_utilities_7get_avg_fold_float32 = {"get_avg_fold_float32", (PyCFunction)__pyx_pw_12QF_utilities_7get_avg_fold_float32, METH_VARARGS|METH_KEYWORDS, 0}; static PyObject *__pyx_pw_12QF_utilities_7get_avg_fold_float32(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyArrayObject *__pyx_v_quadrants = 0; int __pyx_v_nQuadrant; int __pyx_v_fold_height; int __pyx_v_fold_width; __pyx_t_5numpy_float32_t __pyx_v_threshold; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("get_avg_fold_float32 (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_quadrants,&__pyx_n_s_nQuadrant,&__pyx_n_s_fold_height,&__pyx_n_s_fold_width,&__pyx_n_s_threshold,0}; PyObject* values[5] = {0,0,0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); CYTHON_FALLTHROUGH; case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); CYTHON_FALLTHROUGH; case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_quadrants)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_nQuadrant)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("get_avg_fold_float32", 1, 5, 5, 1); __PYX_ERR(0, 66, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_fold_height)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("get_avg_fold_float32", 1, 5, 5, 2); __PYX_ERR(0, 66, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 3: if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_fold_width)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("get_avg_fold_float32", 1, 5, 5, 3); __PYX_ERR(0, 66, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 4: if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_threshold)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("get_avg_fold_float32", 1, 5, 5, 4); __PYX_ERR(0, 66, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get_avg_fold_float32") < 0)) __PYX_ERR(0, 66, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 5) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); values[2] = PyTuple_GET_ITEM(__pyx_args, 2); values[3] = PyTuple_GET_ITEM(__pyx_args, 3); values[4] = PyTuple_GET_ITEM(__pyx_args, 4); } __pyx_v_quadrants = ((PyArrayObject *)values[0]); __pyx_v_nQuadrant = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_nQuadrant == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 66, __pyx_L3_error) __pyx_v_fold_height = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_fold_height == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 66, __pyx_L3_error) __pyx_v_fold_width = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_fold_width == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 66, __pyx_L3_error) __pyx_v_threshold = __pyx_PyFloat_AsFloat(values[4]); if (unlikely((__pyx_v_threshold == ((npy_float32)-1)) && PyErr_Occurred())) __PYX_ERR(0, 66, __pyx_L3_error) } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("get_avg_fold_float32", 1, 5, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 66, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("QF_utilities.get_avg_fold_float32", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_quadrants), __pyx_ptype_5numpy_ndarray, 1, "quadrants", 0))) __PYX_ERR(0, 66, __pyx_L1_error) __pyx_r = __pyx_pf_12QF_utilities_6get_avg_fold_float32(__pyx_self, __pyx_v_quadrants, __pyx_v_nQuadrant, __pyx_v_fold_height, __pyx_v_fold_width, __pyx_v_threshold); /* function exit code */ goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_12QF_utilities_6get_avg_fold_float32(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_quadrants, int __pyx_v_nQuadrant, int __pyx_v_fold_height, int __pyx_v_fold_width, __pyx_t_5numpy_float32_t __pyx_v_threshold) { PyArrayObject *__pyx_v_result = 0; Py_ssize_t __pyx_v_x; Py_ssize_t __pyx_v_y; Py_ssize_t __pyx_v_n_fold; Py_ssize_t __pyx_v_i; double __pyx_v_sum_val; PyArrayObject *__pyx_v_fold = 0; __Pyx_LocalBuf_ND __pyx_pybuffernd_fold; __Pyx_Buffer __pyx_pybuffer_fold; __Pyx_LocalBuf_ND __pyx_pybuffernd_quadrants; __Pyx_Buffer __pyx_pybuffer_quadrants; __Pyx_LocalBuf_ND __pyx_pybuffernd_result; __Pyx_Buffer __pyx_pybuffer_result; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("get_avg_fold_float32", 0); __pyx_pybuffer_result.pybuffer.buf = NULL; __pyx_pybuffer_result.refcount = 0; __pyx_pybuffernd_result.data = NULL; __pyx_pybuffernd_result.rcbuffer = &__pyx_pybuffer_result; __pyx_pybuffer_fold.pybuffer.buf = NULL; __pyx_pybuffer_fold.refcount = 0; __pyx_pybuffernd_fold.data = NULL; __pyx_pybuffernd_fold.rcbuffer = &__pyx_pybuffer_fold; __pyx_pybuffer_quadrants.pybuffer.buf = NULL; __pyx_pybuffer_quadrants.refcount = 0; __pyx_pybuffernd_quadrants.data = NULL; __pyx_pybuffernd_quadrants.rcbuffer = &__pyx_pybuffer_quadrants; { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_quadrants.rcbuffer->pybuffer, (PyObject*)__pyx_v_quadrants, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 3, 0, __pyx_stack) == -1)) __PYX_ERR(0, 66, __pyx_L1_error) } __pyx_pybuffernd_quadrants.diminfo[0].strides = __pyx_pybuffernd_quadrants.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_quadrants.diminfo[0].shape = __pyx_pybuffernd_quadrants.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_quadrants.diminfo[1].strides = __pyx_pybuffernd_quadrants.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_quadrants.diminfo[1].shape = __pyx_pybuffernd_quadrants.rcbuffer->pybuffer.shape[1]; __pyx_pybuffernd_quadrants.diminfo[2].strides = __pyx_pybuffernd_quadrants.rcbuffer->pybuffer.strides[2]; __pyx_pybuffernd_quadrants.diminfo[2].shape = __pyx_pybuffernd_quadrants.rcbuffer->pybuffer.shape[2]; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; __Pyx_PyThreadState_declare __Pyx_PyThreadState_assign __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fold.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_quadrants.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_result.rcbuffer->pybuffer); __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} __Pyx_AddTraceback("QF_utilities.get_avg_fold_float32", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; goto __pyx_L2; __pyx_L0:; __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fold.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_quadrants.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_result.rcbuffer->pybuffer); __pyx_L2:; __Pyx_XDECREF((PyObject *)__pyx_v_result); __Pyx_XDECREF((PyObject *)__pyx_v_fold); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_tuple__14 = PyTuple_Pack(12, __pyx_n_s_quadrants, __pyx_n_s_nQuadrant, __pyx_n_s_fold_height, __pyx_n_s_fold_width, __pyx_n_s_threshold, __pyx_n_s_result, __pyx_n_s_x, __pyx_n_s_y, __pyx_n_s_n_fold, __pyx_n_s_i, __pyx_n_s_sum_val, __pyx_n_s_fold); if (unlikely(!__pyx_tuple__14)) __PYX_ERR(0, 66, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__14); __Pyx_GIVEREF(__pyx_tuple__14); /* … */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_12QF_utilities_7get_avg_fold_float32, NULL, __pyx_n_s_QF_utilities); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 66, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_get_avg_fold_float32, __pyx_t_1) < 0) __PYX_ERR(0, 66, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_codeobj__15 = (PyObject*)__Pyx_PyCode_New(5, 0, 12, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__14, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_QF_utilities_pyx, __pyx_n_s_get_avg_fold_float32, 66, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__15)) __PYX_ERR(0, 66, __pyx_L1_error)
+067: cdef np.ndarray[double, ndim=2] result = np.zeros((fold_height, fold_width))
__pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 67, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_zeros); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 67, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_fold_height); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 67, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_fold_width); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 67, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 67, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_4); __pyx_t_2 = 0; __pyx_t_4 = 0; __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); if (likely(__pyx_t_4)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_3, function); } } if (!__pyx_t_4) { __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 67, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_1); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_5}; __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 67, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } else #endif #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_5}; __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 67, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } else #endif { __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 67, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4); __pyx_t_4 = NULL; __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_t_5); __pyx_t_5 = 0; __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 67, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 67, __pyx_L1_error) __pyx_t_6 = ((PyArrayObject *)__pyx_t_1); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_result.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_double, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) { __pyx_v_result = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_result.rcbuffer->pybuffer.buf = NULL; __PYX_ERR(0, 67, __pyx_L1_error) } else {__pyx_pybuffernd_result.diminfo[0].strides = __pyx_pybuffernd_result.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_result.diminfo[0].shape = __pyx_pybuffernd_result.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_result.diminfo[1].strides = __pyx_pybuffernd_result.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_result.diminfo[1].shape = __pyx_pybuffernd_result.rcbuffer->pybuffer.shape[1]; } } __pyx_t_6 = 0; __pyx_v_result = ((PyArrayObject *)__pyx_t_1); __pyx_t_1 = 0;
068: cdef Py_ssize_t x, y, n_fold, i
069: cdef double sum_val
070: cdef np.ndarray[np.float32_t, ndim=2] fold
071:
072: # cdef int end = center_y + box_width
+073: if nQuadrant > 0:
__pyx_t_7 = ((__pyx_v_nQuadrant > 0) != 0); if (__pyx_t_7) { /* … */ }
+074: for x in range(fold_width):
__pyx_t_8 = __pyx_v_fold_width; for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_8; __pyx_t_9+=1) { __pyx_v_x = __pyx_t_9;
+075: for y in range(fold_height):
__pyx_t_10 = __pyx_v_fold_height; for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_10; __pyx_t_11+=1) { __pyx_v_y = __pyx_t_11;
+076: sum_val = 0.0
__pyx_v_sum_val = 0.0;
+077: n_fold = 0
__pyx_v_n_fold = 0;
+078: for i in range(nQuadrant):
__pyx_t_12 = __pyx_v_nQuadrant; for (__pyx_t_13 = 0; __pyx_t_13 < __pyx_t_12; __pyx_t_13+=1) { __pyx_v_i = __pyx_t_13;
+079: fold = quadrants[i]
__pyx_t_1 = __Pyx_GetItemInt(((PyObject *)__pyx_v_quadrants), __pyx_v_i, Py_ssize_t, 1, PyInt_FromSsize_t, 0, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 79, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 79, __pyx_L1_error) __pyx_t_14 = ((PyArrayObject *)__pyx_t_1); { __Pyx_BufFmt_StackElem __pyx_stack[1]; __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fold.rcbuffer->pybuffer); __pyx_t_15 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_fold.rcbuffer->pybuffer, (PyObject*)__pyx_t_14, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack); if (unlikely(__pyx_t_15 < 0)) { PyErr_Fetch(&__pyx_t_16, &__pyx_t_17, &__pyx_t_18); if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_fold.rcbuffer->pybuffer, (PyObject*)__pyx_v_fold, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) { Py_XDECREF(__pyx_t_16); Py_XDECREF(__pyx_t_17); Py_XDECREF(__pyx_t_18); __Pyx_RaiseBufferFallbackError(); } else { PyErr_Restore(__pyx_t_16, __pyx_t_17, __pyx_t_18); } __pyx_t_16 = __pyx_t_17 = __pyx_t_18 = 0; } __pyx_pybuffernd_fold.diminfo[0].strides = __pyx_pybuffernd_fold.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_fold.diminfo[0].shape = __pyx_pybuffernd_fold.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_fold.diminfo[1].strides = __pyx_pybuffernd_fold.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_fold.diminfo[1].shape = __pyx_pybuffernd_fold.rcbuffer->pybuffer.shape[1]; if (unlikely(__pyx_t_15 < 0)) __PYX_ERR(0, 79, __pyx_L1_error) } __pyx_t_14 = 0; __Pyx_XDECREF_SET(__pyx_v_fold, ((PyArrayObject *)__pyx_t_1)); __pyx_t_1 = 0;
+080: if fold[y,x] > threshold :
__pyx_t_19 = __pyx_v_y; __pyx_t_20 = __pyx_v_x; __pyx_t_7 = (((*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_fold.rcbuffer->pybuffer.buf, __pyx_t_19, __pyx_pybuffernd_fold.diminfo[0].strides, __pyx_t_20, __pyx_pybuffernd_fold.diminfo[1].strides)) > __pyx_v_threshold) != 0); if (__pyx_t_7) { /* … */ } }
+081: sum_val += fold[y,x]
__pyx_t_21 = __pyx_v_y; __pyx_t_22 = __pyx_v_x; __pyx_v_sum_val = (__pyx_v_sum_val + (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_fold.rcbuffer->pybuffer.buf, __pyx_t_21, __pyx_pybuffernd_fold.diminfo[0].strides, __pyx_t_22, __pyx_pybuffernd_fold.diminfo[1].strides)));
+082: n_fold += 1
__pyx_v_n_fold = (__pyx_v_n_fold + 1);
+083: if n_fold == 0 :
__pyx_t_7 = ((__pyx_v_n_fold == 0) != 0); if (__pyx_t_7) { /* … */ goto __pyx_L11; }
+084: result[y,x] = 0
__pyx_t_23 = __pyx_v_y; __pyx_t_24 = __pyx_v_x; *__Pyx_BufPtrStrided2d(double *, __pyx_pybuffernd_result.rcbuffer->pybuffer.buf, __pyx_t_23, __pyx_pybuffernd_result.diminfo[0].strides, __pyx_t_24, __pyx_pybuffernd_result.diminfo[1].strides) = 0.0;
085: else:
+086: result[y,x] = sum_val/n_fold
/*else*/ { if (unlikely(__pyx_v_n_fold == 0)) { PyErr_SetString(PyExc_ZeroDivisionError, "float division"); __PYX_ERR(0, 86, __pyx_L1_error) } __pyx_t_25 = __pyx_v_y; __pyx_t_26 = __pyx_v_x; *__Pyx_BufPtrStrided2d(double *, __pyx_pybuffernd_result.rcbuffer->pybuffer.buf, __pyx_t_25, __pyx_pybuffernd_result.diminfo[0].strides, __pyx_t_26, __pyx_pybuffernd_result.diminfo[1].strides) = (__pyx_v_sum_val / __pyx_v_n_fold); } __pyx_L11:; } }
+087: return result
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_result)); __pyx_r = ((PyObject *)__pyx_v_result); goto __pyx_L0;
088:
089: #
090: # def apply_radial_bgsub_int8(np.ndarray[np.uint8_t, ndim=2] img, np.ndarray[np.uint8_t, ndim=2] smooth_img, int center_x, int center_y, int radius, int threshold):
091: # cdef int img_height = img.shape[0]
092: # cdef int img_width = img.shape[1]
093: # cdef np.ndarray[np.uint8_t, ndim=2] result = np.zeros((img_height, img_width), dtype = np.uint8)
094: # cdef np.ndarray[np.uint8_t, ndim=2] radial_bgsub = np.full((radius,1), np.max(img), dtype = np.uint8)
095: # cdef Py_ssize_t x, y
096: # cdef int r
097: # cdef np.uint8_t bgsub
098: # cdef np.uint8_t val, min
099: # cdef np.uint8_t zero = 0
100: #
101: # for x in range(img_width):
102: # for y in range(img_height):
103: # val = smooth_img[y,x]
104: # if val >= threshold:
105: # r = int(distance( x, y, center_x, center_y))
106: # min = radial_bgsub[r]
107: # if min > val:
108: # radial_bgsub[r] = val
109: #
110: # for x in range(img_width):
111: # for y in range(img_height):
112: # val = img[y,x]
113: # if val >= threshold:
114: # bgsub = 0
115: # r = int(distance( x, y, center_x, center_y))
116: # if radius > r:
117: # bgsub = radial_bgsub[r]
118: #
119: # if bgsub <= val:
120: # result[y,x] = val - bgsub
121: # else:
122: # result[y,x] = zero
123: # else:
124: # result[y,x] = val
125: #
126: # return result
127: #
128: #
129: # def apply_radial_bgsub_int16(np.ndarray[np.uint16_t, ndim=2] img, np.ndarray[np.uint16_t, ndim=2] smooth_img, int center_x, int center_y, int radius, int threshold):
130: # cdef int img_height = img.shape[0]
131: # cdef int img_width = img.shape[1]
132: # cdef np.ndarray[np.uint16_t, ndim=2] result = np.zeros((img_height, img_width), dtype = np.uint16)
133: # cdef np.ndarray[np.uint16_t, ndim=2] radial_bgsub = np.full((radius,1), np.max(img), dtype = np.uint16)
134: # cdef Py_ssize_t x, y
135: # cdef int r
136: # cdef np.uint16_t bgsub
137: # cdef np.uint16_t val, min
138: # cdef np.uint16_t zero = 0
139: #
140: # for x in range(img_width):
141: # for y in range(img_height):
142: # val = smooth_img[y,x]
143: # if val >= threshold:
144: # r = int(distance( x, y, center_x, center_y))
145: # min = radial_bgsub[r]
146: # if min > val:
147: # radial_bgsub[r] = val
148: #
149: # for x in range(img_width):
150: # for y in range(img_height):
151: # val = img[y,x]
152: # if val >= threshold:
153: # bgsub = 0
154: # r = int(distance( x, y, center_x, center_y))
155: # if radius > r:
156: # bgsub = radial_bgsub[r]
157: #
158: # if bgsub <= val:
159: # result[y,x] = val - bgsub
160: # else:
161: # result[y,x] = zero
162: # else:
163: # result[y,x] = val
164: #
165: # return result
166:
167:
+168: def apply_radial_bgsub_float32(np.ndarray[np.float32_t, ndim=2] img, np.ndarray[np.float32_t, ndim=2] smooth_img, int center_x, int center_y, int radius, int threshold):
/* Python wrapper */ static PyObject *__pyx_pw_12QF_utilities_9apply_radial_bgsub_float32(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyMethodDef __pyx_mdef_12QF_utilities_9apply_radial_bgsub_float32 = {"apply_radial_bgsub_float32", (PyCFunction)__pyx_pw_12QF_utilities_9apply_radial_bgsub_float32, METH_VARARGS|METH_KEYWORDS, 0}; static PyObject *__pyx_pw_12QF_utilities_9apply_radial_bgsub_float32(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyArrayObject *__pyx_v_img = 0; PyArrayObject *__pyx_v_smooth_img = 0; int __pyx_v_center_x; int __pyx_v_center_y; int __pyx_v_radius; int __pyx_v_threshold; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("apply_radial_bgsub_float32 (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_img,&__pyx_n_s_smooth_img,&__pyx_n_s_center_x,&__pyx_n_s_center_y,&__pyx_n_s_radius,&__pyx_n_s_threshold,0}; PyObject* values[6] = {0,0,0,0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); CYTHON_FALLTHROUGH; case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); CYTHON_FALLTHROUGH; case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); CYTHON_FALLTHROUGH; case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_img)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_smooth_img)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("apply_radial_bgsub_float32", 1, 6, 6, 1); __PYX_ERR(0, 168, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_center_x)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("apply_radial_bgsub_float32", 1, 6, 6, 2); __PYX_ERR(0, 168, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 3: if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_center_y)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("apply_radial_bgsub_float32", 1, 6, 6, 3); __PYX_ERR(0, 168, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 4: if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_radius)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("apply_radial_bgsub_float32", 1, 6, 6, 4); __PYX_ERR(0, 168, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 5: if (likely((values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_threshold)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("apply_radial_bgsub_float32", 1, 6, 6, 5); __PYX_ERR(0, 168, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "apply_radial_bgsub_float32") < 0)) __PYX_ERR(0, 168, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 6) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); values[2] = PyTuple_GET_ITEM(__pyx_args, 2); values[3] = PyTuple_GET_ITEM(__pyx_args, 3); values[4] = PyTuple_GET_ITEM(__pyx_args, 4); values[5] = PyTuple_GET_ITEM(__pyx_args, 5); } __pyx_v_img = ((PyArrayObject *)values[0]); __pyx_v_smooth_img = ((PyArrayObject *)values[1]); __pyx_v_center_x = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_center_x == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 168, __pyx_L3_error) __pyx_v_center_y = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_center_y == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 168, __pyx_L3_error) __pyx_v_radius = __Pyx_PyInt_As_int(values[4]); if (unlikely((__pyx_v_radius == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 168, __pyx_L3_error) __pyx_v_threshold = __Pyx_PyInt_As_int(values[5]); if (unlikely((__pyx_v_threshold == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 168, __pyx_L3_error) } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("apply_radial_bgsub_float32", 1, 6, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 168, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("QF_utilities.apply_radial_bgsub_float32", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_img), __pyx_ptype_5numpy_ndarray, 1, "img", 0))) __PYX_ERR(0, 168, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_smooth_img), __pyx_ptype_5numpy_ndarray, 1, "smooth_img", 0))) __PYX_ERR(0, 168, __pyx_L1_error) __pyx_r = __pyx_pf_12QF_utilities_8apply_radial_bgsub_float32(__pyx_self, __pyx_v_img, __pyx_v_smooth_img, __pyx_v_center_x, __pyx_v_center_y, __pyx_v_radius, __pyx_v_threshold); /* function exit code */ goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_12QF_utilities_8apply_radial_bgsub_float32(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_img, PyArrayObject *__pyx_v_smooth_img, int __pyx_v_center_x, int __pyx_v_center_y, int __pyx_v_radius, int __pyx_v_threshold) { int __pyx_v_img_height; int __pyx_v_img_width; PyArrayObject *__pyx_v_result = 0; PyArrayObject *__pyx_v_radial_bgsub = 0; Py_ssize_t __pyx_v_x; Py_ssize_t __pyx_v_y; int __pyx_v_r; __pyx_t_5numpy_float32_t __pyx_v_bgsub; __pyx_t_5numpy_float32_t __pyx_v_val; __pyx_t_5numpy_float32_t __pyx_v_min; __pyx_t_5numpy_float32_t __pyx_v_zero; __Pyx_LocalBuf_ND __pyx_pybuffernd_img; __Pyx_Buffer __pyx_pybuffer_img; __Pyx_LocalBuf_ND __pyx_pybuffernd_radial_bgsub; __Pyx_Buffer __pyx_pybuffer_radial_bgsub; __Pyx_LocalBuf_ND __pyx_pybuffernd_result; __Pyx_Buffer __pyx_pybuffer_result; __Pyx_LocalBuf_ND __pyx_pybuffernd_smooth_img; __Pyx_Buffer __pyx_pybuffer_smooth_img; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("apply_radial_bgsub_float32", 0); __pyx_pybuffer_result.pybuffer.buf = NULL; __pyx_pybuffer_result.refcount = 0; __pyx_pybuffernd_result.data = NULL; __pyx_pybuffernd_result.rcbuffer = &__pyx_pybuffer_result; __pyx_pybuffer_radial_bgsub.pybuffer.buf = NULL; __pyx_pybuffer_radial_bgsub.refcount = 0; __pyx_pybuffernd_radial_bgsub.data = NULL; __pyx_pybuffernd_radial_bgsub.rcbuffer = &__pyx_pybuffer_radial_bgsub; __pyx_pybuffer_img.pybuffer.buf = NULL; __pyx_pybuffer_img.refcount = 0; __pyx_pybuffernd_img.data = NULL; __pyx_pybuffernd_img.rcbuffer = &__pyx_pybuffer_img; __pyx_pybuffer_smooth_img.pybuffer.buf = NULL; __pyx_pybuffer_smooth_img.refcount = 0; __pyx_pybuffernd_smooth_img.data = NULL; __pyx_pybuffernd_smooth_img.rcbuffer = &__pyx_pybuffer_smooth_img; { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_img.rcbuffer->pybuffer, (PyObject*)__pyx_v_img, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 168, __pyx_L1_error) } __pyx_pybuffernd_img.diminfo[0].strides = __pyx_pybuffernd_img.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_img.diminfo[0].shape = __pyx_pybuffernd_img.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_img.diminfo[1].strides = __pyx_pybuffernd_img.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_img.diminfo[1].shape = __pyx_pybuffernd_img.rcbuffer->pybuffer.shape[1]; { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_smooth_img.rcbuffer->pybuffer, (PyObject*)__pyx_v_smooth_img, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 168, __pyx_L1_error) } __pyx_pybuffernd_smooth_img.diminfo[0].strides = __pyx_pybuffernd_smooth_img.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_smooth_img.diminfo[0].shape = __pyx_pybuffernd_smooth_img.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_smooth_img.diminfo[1].strides = __pyx_pybuffernd_smooth_img.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_smooth_img.diminfo[1].shape = __pyx_pybuffernd_smooth_img.rcbuffer->pybuffer.shape[1]; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_7); { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; __Pyx_PyThreadState_declare __Pyx_PyThreadState_assign __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_img.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_radial_bgsub.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_result.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_smooth_img.rcbuffer->pybuffer); __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} __Pyx_AddTraceback("QF_utilities.apply_radial_bgsub_float32", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; goto __pyx_L2; __pyx_L0:; __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_img.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_radial_bgsub.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_result.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_smooth_img.rcbuffer->pybuffer); __pyx_L2:; __Pyx_XDECREF((PyObject *)__pyx_v_result); __Pyx_XDECREF((PyObject *)__pyx_v_radial_bgsub); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_tuple__16 = PyTuple_Pack(17, __pyx_n_s_img, __pyx_n_s_smooth_img, __pyx_n_s_center_x, __pyx_n_s_center_y, __pyx_n_s_radius, __pyx_n_s_threshold, __pyx_n_s_img_height, __pyx_n_s_img_width, __pyx_n_s_result, __pyx_n_s_radial_bgsub, __pyx_n_s_x, __pyx_n_s_y, __pyx_n_s_r, __pyx_n_s_bgsub, __pyx_n_s_val, __pyx_n_s_min, __pyx_n_s_zero); if (unlikely(!__pyx_tuple__16)) __PYX_ERR(0, 168, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__16); __Pyx_GIVEREF(__pyx_tuple__16); /* … */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_12QF_utilities_9apply_radial_bgsub_float32, NULL, __pyx_n_s_QF_utilities); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 168, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_apply_radial_bgsub_float32, __pyx_t_1) < 0) __PYX_ERR(0, 168, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_codeobj__17 = (PyObject*)__Pyx_PyCode_New(6, 0, 17, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__16, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_QF_utilities_pyx, __pyx_n_s_apply_radial_bgsub_float32, 168, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__17)) __PYX_ERR(0, 168, __pyx_L1_error)
+169: cdef int img_height = img.shape[0]
__pyx_v_img_height = (__pyx_v_img->dimensions[0]);
+170: cdef int img_width = img.shape[1]
__pyx_v_img_width = (__pyx_v_img->dimensions[1]);
+171: cdef np.ndarray[np.float32_t, ndim=2] result = np.zeros((img_height, img_width), dtype = np.float32)
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 171, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 171, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_img_height); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 171, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_img_width); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 171, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 171, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); __pyx_t_1 = 0; __pyx_t_3 = 0; __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 171, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 171, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 171, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_float32); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 171, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 171, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 171, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 171, __pyx_L1_error) __pyx_t_6 = ((PyArrayObject *)__pyx_t_5); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_result.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) { __pyx_v_result = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_result.rcbuffer->pybuffer.buf = NULL; __PYX_ERR(0, 171, __pyx_L1_error) } else {__pyx_pybuffernd_result.diminfo[0].strides = __pyx_pybuffernd_result.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_result.diminfo[0].shape = __pyx_pybuffernd_result.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_result.diminfo[1].strides = __pyx_pybuffernd_result.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_result.diminfo[1].shape = __pyx_pybuffernd_result.rcbuffer->pybuffer.shape[1]; } } __pyx_t_6 = 0; __pyx_v_result = ((PyArrayObject *)__pyx_t_5); __pyx_t_5 = 0;
+172: cdef np.ndarray[np.float32_t, ndim=2] radial_bgsub = np.full((radius,1), np.max(img), dtype = np.float32)
__pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 172, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_full); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 172, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_radius); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 172, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 172, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5); __Pyx_INCREF(__pyx_int_1); __Pyx_GIVEREF(__pyx_int_1); PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_1); __pyx_t_5 = 0; __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 172, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_max); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 172, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = NULL; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_1); if (likely(__pyx_t_2)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); __Pyx_INCREF(__pyx_t_2); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_1, function); } } if (!__pyx_t_2) { __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_1, ((PyObject *)__pyx_v_img)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 172, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_1)) { PyObject *__pyx_temp[2] = {__pyx_t_2, ((PyObject *)__pyx_v_img)}; __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 172, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_GOTREF(__pyx_t_5); } else #endif #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { PyObject *__pyx_temp[2] = {__pyx_t_2, ((PyObject *)__pyx_v_img)}; __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 172, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_GOTREF(__pyx_t_5); } else #endif { __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 172, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2); __pyx_t_2 = NULL; __Pyx_INCREF(((PyObject *)__pyx_v_img)); __Pyx_GIVEREF(((PyObject *)__pyx_v_img)); PyTuple_SET_ITEM(__pyx_t_7, 0+1, ((PyObject *)__pyx_v_img)); __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_7, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 172, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 172, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_5); __pyx_t_3 = 0; __pyx_t_5 = 0; __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 172, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 172, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float32); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 172, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 172, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 172, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (!(likely(((__pyx_t_7) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_7, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 172, __pyx_L1_error) __pyx_t_8 = ((PyArrayObject *)__pyx_t_7); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_radial_bgsub.rcbuffer->pybuffer, (PyObject*)__pyx_t_8, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) { __pyx_v_radial_bgsub = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_radial_bgsub.rcbuffer->pybuffer.buf = NULL; __PYX_ERR(0, 172, __pyx_L1_error) } else {__pyx_pybuffernd_radial_bgsub.diminfo[0].strides = __pyx_pybuffernd_radial_bgsub.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_radial_bgsub.diminfo[0].shape = __pyx_pybuffernd_radial_bgsub.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_radial_bgsub.diminfo[1].strides = __pyx_pybuffernd_radial_bgsub.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_radial_bgsub.diminfo[1].shape = __pyx_pybuffernd_radial_bgsub.rcbuffer->pybuffer.shape[1]; } } __pyx_t_8 = 0; __pyx_v_radial_bgsub = ((PyArrayObject *)__pyx_t_7); __pyx_t_7 = 0;
173: cdef Py_ssize_t x, y
174: cdef int r
175: cdef np.float32_t bgsub
176: cdef np.float32_t val, min
+177: cdef np.float32_t zero = 0.0
__pyx_v_zero = 0.0;
178:
+179: for x in range(img_width):
__pyx_t_9 = __pyx_v_img_width; for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) { __pyx_v_x = __pyx_t_10;
+180: for y in range(img_height):
__pyx_t_11 = __pyx_v_img_height; for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) { __pyx_v_y = __pyx_t_12;
+181: val = smooth_img[y,x]
__pyx_t_13 = __pyx_v_y; __pyx_t_14 = __pyx_v_x; __pyx_v_val = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_smooth_img.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_smooth_img.diminfo[0].strides, __pyx_t_14, __pyx_pybuffernd_smooth_img.diminfo[1].strides));
+182: if val >= threshold:
__pyx_t_15 = ((__pyx_v_val >= __pyx_v_threshold) != 0); if (__pyx_t_15) { /* … */ } } }
+183: r = int(distance( x, y, center_x, center_y))
__pyx_v_r = ((int)__pyx_f_12QF_utilities_distance(__pyx_v_x, __pyx_v_y, __pyx_v_center_x, __pyx_v_center_y, 0));
+184: min = radial_bgsub[r]
__pyx_t_7 = __Pyx_GetItemInt(((PyObject *)__pyx_v_radial_bgsub), __pyx_v_r, int, 1, __Pyx_PyInt_From_int, 0, 0, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 184, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_16 = __pyx_PyFloat_AsFloat(__pyx_t_7); if (unlikely((__pyx_t_16 == ((npy_float32)-1)) && PyErr_Occurred())) __PYX_ERR(0, 184, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_v_min = __pyx_t_16;
+185: if min > val:
__pyx_t_15 = ((__pyx_v_min > __pyx_v_val) != 0); if (__pyx_t_15) { /* … */ }
+186: radial_bgsub[r] = val
__pyx_t_7 = PyFloat_FromDouble(__pyx_v_val); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 186, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); if (unlikely(__Pyx_SetItemInt(((PyObject *)__pyx_v_radial_bgsub), __pyx_v_r, __pyx_t_7, int, 1, __Pyx_PyInt_From_int, 0, 0, 0) < 0)) __PYX_ERR(0, 186, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
187:
+188: for x in range(img_width):
__pyx_t_9 = __pyx_v_img_width; for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) { __pyx_v_x = __pyx_t_10;
+189: for y in range(img_height):
__pyx_t_11 = __pyx_v_img_height; for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) { __pyx_v_y = __pyx_t_12;
+190: val = img[y,x]
__pyx_t_17 = __pyx_v_y; __pyx_t_18 = __pyx_v_x; __pyx_v_val = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_img.rcbuffer->pybuffer.buf, __pyx_t_17, __pyx_pybuffernd_img.diminfo[0].strides, __pyx_t_18, __pyx_pybuffernd_img.diminfo[1].strides));
+191: if val >= threshold:
__pyx_t_15 = ((__pyx_v_val >= __pyx_v_threshold) != 0); if (__pyx_t_15) { /* … */ goto __pyx_L13; }
+192: bgsub = 0.0
__pyx_v_bgsub = 0.0;
+193: r = int(distance( x, y, center_x, center_y))
__pyx_v_r = ((int)__pyx_f_12QF_utilities_distance(__pyx_v_x, __pyx_v_y, __pyx_v_center_x, __pyx_v_center_y, 0));
+194: if radius > r:
__pyx_t_15 = ((__pyx_v_radius > __pyx_v_r) != 0); if (__pyx_t_15) { /* … */ }
+195: bgsub = radial_bgsub[r]
__pyx_t_7 = __Pyx_GetItemInt(((PyObject *)__pyx_v_radial_bgsub), __pyx_v_r, int, 1, __Pyx_PyInt_From_int, 0, 0, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 195, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_16 = __pyx_PyFloat_AsFloat(__pyx_t_7); if (unlikely((__pyx_t_16 == ((npy_float32)-1)) && PyErr_Occurred())) __PYX_ERR(0, 195, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_v_bgsub = __pyx_t_16;
196:
+197: if bgsub <= val:
__pyx_t_15 = ((__pyx_v_bgsub <= __pyx_v_val) != 0); if (__pyx_t_15) { /* … */ goto __pyx_L15; }
+198: result[y,x] = val - bgsub
__pyx_t_19 = __pyx_v_y; __pyx_t_20 = __pyx_v_x; *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_result.rcbuffer->pybuffer.buf, __pyx_t_19, __pyx_pybuffernd_result.diminfo[0].strides, __pyx_t_20, __pyx_pybuffernd_result.diminfo[1].strides) = (__pyx_v_val - __pyx_v_bgsub);
199: else:
+200: result[y,x] = zero
/*else*/ { __pyx_t_21 = __pyx_v_y; __pyx_t_22 = __pyx_v_x; *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_result.rcbuffer->pybuffer.buf, __pyx_t_21, __pyx_pybuffernd_result.diminfo[0].strides, __pyx_t_22, __pyx_pybuffernd_result.diminfo[1].strides) = __pyx_v_zero; } __pyx_L15:;
201: else:
+202: result[y,x] = val
/*else*/ { __pyx_t_23 = __pyx_v_y; __pyx_t_24 = __pyx_v_x; *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_result.rcbuffer->pybuffer.buf, __pyx_t_23, __pyx_pybuffernd_result.diminfo[0].strides, __pyx_t_24, __pyx_pybuffernd_result.diminfo[1].strides) = __pyx_v_val; } __pyx_L13:; } }
203:
+204: return result
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_result)); __pyx_r = ((PyObject *)__pyx_v_result); goto __pyx_L0;
205:
206:
+207: cdef float sigmoid(float k, int x0, float x):
static float __pyx_f_12QF_utilities_sigmoid(float __pyx_v_k, int __pyx_v_x0, float __pyx_v_x) { float __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("sigmoid", 0); /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_WriteUnraisable("QF_utilities.sigmoid", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); __pyx_r = 0; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; }
+208: return 1.0/(1.0+exp(-k*(x-x0)))
__pyx_t_1 = (1.0 + exp(((-__pyx_v_k) * (__pyx_v_x - __pyx_v_x0)))); if (unlikely(__pyx_t_1 == 0)) { PyErr_SetString(PyExc_ZeroDivisionError, "float division"); __PYX_ERR(0, 208, __pyx_L1_error) } __pyx_r = (1.0 / __pyx_t_1); goto __pyx_L0;
209:
210:
+211: def combine_bgsub_float32(np.ndarray[np.float32_t, ndim=2] img1, np.ndarray[np.float32_t, ndim=2] img2, int center_x, int center_y, float sigmoid_k, int radius):
/* Python wrapper */ static PyObject *__pyx_pw_12QF_utilities_11combine_bgsub_float32(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyMethodDef __pyx_mdef_12QF_utilities_11combine_bgsub_float32 = {"combine_bgsub_float32", (PyCFunction)__pyx_pw_12QF_utilities_11combine_bgsub_float32, METH_VARARGS|METH_KEYWORDS, 0}; static PyObject *__pyx_pw_12QF_utilities_11combine_bgsub_float32(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyArrayObject *__pyx_v_img1 = 0; PyArrayObject *__pyx_v_img2 = 0; int __pyx_v_center_x; int __pyx_v_center_y; float __pyx_v_sigmoid_k; int __pyx_v_radius; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("combine_bgsub_float32 (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_img1,&__pyx_n_s_img2,&__pyx_n_s_center_x,&__pyx_n_s_center_y,&__pyx_n_s_sigmoid_k,&__pyx_n_s_radius,0}; PyObject* values[6] = {0,0,0,0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); CYTHON_FALLTHROUGH; case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); CYTHON_FALLTHROUGH; case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); CYTHON_FALLTHROUGH; case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_img1)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_img2)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("combine_bgsub_float32", 1, 6, 6, 1); __PYX_ERR(0, 211, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_center_x)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("combine_bgsub_float32", 1, 6, 6, 2); __PYX_ERR(0, 211, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 3: if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_center_y)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("combine_bgsub_float32", 1, 6, 6, 3); __PYX_ERR(0, 211, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 4: if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_sigmoid_k)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("combine_bgsub_float32", 1, 6, 6, 4); __PYX_ERR(0, 211, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 5: if (likely((values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_radius)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("combine_bgsub_float32", 1, 6, 6, 5); __PYX_ERR(0, 211, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "combine_bgsub_float32") < 0)) __PYX_ERR(0, 211, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 6) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); values[2] = PyTuple_GET_ITEM(__pyx_args, 2); values[3] = PyTuple_GET_ITEM(__pyx_args, 3); values[4] = PyTuple_GET_ITEM(__pyx_args, 4); values[5] = PyTuple_GET_ITEM(__pyx_args, 5); } __pyx_v_img1 = ((PyArrayObject *)values[0]); __pyx_v_img2 = ((PyArrayObject *)values[1]); __pyx_v_center_x = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_center_x == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 211, __pyx_L3_error) __pyx_v_center_y = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_center_y == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 211, __pyx_L3_error) __pyx_v_sigmoid_k = __pyx_PyFloat_AsFloat(values[4]); if (unlikely((__pyx_v_sigmoid_k == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 211, __pyx_L3_error) __pyx_v_radius = __Pyx_PyInt_As_int(values[5]); if (unlikely((__pyx_v_radius == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 211, __pyx_L3_error) } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("combine_bgsub_float32", 1, 6, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 211, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("QF_utilities.combine_bgsub_float32", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_img1), __pyx_ptype_5numpy_ndarray, 1, "img1", 0))) __PYX_ERR(0, 211, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_img2), __pyx_ptype_5numpy_ndarray, 1, "img2", 0))) __PYX_ERR(0, 211, __pyx_L1_error) __pyx_r = __pyx_pf_12QF_utilities_10combine_bgsub_float32(__pyx_self, __pyx_v_img1, __pyx_v_img2, __pyx_v_center_x, __pyx_v_center_y, __pyx_v_sigmoid_k, __pyx_v_radius); /* function exit code */ goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_12QF_utilities_10combine_bgsub_float32(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_img1, PyArrayObject *__pyx_v_img2, int __pyx_v_center_x, int __pyx_v_center_y, float __pyx_v_sigmoid_k, int __pyx_v_radius) { int __pyx_v_img_height; int __pyx_v_img_width; PyArrayObject *__pyx_v_result = 0; int __pyx_v_x; int __pyx_v_y; __pyx_t_5numpy_float32_t __pyx_v_r; __pyx_t_5numpy_float32_t __pyx_v_tophat_ratio; __pyx_t_5numpy_float32_t __pyx_v_radial_ratio; __pyx_t_5numpy_float32_t __pyx_v_tophat_val; __pyx_t_5numpy_float32_t __pyx_v_radial_val; __Pyx_LocalBuf_ND __pyx_pybuffernd_img1; __Pyx_Buffer __pyx_pybuffer_img1; __Pyx_LocalBuf_ND __pyx_pybuffernd_img2; __Pyx_Buffer __pyx_pybuffer_img2; __Pyx_LocalBuf_ND __pyx_pybuffernd_result; __Pyx_Buffer __pyx_pybuffer_result; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("combine_bgsub_float32", 0); __pyx_pybuffer_result.pybuffer.buf = NULL; __pyx_pybuffer_result.refcount = 0; __pyx_pybuffernd_result.data = NULL; __pyx_pybuffernd_result.rcbuffer = &__pyx_pybuffer_result; __pyx_pybuffer_img1.pybuffer.buf = NULL; __pyx_pybuffer_img1.refcount = 0; __pyx_pybuffernd_img1.data = NULL; __pyx_pybuffernd_img1.rcbuffer = &__pyx_pybuffer_img1; __pyx_pybuffer_img2.pybuffer.buf = NULL; __pyx_pybuffer_img2.refcount = 0; __pyx_pybuffernd_img2.data = NULL; __pyx_pybuffernd_img2.rcbuffer = &__pyx_pybuffer_img2; { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_img1.rcbuffer->pybuffer, (PyObject*)__pyx_v_img1, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 211, __pyx_L1_error) } __pyx_pybuffernd_img1.diminfo[0].strides = __pyx_pybuffernd_img1.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_img1.diminfo[0].shape = __pyx_pybuffernd_img1.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_img1.diminfo[1].strides = __pyx_pybuffernd_img1.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_img1.diminfo[1].shape = __pyx_pybuffernd_img1.rcbuffer->pybuffer.shape[1]; { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_img2.rcbuffer->pybuffer, (PyObject*)__pyx_v_img2, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 211, __pyx_L1_error) } __pyx_pybuffernd_img2.diminfo[0].strides = __pyx_pybuffernd_img2.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_img2.diminfo[0].shape = __pyx_pybuffernd_img2.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_img2.diminfo[1].strides = __pyx_pybuffernd_img2.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_img2.diminfo[1].shape = __pyx_pybuffernd_img2.rcbuffer->pybuffer.shape[1]; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; __Pyx_PyThreadState_declare __Pyx_PyThreadState_assign __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_img1.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_img2.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_result.rcbuffer->pybuffer); __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} __Pyx_AddTraceback("QF_utilities.combine_bgsub_float32", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; goto __pyx_L2; __pyx_L0:; __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_img1.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_img2.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_result.rcbuffer->pybuffer); __pyx_L2:; __Pyx_XDECREF((PyObject *)__pyx_v_result); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_tuple__18 = PyTuple_Pack(17, __pyx_n_s_img1, __pyx_n_s_img2, __pyx_n_s_center_x, __pyx_n_s_center_y, __pyx_n_s_sigmoid_k, __pyx_n_s_radius, __pyx_n_s_img_height, __pyx_n_s_img_width, __pyx_n_s_result, __pyx_n_s_x, __pyx_n_s_y, __pyx_n_s_r, __pyx_n_s_tophat_ratio, __pyx_n_s_radial_ratio, __pyx_n_s_tophat_val, __pyx_n_s_radial_val, __pyx_n_s_th_tmp); if (unlikely(!__pyx_tuple__18)) __PYX_ERR(0, 211, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__18); __Pyx_GIVEREF(__pyx_tuple__18); /* … */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_12QF_utilities_11combine_bgsub_float32, NULL, __pyx_n_s_QF_utilities); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 211, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_combine_bgsub_float32, __pyx_t_1) < 0) __PYX_ERR(0, 211, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_codeobj__19 = (PyObject*)__Pyx_PyCode_New(6, 0, 17, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__18, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_QF_utilities_pyx, __pyx_n_s_combine_bgsub_float32, 211, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__19)) __PYX_ERR(0, 211, __pyx_L1_error)
+212: cdef int img_height = img1.shape[0]
__pyx_v_img_height = (__pyx_v_img1->dimensions[0]);
+213: cdef int img_width = img1.shape[1]
__pyx_v_img_width = (__pyx_v_img1->dimensions[1]);
+214: cdef np.ndarray[np.float32_t, ndim=2] result = np.zeros((img_height, img_width), dtype = np.float32)
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 214, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 214, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_img_height); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 214, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_img_width); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 214, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 214, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); __pyx_t_1 = 0; __pyx_t_3 = 0; __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 214, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 214, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 214, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_float32); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 214, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 214, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 214, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 214, __pyx_L1_error) __pyx_t_6 = ((PyArrayObject *)__pyx_t_5); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_result.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) { __pyx_v_result = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_result.rcbuffer->pybuffer.buf = NULL; __PYX_ERR(0, 214, __pyx_L1_error) } else {__pyx_pybuffernd_result.diminfo[0].strides = __pyx_pybuffernd_result.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_result.diminfo[0].shape = __pyx_pybuffernd_result.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_result.diminfo[1].strides = __pyx_pybuffernd_result.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_result.diminfo[1].shape = __pyx_pybuffernd_result.rcbuffer->pybuffer.shape[1]; } } __pyx_t_6 = 0; __pyx_v_result = ((PyArrayObject *)__pyx_t_5); __pyx_t_5 = 0;
215: cdef int x, y
216: cdef np.float32_t r
217: cdef np.float32_t tophat_ratio, radial_ratio
218: cdef np.float32_t tophat_val, radial_val, th_tmp
219:
+220: for x in range(img_width):
__pyx_t_7 = __pyx_v_img_width; for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) { __pyx_v_x = __pyx_t_8;
+221: for y in range(img_height):
__pyx_t_9 = __pyx_v_img_height; for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) { __pyx_v_y = __pyx_t_10;
+222: r = distance( x, y, center_x, center_y)
__pyx_v_r = __pyx_f_12QF_utilities_distance(__pyx_v_x, __pyx_v_y, __pyx_v_center_x, __pyx_v_center_y, 0);
+223: tophat_ratio = sigmoid(sigmoid_k, radius, r)
__pyx_v_tophat_ratio = __pyx_f_12QF_utilities_sigmoid(__pyx_v_sigmoid_k, __pyx_v_radius, __pyx_v_r);
+224: radial_ratio = 1.0 - tophat_ratio
__pyx_v_radial_ratio = (1.0 - __pyx_v_tophat_ratio);
+225: tophat_val = tophat_ratio * img2[y,x]
__pyx_t_11 = __pyx_v_y; __pyx_t_12 = __pyx_v_x; __pyx_v_tophat_val = (__pyx_v_tophat_ratio * (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_img2.rcbuffer->pybuffer.buf, __pyx_t_11, __pyx_pybuffernd_img2.diminfo[0].strides, __pyx_t_12, __pyx_pybuffernd_img2.diminfo[1].strides)));
+226: radial_val = radial_ratio * img1[y,x]
__pyx_t_13 = __pyx_v_y; __pyx_t_14 = __pyx_v_x; __pyx_v_radial_val = (__pyx_v_radial_ratio * (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_img1.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_img1.diminfo[0].strides, __pyx_t_14, __pyx_pybuffernd_img1.diminfo[1].strides)));
+227: result[y,x] = tophat_val+radial_val
__pyx_t_15 = __pyx_v_y; __pyx_t_16 = __pyx_v_x; *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_result.rcbuffer->pybuffer.buf, __pyx_t_15, __pyx_pybuffernd_result.diminfo[0].strides, __pyx_t_16, __pyx_pybuffernd_result.diminfo[1].strides) = (__pyx_v_tophat_val + __pyx_v_radial_val); } }
+228: return result
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_result)); __pyx_r = ((PyObject *)__pyx_v_result); goto __pyx_L0;
229:
230: # def combine_bgsub_uint16(np.ndarray[np.uint16_t, ndim=2] tophat_img, np.ndarray[np.uint16_t, ndim=2] radial_img, int center_x, int center_y, float sigmoid_k, int radius, int threshold):
231: # cdef int img_height = tophat_img.shape[0]
232: # cdef int img_width = tophat_img.shape[1]
233: # cdef np.ndarray[np.uint16_t, ndim=2] result = np.zeros((img_height, img_width), dtype = np.uint16)
234: # cdef Py_ssize_t x, y
235: # cdef int r
236: # cdef float tophat_ratio, radial_ratio
237: # cdef np.uint16_t tophat_val, radial_val, th_tmp
238: #
239: # for x in range(img_width):
240: # for y in range(img_height):
241: # th_tmp = tophat_img[y,x]
242: # if th_tmp >= threshold:
243: # r = int(distance( x, y, center_x, center_y))
244: # tophat_ratio = sigmoid(sigmoid_k, radius, r)
245: # radial_ratio = 1.0 - tophat_ratio
246: # tophat_val = int(tophat_ratio * th_tmp)
247: # radial_val = int(radial_ratio * radial_img[y,x])
248: # result[y,x] = tophat_val+radial_val
249: # else:
250: # result[y,x] = th_tmp
251: #
252: # return result
253: #
254: # def combine_bgsub_uint8(np.ndarray[np.uint8_t, ndim=2] tophat_img, np.ndarray[np.uint8_t, ndim=2] radial_img, int center_x, int center_y, float sigmoid_k, int radius, int threshold):
255: # cdef int img_height = tophat_img.shape[0]
256: # cdef int img_width = tophat_img.shape[1]
257: # cdef np.ndarray[np.uint8_t, ndim=2] result = np.zeros((img_height, img_width), dtype = np.uint8)
258: # cdef Py_ssize_t x, y
259: # cdef int r
260: # cdef float tophat_ratio, radial_ratio
261: # cdef np.uint8_t tophat_val, radial_val, th_tmp
262: #
263: # for x in range(img_width):
264: # for y in range(img_height):
265: # th_tmp = tophat_img[y,x]
266: # if th_tmp >= threshold:
267: # r = int(distance( x, y, center_x, center_y))
268: # tophat_ratio = sigmoid(sigmoid_k, radius, r)
269: # radial_ratio = 1.0 - tophat_ratio
270: # tophat_val = int(tophat_ratio * th_tmp)
271: # radial_val = int(radial_ratio * radial_img[y,x])
272: # result[y,x] = tophat_val+radial_val
273: # else:
274: # result[y,x] = th_tmp
275: #
276: # return result
277:
278:
+279: def getCirSubtr_f32(np.ndarray[np.float32_t, ndim=2] img, np.ndarray[np.float32_t, ndim=1] subtr_hist, int radius):
/* Python wrapper */ static PyObject *__pyx_pw_12QF_utilities_13getCirSubtr_f32(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyMethodDef __pyx_mdef_12QF_utilities_13getCirSubtr_f32 = {"getCirSubtr_f32", (PyCFunction)__pyx_pw_12QF_utilities_13getCirSubtr_f32, METH_VARARGS|METH_KEYWORDS, 0}; static PyObject *__pyx_pw_12QF_utilities_13getCirSubtr_f32(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyArrayObject *__pyx_v_img = 0; PyArrayObject *__pyx_v_subtr_hist = 0; int __pyx_v_radius; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("getCirSubtr_f32 (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_img,&__pyx_n_s_subtr_hist,&__pyx_n_s_radius,0}; PyObject* values[3] = {0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_img)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_subtr_hist)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("getCirSubtr_f32", 1, 3, 3, 1); __PYX_ERR(0, 279, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_radius)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("getCirSubtr_f32", 1, 3, 3, 2); __PYX_ERR(0, 279, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "getCirSubtr_f32") < 0)) __PYX_ERR(0, 279, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); values[2] = PyTuple_GET_ITEM(__pyx_args, 2); } __pyx_v_img = ((PyArrayObject *)values[0]); __pyx_v_subtr_hist = ((PyArrayObject *)values[1]); __pyx_v_radius = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_radius == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 279, __pyx_L3_error) } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("getCirSubtr_f32", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 279, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("QF_utilities.getCirSubtr_f32", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_img), __pyx_ptype_5numpy_ndarray, 1, "img", 0))) __PYX_ERR(0, 279, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_subtr_hist), __pyx_ptype_5numpy_ndarray, 1, "subtr_hist", 0))) __PYX_ERR(0, 279, __pyx_L1_error) __pyx_r = __pyx_pf_12QF_utilities_12getCirSubtr_f32(__pyx_self, __pyx_v_img, __pyx_v_subtr_hist, __pyx_v_radius); /* function exit code */ goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_12QF_utilities_12getCirSubtr_f32(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_img, PyArrayObject *__pyx_v_subtr_hist, int __pyx_v_radius) { int __pyx_v_img_height; int __pyx_v_img_width; PyArrayObject *__pyx_v_result = 0; Py_ssize_t __pyx_v_x; Py_ssize_t __pyx_v_y; int __pyx_v_r; __pyx_t_5numpy_float32_t __pyx_v_bgsub; __pyx_t_5numpy_float32_t __pyx_v_val; CYTHON_UNUSED __pyx_t_5numpy_float32_t __pyx_v_zero; __Pyx_LocalBuf_ND __pyx_pybuffernd_img; __Pyx_Buffer __pyx_pybuffer_img; __Pyx_LocalBuf_ND __pyx_pybuffernd_result; __Pyx_Buffer __pyx_pybuffer_result; __Pyx_LocalBuf_ND __pyx_pybuffernd_subtr_hist; __Pyx_Buffer __pyx_pybuffer_subtr_hist; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("getCirSubtr_f32", 0); __pyx_pybuffer_result.pybuffer.buf = NULL; __pyx_pybuffer_result.refcount = 0; __pyx_pybuffernd_result.data = NULL; __pyx_pybuffernd_result.rcbuffer = &__pyx_pybuffer_result; __pyx_pybuffer_img.pybuffer.buf = NULL; __pyx_pybuffer_img.refcount = 0; __pyx_pybuffernd_img.data = NULL; __pyx_pybuffernd_img.rcbuffer = &__pyx_pybuffer_img; __pyx_pybuffer_subtr_hist.pybuffer.buf = NULL; __pyx_pybuffer_subtr_hist.refcount = 0; __pyx_pybuffernd_subtr_hist.data = NULL; __pyx_pybuffernd_subtr_hist.rcbuffer = &__pyx_pybuffer_subtr_hist; { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_img.rcbuffer->pybuffer, (PyObject*)__pyx_v_img, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 279, __pyx_L1_error) } __pyx_pybuffernd_img.diminfo[0].strides = __pyx_pybuffernd_img.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_img.diminfo[0].shape = __pyx_pybuffernd_img.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_img.diminfo[1].strides = __pyx_pybuffernd_img.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_img.diminfo[1].shape = __pyx_pybuffernd_img.rcbuffer->pybuffer.shape[1]; { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_subtr_hist.rcbuffer->pybuffer, (PyObject*)__pyx_v_subtr_hist, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 279, __pyx_L1_error) } __pyx_pybuffernd_subtr_hist.diminfo[0].strides = __pyx_pybuffernd_subtr_hist.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_subtr_hist.diminfo[0].shape = __pyx_pybuffernd_subtr_hist.rcbuffer->pybuffer.shape[0]; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; __Pyx_PyThreadState_declare __Pyx_PyThreadState_assign __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_img.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_result.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_subtr_hist.rcbuffer->pybuffer); __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} __Pyx_AddTraceback("QF_utilities.getCirSubtr_f32", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; goto __pyx_L2; __pyx_L0:; __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_img.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_result.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_subtr_hist.rcbuffer->pybuffer); __pyx_L2:; __Pyx_XDECREF((PyObject *)__pyx_v_result); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_tuple__20 = PyTuple_Pack(13, __pyx_n_s_img, __pyx_n_s_subtr_hist, __pyx_n_s_radius, __pyx_n_s_img_height, __pyx_n_s_img_width, __pyx_n_s_result, __pyx_n_s_x, __pyx_n_s_y, __pyx_n_s_r, __pyx_n_s_bgsub, __pyx_n_s_val, __pyx_n_s_min, __pyx_n_s_zero); if (unlikely(!__pyx_tuple__20)) __PYX_ERR(0, 279, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__20); __Pyx_GIVEREF(__pyx_tuple__20); /* … */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_12QF_utilities_13getCirSubtr_f32, NULL, __pyx_n_s_QF_utilities); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 279, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_getCirSubtr_f32, __pyx_t_1) < 0) __PYX_ERR(0, 279, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_codeobj__21 = (PyObject*)__Pyx_PyCode_New(3, 0, 13, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__20, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_QF_utilities_pyx, __pyx_n_s_getCirSubtr_f32, 279, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__21)) __PYX_ERR(0, 279, __pyx_L1_error)
+280: cdef int img_height = img.shape[0]
__pyx_v_img_height = (__pyx_v_img->dimensions[0]);
+281: cdef int img_width = img.shape[1]
__pyx_v_img_width = (__pyx_v_img->dimensions[1]);
+282: cdef np.ndarray[np.float32_t, ndim=2] result = np.zeros((img_height, img_width), dtype = np.float32)
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 282, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 282, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_img_height); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 282, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_img_width); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 282, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 282, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); __pyx_t_1 = 0; __pyx_t_3 = 0; __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 282, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 282, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 282, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_float32); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 282, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 282, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 282, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 282, __pyx_L1_error) __pyx_t_6 = ((PyArrayObject *)__pyx_t_5); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_result.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) { __pyx_v_result = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_result.rcbuffer->pybuffer.buf = NULL; __PYX_ERR(0, 282, __pyx_L1_error) } else {__pyx_pybuffernd_result.diminfo[0].strides = __pyx_pybuffernd_result.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_result.diminfo[0].shape = __pyx_pybuffernd_result.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_result.diminfo[1].strides = __pyx_pybuffernd_result.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_result.diminfo[1].shape = __pyx_pybuffernd_result.rcbuffer->pybuffer.shape[1]; } } __pyx_t_6 = 0; __pyx_v_result = ((PyArrayObject *)__pyx_t_5); __pyx_t_5 = 0;
283: cdef Py_ssize_t x, y
284: cdef int r
285: cdef np.float32_t bgsub
286: cdef np.float32_t val, min
+287: cdef np.float32_t zero = 0.0
__pyx_v_zero = 0.0;
288:
+289: for x in range(img_width):
__pyx_t_7 = __pyx_v_img_width; for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) { __pyx_v_x = __pyx_t_8;
+290: for y in range(img_height):
__pyx_t_9 = __pyx_v_img_height; for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) { __pyx_v_y = __pyx_t_10;
+291: val = img[y,x]
__pyx_t_11 = __pyx_v_y; __pyx_t_12 = __pyx_v_x; __pyx_v_val = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_img.rcbuffer->pybuffer.buf, __pyx_t_11, __pyx_pybuffernd_img.diminfo[0].strides, __pyx_t_12, __pyx_pybuffernd_img.diminfo[1].strides));
+292: bgsub = 0.0
__pyx_v_bgsub = 0.0;
+293: r = int(distance( x, y, img_width, img_height))
__pyx_v_r = ((int)__pyx_f_12QF_utilities_distance(__pyx_v_x, __pyx_v_y, __pyx_v_img_width, __pyx_v_img_height, 0));
+294: if radius > r:
__pyx_t_13 = ((__pyx_v_radius > __pyx_v_r) != 0); if (__pyx_t_13) { /* … */ }
+295: bgsub = subtr_hist[r]
__pyx_t_14 = __pyx_v_r; __pyx_v_bgsub = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_subtr_hist.rcbuffer->pybuffer.buf, __pyx_t_14, __pyx_pybuffernd_subtr_hist.diminfo[0].strides));
296:
+297: result[y, x] = val - bgsub
__pyx_t_15 = __pyx_v_y; __pyx_t_16 = __pyx_v_x; *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_result.rcbuffer->pybuffer.buf, __pyx_t_15, __pyx_pybuffernd_result.diminfo[0].strides, __pyx_t_16, __pyx_pybuffernd_result.diminfo[1].strides) = (__pyx_v_val - __pyx_v_bgsub); } }
298: # if bgsub <= val:
299: # result[y,x] = val - bgsub
300: # else:
301: # result[y,x] = zero
+302: return result
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_result)); __pyx_r = ((PyObject *)__pyx_v_result); goto __pyx_L0;
303:
+304: def getCirSubtr_i16(np.ndarray[np.uint16_t, ndim=2] img, np.ndarray[np.uint16_t, ndim=1] subtr_hist, int radius):
/* Python wrapper */ static PyObject *__pyx_pw_12QF_utilities_15getCirSubtr_i16(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyMethodDef __pyx_mdef_12QF_utilities_15getCirSubtr_i16 = {"getCirSubtr_i16", (PyCFunction)__pyx_pw_12QF_utilities_15getCirSubtr_i16, METH_VARARGS|METH_KEYWORDS, 0}; static PyObject *__pyx_pw_12QF_utilities_15getCirSubtr_i16(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyArrayObject *__pyx_v_img = 0; PyArrayObject *__pyx_v_subtr_hist = 0; int __pyx_v_radius; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("getCirSubtr_i16 (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_img,&__pyx_n_s_subtr_hist,&__pyx_n_s_radius,0}; PyObject* values[3] = {0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_img)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_subtr_hist)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("getCirSubtr_i16", 1, 3, 3, 1); __PYX_ERR(0, 304, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_radius)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("getCirSubtr_i16", 1, 3, 3, 2); __PYX_ERR(0, 304, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "getCirSubtr_i16") < 0)) __PYX_ERR(0, 304, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); values[2] = PyTuple_GET_ITEM(__pyx_args, 2); } __pyx_v_img = ((PyArrayObject *)values[0]); __pyx_v_subtr_hist = ((PyArrayObject *)values[1]); __pyx_v_radius = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_radius == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 304, __pyx_L3_error) } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("getCirSubtr_i16", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 304, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("QF_utilities.getCirSubtr_i16", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_img), __pyx_ptype_5numpy_ndarray, 1, "img", 0))) __PYX_ERR(0, 304, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_subtr_hist), __pyx_ptype_5numpy_ndarray, 1, "subtr_hist", 0))) __PYX_ERR(0, 304, __pyx_L1_error) __pyx_r = __pyx_pf_12QF_utilities_14getCirSubtr_i16(__pyx_self, __pyx_v_img, __pyx_v_subtr_hist, __pyx_v_radius); /* function exit code */ goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_12QF_utilities_14getCirSubtr_i16(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_img, PyArrayObject *__pyx_v_subtr_hist, int __pyx_v_radius) { int __pyx_v_img_height; int __pyx_v_img_width; PyArrayObject *__pyx_v_result = 0; Py_ssize_t __pyx_v_x; Py_ssize_t __pyx_v_y; int __pyx_v_r; __pyx_t_5numpy_uint16_t __pyx_v_bgsub; __pyx_t_5numpy_uint16_t __pyx_v_val; __pyx_t_5numpy_uint16_t __pyx_v_zero; __Pyx_LocalBuf_ND __pyx_pybuffernd_img; __Pyx_Buffer __pyx_pybuffer_img; __Pyx_LocalBuf_ND __pyx_pybuffernd_result; __Pyx_Buffer __pyx_pybuffer_result; __Pyx_LocalBuf_ND __pyx_pybuffernd_subtr_hist; __Pyx_Buffer __pyx_pybuffer_subtr_hist; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("getCirSubtr_i16", 0); __pyx_pybuffer_result.pybuffer.buf = NULL; __pyx_pybuffer_result.refcount = 0; __pyx_pybuffernd_result.data = NULL; __pyx_pybuffernd_result.rcbuffer = &__pyx_pybuffer_result; __pyx_pybuffer_img.pybuffer.buf = NULL; __pyx_pybuffer_img.refcount = 0; __pyx_pybuffernd_img.data = NULL; __pyx_pybuffernd_img.rcbuffer = &__pyx_pybuffer_img; __pyx_pybuffer_subtr_hist.pybuffer.buf = NULL; __pyx_pybuffer_subtr_hist.refcount = 0; __pyx_pybuffernd_subtr_hist.data = NULL; __pyx_pybuffernd_subtr_hist.rcbuffer = &__pyx_pybuffer_subtr_hist; { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_img.rcbuffer->pybuffer, (PyObject*)__pyx_v_img, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint16_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 304, __pyx_L1_error) } __pyx_pybuffernd_img.diminfo[0].strides = __pyx_pybuffernd_img.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_img.diminfo[0].shape = __pyx_pybuffernd_img.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_img.diminfo[1].strides = __pyx_pybuffernd_img.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_img.diminfo[1].shape = __pyx_pybuffernd_img.rcbuffer->pybuffer.shape[1]; { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_subtr_hist.rcbuffer->pybuffer, (PyObject*)__pyx_v_subtr_hist, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint16_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 304, __pyx_L1_error) } __pyx_pybuffernd_subtr_hist.diminfo[0].strides = __pyx_pybuffernd_subtr_hist.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_subtr_hist.diminfo[0].shape = __pyx_pybuffernd_subtr_hist.rcbuffer->pybuffer.shape[0]; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; __Pyx_PyThreadState_declare __Pyx_PyThreadState_assign __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_img.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_result.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_subtr_hist.rcbuffer->pybuffer); __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} __Pyx_AddTraceback("QF_utilities.getCirSubtr_i16", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; goto __pyx_L2; __pyx_L0:; __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_img.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_result.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_subtr_hist.rcbuffer->pybuffer); __pyx_L2:; __Pyx_XDECREF((PyObject *)__pyx_v_result); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_tuple__22 = PyTuple_Pack(13, __pyx_n_s_img, __pyx_n_s_subtr_hist, __pyx_n_s_radius, __pyx_n_s_img_height, __pyx_n_s_img_width, __pyx_n_s_result, __pyx_n_s_x, __pyx_n_s_y, __pyx_n_s_r, __pyx_n_s_bgsub, __pyx_n_s_val, __pyx_n_s_min, __pyx_n_s_zero); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(0, 304, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__22); __Pyx_GIVEREF(__pyx_tuple__22); /* … */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_12QF_utilities_15getCirSubtr_i16, NULL, __pyx_n_s_QF_utilities); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 304, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_getCirSubtr_i16, __pyx_t_1) < 0) __PYX_ERR(0, 304, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_codeobj__23 = (PyObject*)__Pyx_PyCode_New(3, 0, 13, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__22, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_QF_utilities_pyx, __pyx_n_s_getCirSubtr_i16, 304, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__23)) __PYX_ERR(0, 304, __pyx_L1_error)
+305: cdef int img_height = img.shape[0]
__pyx_v_img_height = (__pyx_v_img->dimensions[0]);
+306: cdef int img_width = img.shape[1]
__pyx_v_img_width = (__pyx_v_img->dimensions[1]);
+307: cdef np.ndarray[np.uint16_t, ndim=2] result = np.zeros((img_height, img_width), dtype = np.uint16)
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 307, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 307, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_img_height); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 307, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_img_width); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 307, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 307, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); __pyx_t_1 = 0; __pyx_t_3 = 0; __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 307, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 307, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 307, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_uint16); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 307, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 307, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 307, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 307, __pyx_L1_error) __pyx_t_6 = ((PyArrayObject *)__pyx_t_5); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_result.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint16_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) { __pyx_v_result = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_result.rcbuffer->pybuffer.buf = NULL; __PYX_ERR(0, 307, __pyx_L1_error) } else {__pyx_pybuffernd_result.diminfo[0].strides = __pyx_pybuffernd_result.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_result.diminfo[0].shape = __pyx_pybuffernd_result.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_result.diminfo[1].strides = __pyx_pybuffernd_result.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_result.diminfo[1].shape = __pyx_pybuffernd_result.rcbuffer->pybuffer.shape[1]; } } __pyx_t_6 = 0; __pyx_v_result = ((PyArrayObject *)__pyx_t_5); __pyx_t_5 = 0;
308: cdef Py_ssize_t x, y
309: cdef int r
310: cdef np.uint16_t bgsub
311: cdef np.uint16_t val, min
+312: cdef np.uint16_t zero = 0
__pyx_v_zero = 0;
313:
+314: for x in range(img_width):
__pyx_t_7 = __pyx_v_img_width; for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) { __pyx_v_x = __pyx_t_8;
+315: for y in range(img_height):
__pyx_t_9 = __pyx_v_img_height; for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) { __pyx_v_y = __pyx_t_10;
+316: val = img[y,x]
__pyx_t_11 = __pyx_v_y; __pyx_t_12 = __pyx_v_x; __pyx_v_val = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_uint16_t *, __pyx_pybuffernd_img.rcbuffer->pybuffer.buf, __pyx_t_11, __pyx_pybuffernd_img.diminfo[0].strides, __pyx_t_12, __pyx_pybuffernd_img.diminfo[1].strides));
+317: bgsub = 0
__pyx_v_bgsub = 0;
+318: r = int(distance( x, y, img_width, img_height))
__pyx_v_r = ((int)__pyx_f_12QF_utilities_distance(__pyx_v_x, __pyx_v_y, __pyx_v_img_width, __pyx_v_img_height, 0));
+319: if radius > r:
__pyx_t_13 = ((__pyx_v_radius > __pyx_v_r) != 0); if (__pyx_t_13) { /* … */ }
+320: bgsub = subtr_hist[r]
__pyx_t_14 = __pyx_v_r; __pyx_v_bgsub = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_uint16_t *, __pyx_pybuffernd_subtr_hist.rcbuffer->pybuffer.buf, __pyx_t_14, __pyx_pybuffernd_subtr_hist.diminfo[0].strides));
321:
322: # result[y, x] = val - bgsub
+323: if bgsub <= val:
__pyx_t_13 = ((__pyx_v_bgsub <= __pyx_v_val) != 0); if (__pyx_t_13) { /* … */ goto __pyx_L8; }
+324: result[y,x] = val - bgsub
__pyx_t_15 = __pyx_v_y; __pyx_t_16 = __pyx_v_x; *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_uint16_t *, __pyx_pybuffernd_result.rcbuffer->pybuffer.buf, __pyx_t_15, __pyx_pybuffernd_result.diminfo[0].strides, __pyx_t_16, __pyx_pybuffernd_result.diminfo[1].strides) = (__pyx_v_val - __pyx_v_bgsub);
325: else:
+326: result[y,x] = zero
/*else*/ { __pyx_t_17 = __pyx_v_y; __pyx_t_18 = __pyx_v_x; *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_uint16_t *, __pyx_pybuffernd_result.rcbuffer->pybuffer.buf, __pyx_t_17, __pyx_pybuffernd_result.diminfo[0].strides, __pyx_t_18, __pyx_pybuffernd_result.diminfo[1].strides) = __pyx_v_zero; } __pyx_L8:; } }
+327: return result
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_result)); __pyx_r = ((PyObject *)__pyx_v_result); goto __pyx_L0;
328:
+329: def getCirSubtr_i8(np.ndarray[np.uint8_t, ndim=2] img, np.ndarray[np.uint8_t, ndim=1] subtr_hist, int radius):
/* Python wrapper */ static PyObject *__pyx_pw_12QF_utilities_17getCirSubtr_i8(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyMethodDef __pyx_mdef_12QF_utilities_17getCirSubtr_i8 = {"getCirSubtr_i8", (PyCFunction)__pyx_pw_12QF_utilities_17getCirSubtr_i8, METH_VARARGS|METH_KEYWORDS, 0}; static PyObject *__pyx_pw_12QF_utilities_17getCirSubtr_i8(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyArrayObject *__pyx_v_img = 0; PyArrayObject *__pyx_v_subtr_hist = 0; int __pyx_v_radius; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("getCirSubtr_i8 (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_img,&__pyx_n_s_subtr_hist,&__pyx_n_s_radius,0}; PyObject* values[3] = {0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_img)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_subtr_hist)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("getCirSubtr_i8", 1, 3, 3, 1); __PYX_ERR(0, 329, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_radius)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("getCirSubtr_i8", 1, 3, 3, 2); __PYX_ERR(0, 329, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "getCirSubtr_i8") < 0)) __PYX_ERR(0, 329, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); values[2] = PyTuple_GET_ITEM(__pyx_args, 2); } __pyx_v_img = ((PyArrayObject *)values[0]); __pyx_v_subtr_hist = ((PyArrayObject *)values[1]); __pyx_v_radius = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_radius == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 329, __pyx_L3_error) } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("getCirSubtr_i8", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 329, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("QF_utilities.getCirSubtr_i8", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_img), __pyx_ptype_5numpy_ndarray, 1, "img", 0))) __PYX_ERR(0, 329, __pyx_L1_error) if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_subtr_hist), __pyx_ptype_5numpy_ndarray, 1, "subtr_hist", 0))) __PYX_ERR(0, 329, __pyx_L1_error) __pyx_r = __pyx_pf_12QF_utilities_16getCirSubtr_i8(__pyx_self, __pyx_v_img, __pyx_v_subtr_hist, __pyx_v_radius); /* function exit code */ goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_12QF_utilities_16getCirSubtr_i8(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_img, PyArrayObject *__pyx_v_subtr_hist, int __pyx_v_radius) { int __pyx_v_img_height; int __pyx_v_img_width; PyArrayObject *__pyx_v_result = 0; Py_ssize_t __pyx_v_x; Py_ssize_t __pyx_v_y; int __pyx_v_r; __pyx_t_5numpy_uint8_t __pyx_v_bgsub; __pyx_t_5numpy_uint8_t __pyx_v_val; __pyx_t_5numpy_uint8_t __pyx_v_zero; __Pyx_LocalBuf_ND __pyx_pybuffernd_img; __Pyx_Buffer __pyx_pybuffer_img; __Pyx_LocalBuf_ND __pyx_pybuffernd_result; __Pyx_Buffer __pyx_pybuffer_result; __Pyx_LocalBuf_ND __pyx_pybuffernd_subtr_hist; __Pyx_Buffer __pyx_pybuffer_subtr_hist; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("getCirSubtr_i8", 0); __pyx_pybuffer_result.pybuffer.buf = NULL; __pyx_pybuffer_result.refcount = 0; __pyx_pybuffernd_result.data = NULL; __pyx_pybuffernd_result.rcbuffer = &__pyx_pybuffer_result; __pyx_pybuffer_img.pybuffer.buf = NULL; __pyx_pybuffer_img.refcount = 0; __pyx_pybuffernd_img.data = NULL; __pyx_pybuffernd_img.rcbuffer = &__pyx_pybuffer_img; __pyx_pybuffer_subtr_hist.pybuffer.buf = NULL; __pyx_pybuffer_subtr_hist.refcount = 0; __pyx_pybuffernd_subtr_hist.data = NULL; __pyx_pybuffernd_subtr_hist.rcbuffer = &__pyx_pybuffer_subtr_hist; { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_img.rcbuffer->pybuffer, (PyObject*)__pyx_v_img, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 329, __pyx_L1_error) } __pyx_pybuffernd_img.diminfo[0].strides = __pyx_pybuffernd_img.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_img.diminfo[0].shape = __pyx_pybuffernd_img.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_img.diminfo[1].strides = __pyx_pybuffernd_img.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_img.diminfo[1].shape = __pyx_pybuffernd_img.rcbuffer->pybuffer.shape[1]; { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_subtr_hist.rcbuffer->pybuffer, (PyObject*)__pyx_v_subtr_hist, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 329, __pyx_L1_error) } __pyx_pybuffernd_subtr_hist.diminfo[0].strides = __pyx_pybuffernd_subtr_hist.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_subtr_hist.diminfo[0].shape = __pyx_pybuffernd_subtr_hist.rcbuffer->pybuffer.shape[0]; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; __Pyx_PyThreadState_declare __Pyx_PyThreadState_assign __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_img.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_result.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_subtr_hist.rcbuffer->pybuffer); __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} __Pyx_AddTraceback("QF_utilities.getCirSubtr_i8", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; goto __pyx_L2; __pyx_L0:; __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_img.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_result.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_subtr_hist.rcbuffer->pybuffer); __pyx_L2:; __Pyx_XDECREF((PyObject *)__pyx_v_result); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_tuple__24 = PyTuple_Pack(13, __pyx_n_s_img, __pyx_n_s_subtr_hist, __pyx_n_s_radius, __pyx_n_s_img_height, __pyx_n_s_img_width, __pyx_n_s_result, __pyx_n_s_x, __pyx_n_s_y, __pyx_n_s_r, __pyx_n_s_bgsub, __pyx_n_s_val, __pyx_n_s_min, __pyx_n_s_zero); if (unlikely(!__pyx_tuple__24)) __PYX_ERR(0, 329, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__24); __Pyx_GIVEREF(__pyx_tuple__24); /* … */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_12QF_utilities_17getCirSubtr_i8, NULL, __pyx_n_s_QF_utilities); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 329, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_getCirSubtr_i8, __pyx_t_1) < 0) __PYX_ERR(0, 329, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_codeobj__25 = (PyObject*)__Pyx_PyCode_New(3, 0, 13, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__24, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_QF_utilities_pyx, __pyx_n_s_getCirSubtr_i8, 329, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__25)) __PYX_ERR(0, 329, __pyx_L1_error)
+330: cdef int img_height = img.shape[0]
__pyx_v_img_height = (__pyx_v_img->dimensions[0]);
+331: cdef int img_width = img.shape[1]
__pyx_v_img_width = (__pyx_v_img->dimensions[1]);
+332: cdef np.ndarray[np.uint8_t, ndim=2] result = np.zeros((img_height, img_width), dtype = np.uint8)
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 332, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 332, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_img_height); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 332, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_img_width); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 332, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 332, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); __pyx_t_1 = 0; __pyx_t_3 = 0; __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 332, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 332, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 332, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_uint8); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 332, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 332, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 332, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 332, __pyx_L1_error) __pyx_t_6 = ((PyArrayObject *)__pyx_t_5); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_result.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) { __pyx_v_result = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_result.rcbuffer->pybuffer.buf = NULL; __PYX_ERR(0, 332, __pyx_L1_error) } else {__pyx_pybuffernd_result.diminfo[0].strides = __pyx_pybuffernd_result.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_result.diminfo[0].shape = __pyx_pybuffernd_result.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_result.diminfo[1].strides = __pyx_pybuffernd_result.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_result.diminfo[1].shape = __pyx_pybuffernd_result.rcbuffer->pybuffer.shape[1]; } } __pyx_t_6 = 0; __pyx_v_result = ((PyArrayObject *)__pyx_t_5); __pyx_t_5 = 0;
333: cdef Py_ssize_t x, y
334: cdef int r
335: cdef np.uint8_t bgsub
336: cdef np.uint8_t val, min
+337: cdef np.uint8_t zero = 0
__pyx_v_zero = 0;
338:
+339: for x in range(img_width):
__pyx_t_7 = __pyx_v_img_width; for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) { __pyx_v_x = __pyx_t_8;
+340: for y in range(img_height):
__pyx_t_9 = __pyx_v_img_height; for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) { __pyx_v_y = __pyx_t_10;
+341: val = img[y,x]
__pyx_t_11 = __pyx_v_y; __pyx_t_12 = __pyx_v_x; __pyx_v_val = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_img.rcbuffer->pybuffer.buf, __pyx_t_11, __pyx_pybuffernd_img.diminfo[0].strides, __pyx_t_12, __pyx_pybuffernd_img.diminfo[1].strides));
+342: bgsub = 0
__pyx_v_bgsub = 0;
+343: r = int(distance( x, y, img_width, img_height))
__pyx_v_r = ((int)__pyx_f_12QF_utilities_distance(__pyx_v_x, __pyx_v_y, __pyx_v_img_width, __pyx_v_img_height, 0));
+344: if radius > r:
__pyx_t_13 = ((__pyx_v_radius > __pyx_v_r) != 0); if (__pyx_t_13) { /* … */ }
+345: bgsub = subtr_hist[r]
__pyx_t_14 = __pyx_v_r; __pyx_v_bgsub = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_subtr_hist.rcbuffer->pybuffer.buf, __pyx_t_14, __pyx_pybuffernd_subtr_hist.diminfo[0].strides));
346:
347: # result[y, x] = val - bgsub
+348: if bgsub <= val:
__pyx_t_13 = ((__pyx_v_bgsub <= __pyx_v_val) != 0); if (__pyx_t_13) { /* … */ goto __pyx_L8; }
+349: result[y,x] = val - bgsub
__pyx_t_15 = __pyx_v_y; __pyx_t_16 = __pyx_v_x; *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_result.rcbuffer->pybuffer.buf, __pyx_t_15, __pyx_pybuffernd_result.diminfo[0].strides, __pyx_t_16, __pyx_pybuffernd_result.diminfo[1].strides) = (__pyx_v_val - __pyx_v_bgsub);
350: else:
+351: result[y,x] = zero
/*else*/ { __pyx_t_17 = __pyx_v_y; __pyx_t_18 = __pyx_v_x; *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_result.rcbuffer->pybuffer.buf, __pyx_t_17, __pyx_pybuffernd_result.diminfo[0].strides, __pyx_t_18, __pyx_pybuffernd_result.diminfo[1].strides) = __pyx_v_zero; } __pyx_L8:; } }
+352: return result
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_result)); __pyx_r = ((PyObject *)__pyx_v_result); goto __pyx_L0;
353:
354: from libc.math cimport abs, M_PI
355: from libc.math cimport round
356: from libc.math cimport atan
357: from libc.math cimport floor
358: from libc.math cimport ceil
359: # from numpy.math cimport rad2deg
360:
361: @cython.cdivision(True)
+362: def make2DConvexhullBG(np.ndarray[np.float32_t, ndim=2] pchipLines, int width, int height, int centerX, int centerY, int rmin, int rmax):
/* Python wrapper */ static PyObject *__pyx_pw_12QF_utilities_19make2DConvexhullBG(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyMethodDef __pyx_mdef_12QF_utilities_19make2DConvexhullBG = {"make2DConvexhullBG", (PyCFunction)__pyx_pw_12QF_utilities_19make2DConvexhullBG, METH_VARARGS|METH_KEYWORDS, 0}; static PyObject *__pyx_pw_12QF_utilities_19make2DConvexhullBG(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyArrayObject *__pyx_v_pchipLines = 0; int __pyx_v_width; int __pyx_v_height; int __pyx_v_centerX; int __pyx_v_centerY; int __pyx_v_rmin; int __pyx_v_rmax; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("make2DConvexhullBG (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pchipLines,&__pyx_n_s_width,&__pyx_n_s_height,&__pyx_n_s_centerX,&__pyx_n_s_centerY,&__pyx_n_s_rmin,&__pyx_n_s_rmax,0}; PyObject* values[7] = {0,0,0,0,0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); CYTHON_FALLTHROUGH; case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); CYTHON_FALLTHROUGH; case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); CYTHON_FALLTHROUGH; case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); CYTHON_FALLTHROUGH; case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_pchipLines)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_width)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("make2DConvexhullBG", 1, 7, 7, 1); __PYX_ERR(0, 362, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_height)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("make2DConvexhullBG", 1, 7, 7, 2); __PYX_ERR(0, 362, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 3: if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_centerX)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("make2DConvexhullBG", 1, 7, 7, 3); __PYX_ERR(0, 362, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 4: if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_centerY)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("make2DConvexhullBG", 1, 7, 7, 4); __PYX_ERR(0, 362, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 5: if (likely((values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_rmin)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("make2DConvexhullBG", 1, 7, 7, 5); __PYX_ERR(0, 362, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 6: if (likely((values[6] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_rmax)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("make2DConvexhullBG", 1, 7, 7, 6); __PYX_ERR(0, 362, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "make2DConvexhullBG") < 0)) __PYX_ERR(0, 362, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 7) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); values[2] = PyTuple_GET_ITEM(__pyx_args, 2); values[3] = PyTuple_GET_ITEM(__pyx_args, 3); values[4] = PyTuple_GET_ITEM(__pyx_args, 4); values[5] = PyTuple_GET_ITEM(__pyx_args, 5); values[6] = PyTuple_GET_ITEM(__pyx_args, 6); } __pyx_v_pchipLines = ((PyArrayObject *)values[0]); __pyx_v_width = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_width == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 362, __pyx_L3_error) __pyx_v_height = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_height == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 362, __pyx_L3_error) __pyx_v_centerX = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_centerX == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 362, __pyx_L3_error) __pyx_v_centerY = __Pyx_PyInt_As_int(values[4]); if (unlikely((__pyx_v_centerY == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 362, __pyx_L3_error) __pyx_v_rmin = __Pyx_PyInt_As_int(values[5]); if (unlikely((__pyx_v_rmin == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 362, __pyx_L3_error) __pyx_v_rmax = __Pyx_PyInt_As_int(values[6]); if (unlikely((__pyx_v_rmax == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 362, __pyx_L3_error) } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("make2DConvexhullBG", 1, 7, 7, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 362, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("QF_utilities.make2DConvexhullBG", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_pchipLines), __pyx_ptype_5numpy_ndarray, 1, "pchipLines", 0))) __PYX_ERR(0, 362, __pyx_L1_error) __pyx_r = __pyx_pf_12QF_utilities_18make2DConvexhullBG(__pyx_self, __pyx_v_pchipLines, __pyx_v_width, __pyx_v_height, __pyx_v_centerX, __pyx_v_centerY, __pyx_v_rmin, __pyx_v_rmax); /* function exit code */ goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_12QF_utilities_18make2DConvexhullBG(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_pchipLines, int __pyx_v_width, int __pyx_v_height, int __pyx_v_centerX, int __pyx_v_centerY, int __pyx_v_rmin, int __pyx_v_rmax) { PyArrayObject *__pyx_v_backgound = 0; int __pyx_v_x; int __pyx_v_y; int __pyx_v_irad; int __pyx_v_irad_floor; int __pyx_v_irad_ceil; __pyx_t_5numpy_float32_t __pyx_v_deg; __pyx_t_5numpy_float32_t __pyx_v_slope; __pyx_t_5numpy_float32_t __pyx_v_floor_deg; __pyx_t_5numpy_float32_t __pyx_v_alpha; __pyx_t_5numpy_float32_t __pyx_v_ceil_deg; __pyx_t_5numpy_float32_t __pyx_v_beta; __pyx_t_5numpy_float32_t __pyx_v_round_deg; __pyx_t_5numpy_float32_t __pyx_v_deltay; __pyx_t_5numpy_float32_t __pyx_v_deltax; __pyx_t_5numpy_float32_t __pyx_v_tmpdeg; __pyx_t_5numpy_float32_t __pyx_v_rad; __pyx_t_5numpy_float32_t __pyx_v_ceil_rad; __pyx_t_5numpy_float32_t __pyx_v_floor_rad; __pyx_t_5numpy_float32_t __pyx_v_alpha_rad; __pyx_t_5numpy_float32_t __pyx_v_beta_rad; __pyx_t_5numpy_float32_t __pyx_v_zero; CYTHON_UNUSED int __pyx_v_intzero; int __pyx_v_pos1; int __pyx_v_pos2; int __pyx_v_ifloor; int __pyx_v_iceil; int __pyx_v_ideg; __Pyx_LocalBuf_ND __pyx_pybuffernd_backgound; __Pyx_Buffer __pyx_pybuffer_backgound; __Pyx_LocalBuf_ND __pyx_pybuffernd_pchipLines; __Pyx_Buffer __pyx_pybuffer_pchipLines; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("make2DConvexhullBG", 0); __pyx_pybuffer_backgound.pybuffer.buf = NULL; __pyx_pybuffer_backgound.refcount = 0; __pyx_pybuffernd_backgound.data = NULL; __pyx_pybuffernd_backgound.rcbuffer = &__pyx_pybuffer_backgound; __pyx_pybuffer_pchipLines.pybuffer.buf = NULL; __pyx_pybuffer_pchipLines.refcount = 0; __pyx_pybuffernd_pchipLines.data = NULL; __pyx_pybuffernd_pchipLines.rcbuffer = &__pyx_pybuffer_pchipLines; { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_pchipLines.rcbuffer->pybuffer, (PyObject*)__pyx_v_pchipLines, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 362, __pyx_L1_error) } __pyx_pybuffernd_pchipLines.diminfo[0].strides = __pyx_pybuffernd_pchipLines.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_pchipLines.diminfo[0].shape = __pyx_pybuffernd_pchipLines.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_pchipLines.diminfo[1].strides = __pyx_pybuffernd_pchipLines.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_pchipLines.diminfo[1].shape = __pyx_pybuffernd_pchipLines.rcbuffer->pybuffer.shape[1]; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; __Pyx_PyThreadState_declare __Pyx_PyThreadState_assign __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_backgound.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_pchipLines.rcbuffer->pybuffer); __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} __Pyx_AddTraceback("QF_utilities.make2DConvexhullBG", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; goto __pyx_L2; __pyx_L0:; __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_backgound.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_pchipLines.rcbuffer->pybuffer); __pyx_L2:; __Pyx_XDECREF((PyObject *)__pyx_v_backgound); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_tuple__26 = PyTuple_Pack(36, __pyx_n_s_pchipLines, __pyx_n_s_width, __pyx_n_s_height, __pyx_n_s_centerX, __pyx_n_s_centerY, __pyx_n_s_rmin, __pyx_n_s_rmax, __pyx_n_s_backgound, __pyx_n_s_x, __pyx_n_s_y, __pyx_n_s_irad, __pyx_n_s_irad_floor, __pyx_n_s_irad_ceil, __pyx_n_s_deg, __pyx_n_s_slope, __pyx_n_s_floor_deg, __pyx_n_s_alpha, __pyx_n_s_ceil_deg, __pyx_n_s_beta, __pyx_n_s_round_deg, __pyx_n_s_deltay, __pyx_n_s_deltax, __pyx_n_s_subv, __pyx_n_s_tmpdeg, __pyx_n_s_rad, __pyx_n_s_ceil_rad, __pyx_n_s_floor_rad, __pyx_n_s_alpha_rad, __pyx_n_s_beta_rad, __pyx_n_s_zero, __pyx_n_s_intzero, __pyx_n_s_pos1, __pyx_n_s_pos2, __pyx_n_s_ifloor, __pyx_n_s_iceil, __pyx_n_s_ideg); if (unlikely(!__pyx_tuple__26)) __PYX_ERR(0, 362, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__26); __Pyx_GIVEREF(__pyx_tuple__26); /* … */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_12QF_utilities_19make2DConvexhullBG, NULL, __pyx_n_s_QF_utilities); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 362, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_make2DConvexhullBG, __pyx_t_1) < 0) __PYX_ERR(0, 362, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_codeobj__27 = (PyObject*)__Pyx_PyCode_New(7, 0, 36, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__26, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_QF_utilities_pyx, __pyx_n_s_make2DConvexhullBG, 362, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__27)) __PYX_ERR(0, 362, __pyx_L1_error)
+363: cdef np.ndarray[np.float32_t, ndim=2] backgound = np.zeros((height, width), dtype = np.float32)
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 363, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 363, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_height); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 363, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_width); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 363, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 363, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); __pyx_t_1 = 0; __pyx_t_3 = 0; __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 363, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 363, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 363, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_float32); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 363, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 363, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 363, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 363, __pyx_L1_error) __pyx_t_6 = ((PyArrayObject *)__pyx_t_5); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_backgound.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) { __pyx_v_backgound = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_backgound.rcbuffer->pybuffer.buf = NULL; __PYX_ERR(0, 363, __pyx_L1_error) } else {__pyx_pybuffernd_backgound.diminfo[0].strides = __pyx_pybuffernd_backgound.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_backgound.diminfo[0].shape = __pyx_pybuffernd_backgound.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_backgound.diminfo[1].strides = __pyx_pybuffernd_backgound.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_backgound.diminfo[1].shape = __pyx_pybuffernd_backgound.rcbuffer->pybuffer.shape[1]; } } __pyx_t_6 = 0; __pyx_v_backgound = ((PyArrayObject *)__pyx_t_5); __pyx_t_5 = 0;
364: cdef int x, y
365: cdef int irad, irad_floor, irad_ceil
366: cdef np.float32_t deg, slope, floor_deg, alpha, ceil_deg, beta, round_deg, deltay, deltax, subv, tmpdeg
367: cdef np.float32_t rad, ceil_rad, floor_rad, alpha_rad, beta_rad
+368: cdef np.float32_t zero = 0.0
__pyx_v_zero = 0.0;
+369: cdef int intzero = 0
__pyx_v_intzero = 0;
370: cdef int pos1, pos2
371: cdef int ifloor, iceil, ideg
372:
+373: for x in range(width):
__pyx_t_7 = __pyx_v_width; for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) { __pyx_v_x = __pyx_t_8;
+374: for y in range(height):
__pyx_t_9 = __pyx_v_height; for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) { __pyx_v_y = __pyx_t_10;
+375: deltax = float(abs(x - centerX))
__pyx_t_11 = abs((__pyx_v_x - __pyx_v_centerX)); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 375, __pyx_L1_error)
__pyx_v_deltax = ((double)__pyx_t_11);
+376: if deltax == zero:
__pyx_t_12 = ((__pyx_v_deltax == __pyx_v_zero) != 0); if (__pyx_t_12) { /* … */ goto __pyx_L7; }
+377: deg = 90.0
__pyx_v_deg = 90.0;
378: else:
+379: deltay = float(abs(y - centerY))
/*else*/ {
__pyx_t_11 = abs((__pyx_v_y - __pyx_v_centerY)); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 379, __pyx_L1_error)
__pyx_v_deltay = ((double)__pyx_t_11);
+380: slope = deltay / deltax
__pyx_v_slope = (__pyx_v_deltay / __pyx_v_deltax);
+381: deg = atan(slope)*180.0/M_PI
__pyx_v_deg = ((atan(__pyx_v_slope) * 180.0) / M_PI); } __pyx_L7:;
382:
+383: rad = distance(centerX, centerY, x, y)
__pyx_v_rad = __pyx_f_12QF_utilities_distance(__pyx_v_centerX, __pyx_v_centerY, __pyx_v_x, __pyx_v_y, 0);
+384: irad = int(round(rad))
__pyx_v_irad = ((int)round(__pyx_v_rad));
+385: ceil_rad = ceil(rad)
__pyx_v_ceil_rad = ceil(__pyx_v_rad);
+386: floor_rad = floor(rad)
__pyx_v_floor_rad = floor(__pyx_v_rad);
+387: irad_ceil = int(ceil_rad)
__pyx_v_irad_ceil = ((int)__pyx_v_ceil_rad);
+388: irad_floor = int(floor_rad)
__pyx_v_irad_floor = ((int)__pyx_v_floor_rad);
+389: alpha_rad = 1. - (rad-floor_rad)
__pyx_v_alpha_rad = (1. - (__pyx_v_rad - __pyx_v_floor_rad));
+390: beta_rad = 1. - (ceil_rad-rad)
__pyx_v_beta_rad = (1. - (__pyx_v_ceil_rad - __pyx_v_rad));
391:
+392: round_deg = round(deg)
__pyx_v_round_deg = round(__pyx_v_deg);
393:
+394: if round_deg < deg:
__pyx_t_12 = ((__pyx_v_round_deg < __pyx_v_deg) != 0); if (__pyx_t_12) { /* … */ goto __pyx_L8; }
+395: ceil_deg = round_deg + 0.5
__pyx_v_ceil_deg = (__pyx_v_round_deg + 0.5);
+396: floor_deg = round_deg
__pyx_v_floor_deg = __pyx_v_round_deg;
+397: elif round_deg > deg:
__pyx_t_12 = ((__pyx_v_round_deg > __pyx_v_deg) != 0); if (__pyx_t_12) { /* … */ goto __pyx_L8; }
+398: ceil_deg = round_deg
__pyx_v_ceil_deg = __pyx_v_round_deg;
+399: floor_deg = round_deg - 0.5
__pyx_v_floor_deg = (__pyx_v_round_deg - 0.5);
400: else:
+401: ceil_deg = round_deg
/*else*/ { __pyx_v_ceil_deg = __pyx_v_round_deg;
+402: floor_deg = round_deg
__pyx_v_floor_deg = __pyx_v_round_deg; } __pyx_L8:;
403:
404: # alpha = 1. - ((deg - floor_deg) * 2.0)
405: # beta = 1. - ((ceil_deg - deg) * 2.0)
406:
+407: ifloor = int(floor_deg / 0.5)
__pyx_v_ifloor = ((int)(__pyx_v_floor_deg / 0.5));
+408: iceil = int(ceil_deg / 0.5)
__pyx_v_iceil = ((int)(__pyx_v_ceil_deg / 0.5));
+409: tmpdeg = deg/0.5
__pyx_v_tmpdeg = (__pyx_v_deg / 0.5);
+410: alpha = 1. - (tmpdeg - floor_deg / 0.5)
__pyx_v_alpha = (1. - (__pyx_v_tmpdeg - (__pyx_v_floor_deg / 0.5)));
+411: beta = 1. - (ceil_deg / 0.5 - tmpdeg)
__pyx_v_beta = (1. - ((__pyx_v_ceil_deg / 0.5) - __pyx_v_tmpdeg));
+412: ideg = int(round(deg/0.5))
__pyx_v_ideg = ((int)round((__pyx_v_deg / 0.5)));
413:
+414: if irad_ceil <= rmax and irad_floor >= rmin:
__pyx_t_13 = ((__pyx_v_irad_ceil <= __pyx_v_rmax) != 0); if (__pyx_t_13) { } else { __pyx_t_12 = __pyx_t_13; goto __pyx_L10_bool_binop_done; } __pyx_t_13 = ((__pyx_v_irad_floor >= __pyx_v_rmin) != 0); __pyx_t_12 = __pyx_t_13; __pyx_L10_bool_binop_done:; if (__pyx_t_12) { /* … */ } } }
+415: if alpha == 1. and beta == 1.:
__pyx_t_13 = ((__pyx_v_alpha == 1.) != 0); if (__pyx_t_13) { } else { __pyx_t_12 = __pyx_t_13; goto __pyx_L13_bool_binop_done; } __pyx_t_13 = ((__pyx_v_beta == 1.) != 0); __pyx_t_12 = __pyx_t_13; __pyx_L13_bool_binop_done:; if (__pyx_t_12) { /* … */ goto __pyx_L12; }
+416: if alpha_rad == 1. and beta_rad == 1.:
__pyx_t_13 = ((__pyx_v_alpha_rad == 1.) != 0); if (__pyx_t_13) { } else { __pyx_t_12 = __pyx_t_13; goto __pyx_L16_bool_binop_done; } __pyx_t_13 = ((__pyx_v_beta_rad == 1.) != 0); __pyx_t_12 = __pyx_t_13; __pyx_L16_bool_binop_done:; if (__pyx_t_12) { /* … */ goto __pyx_L15; }
+417: pos1 = irad - rmin
__pyx_v_pos1 = (__pyx_v_irad - __pyx_v_rmin);
+418: backgound[y,x] = pchipLines[ideg, pos1]
__pyx_t_14 = __pyx_v_ideg; __pyx_t_15 = __pyx_v_pos1; __pyx_t_16 = __pyx_v_y; __pyx_t_17 = __pyx_v_x; *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_backgound.rcbuffer->pybuffer.buf, __pyx_t_16, __pyx_pybuffernd_backgound.diminfo[0].strides, __pyx_t_17, __pyx_pybuffernd_backgound.diminfo[1].strides) = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_pchipLines.rcbuffer->pybuffer.buf, __pyx_t_14, __pyx_pybuffernd_pchipLines.diminfo[0].strides, __pyx_t_15, __pyx_pybuffernd_pchipLines.diminfo[1].strides));
419: else:
+420: pos1 = irad_floor - rmin
/*else*/ { __pyx_v_pos1 = (__pyx_v_irad_floor - __pyx_v_rmin);
+421: pos2 = irad_ceil - rmin
__pyx_v_pos2 = (__pyx_v_irad_ceil - __pyx_v_rmin);
+422: backgound[y, x] = alpha_rad * pchipLines[ideg, pos1] + beta_rad * pchipLines[ideg, pos2]
__pyx_t_18 = __pyx_v_ideg; __pyx_t_19 = __pyx_v_pos1; __pyx_t_20 = __pyx_v_ideg; __pyx_t_21 = __pyx_v_pos2; __pyx_t_22 = __pyx_v_y; __pyx_t_23 = __pyx_v_x; *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_backgound.rcbuffer->pybuffer.buf, __pyx_t_22, __pyx_pybuffernd_backgound.diminfo[0].strides, __pyx_t_23, __pyx_pybuffernd_backgound.diminfo[1].strides) = ((__pyx_v_alpha_rad * (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_pchipLines.rcbuffer->pybuffer.buf, __pyx_t_18, __pyx_pybuffernd_pchipLines.diminfo[0].strides, __pyx_t_19, __pyx_pybuffernd_pchipLines.diminfo[1].strides))) + (__pyx_v_beta_rad * (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_pchipLines.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_pchipLines.diminfo[0].strides, __pyx_t_21, __pyx_pybuffernd_pchipLines.diminfo[1].strides)))); } __pyx_L15:;
423: else:
+424: if alpha_rad == 1. and beta_rad == 1.:
/*else*/ { __pyx_t_13 = ((__pyx_v_alpha_rad == 1.) != 0); if (__pyx_t_13) { } else { __pyx_t_12 = __pyx_t_13; goto __pyx_L19_bool_binop_done; } __pyx_t_13 = ((__pyx_v_beta_rad == 1.) != 0); __pyx_t_12 = __pyx_t_13; __pyx_L19_bool_binop_done:; if (__pyx_t_12) { /* … */ goto __pyx_L18; }
+425: pos1 = irad - rmin
__pyx_v_pos1 = (__pyx_v_irad - __pyx_v_rmin);
+426: backgound[y,x] = alpha * pchipLines[ifloor, pos1] + beta * pchipLines[iceil, pos1]
__pyx_t_24 = __pyx_v_ifloor; __pyx_t_25 = __pyx_v_pos1; __pyx_t_26 = __pyx_v_iceil; __pyx_t_27 = __pyx_v_pos1; __pyx_t_28 = __pyx_v_y; __pyx_t_29 = __pyx_v_x; *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_backgound.rcbuffer->pybuffer.buf, __pyx_t_28, __pyx_pybuffernd_backgound.diminfo[0].strides, __pyx_t_29, __pyx_pybuffernd_backgound.diminfo[1].strides) = ((__pyx_v_alpha * (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_pchipLines.rcbuffer->pybuffer.buf, __pyx_t_24, __pyx_pybuffernd_pchipLines.diminfo[0].strides, __pyx_t_25, __pyx_pybuffernd_pchipLines.diminfo[1].strides))) + (__pyx_v_beta * (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_pchipLines.rcbuffer->pybuffer.buf, __pyx_t_26, __pyx_pybuffernd_pchipLines.diminfo[0].strides, __pyx_t_27, __pyx_pybuffernd_pchipLines.diminfo[1].strides))));
427: else:
+428: pos1 = irad_floor - rmin
/*else*/ { __pyx_v_pos1 = (__pyx_v_irad_floor - __pyx_v_rmin);
+429: pos2 = irad_ceil - rmin
__pyx_v_pos2 = (__pyx_v_irad_ceil - __pyx_v_rmin);
+430: backgound[y, x] = alpha * (alpha_rad * pchipLines[ifloor, pos1] + beta_rad * pchipLines[ifloor, pos2]) \
__pyx_t_30 = __pyx_v_ifloor; __pyx_t_31 = __pyx_v_pos1; __pyx_t_32 = __pyx_v_ifloor; __pyx_t_33 = __pyx_v_pos2; /* … */ __pyx_t_38 = __pyx_v_y; __pyx_t_39 = __pyx_v_x; *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_backgound.rcbuffer->pybuffer.buf, __pyx_t_38, __pyx_pybuffernd_backgound.diminfo[0].strides, __pyx_t_39, __pyx_pybuffernd_backgound.diminfo[1].strides) = ((__pyx_v_alpha * ((__pyx_v_alpha_rad * (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_pchipLines.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_pchipLines.diminfo[0].strides, __pyx_t_31, __pyx_pybuffernd_pchipLines.diminfo[1].strides))) + (__pyx_v_beta_rad * (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_pchipLines.rcbuffer->pybuffer.buf, __pyx_t_32, __pyx_pybuffernd_pchipLines.diminfo[0].strides, __pyx_t_33, __pyx_pybuffernd_pchipLines.diminfo[1].strides))))) + (__pyx_v_beta * ((__pyx_v_alpha_rad * (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_pchipLines.rcbuffer->pybuffer.buf, __pyx_t_34, __pyx_pybuffernd_pchipLines.diminfo[0].strides, __pyx_t_35, __pyx_pybuffernd_pchipLines.diminfo[1].strides))) + (__pyx_v_beta_rad * (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_pchipLines.rcbuffer->pybuffer.buf, __pyx_t_36, __pyx_pybuffernd_pchipLines.diminfo[0].strides, __pyx_t_37, __pyx_pybuffernd_pchipLines.diminfo[1].strides)))))); } __pyx_L18:; } __pyx_L12:;
+431: + beta * (alpha_rad * pchipLines[iceil, pos1] + beta_rad * pchipLines[iceil, pos2])
__pyx_t_34 = __pyx_v_iceil; __pyx_t_35 = __pyx_v_pos1; __pyx_t_36 = __pyx_v_iceil; __pyx_t_37 = __pyx_v_pos2;
+432: return backgound
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_backgound)); __pyx_r = ((PyObject *)__pyx_v_backgound); goto __pyx_L0;
433:
434: @cython.cdivision(True)
+435: def make2DConvexhullBG2(np.ndarray[np.float32_t, ndim=2] pchipLines, int width, int height, int centerX, int centerY, int rmin, int rmax):
/* Python wrapper */ static PyObject *__pyx_pw_12QF_utilities_21make2DConvexhullBG2(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyMethodDef __pyx_mdef_12QF_utilities_21make2DConvexhullBG2 = {"make2DConvexhullBG2", (PyCFunction)__pyx_pw_12QF_utilities_21make2DConvexhullBG2, METH_VARARGS|METH_KEYWORDS, 0}; static PyObject *__pyx_pw_12QF_utilities_21make2DConvexhullBG2(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyArrayObject *__pyx_v_pchipLines = 0; int __pyx_v_width; int __pyx_v_height; int __pyx_v_centerX; int __pyx_v_centerY; int __pyx_v_rmin; int __pyx_v_rmax; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("make2DConvexhullBG2 (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pchipLines,&__pyx_n_s_width,&__pyx_n_s_height,&__pyx_n_s_centerX,&__pyx_n_s_centerY,&__pyx_n_s_rmin,&__pyx_n_s_rmax,0}; PyObject* values[7] = {0,0,0,0,0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); CYTHON_FALLTHROUGH; case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); CYTHON_FALLTHROUGH; case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); CYTHON_FALLTHROUGH; case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); CYTHON_FALLTHROUGH; case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_pchipLines)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_width)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("make2DConvexhullBG2", 1, 7, 7, 1); __PYX_ERR(0, 435, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_height)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("make2DConvexhullBG2", 1, 7, 7, 2); __PYX_ERR(0, 435, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 3: if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_centerX)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("make2DConvexhullBG2", 1, 7, 7, 3); __PYX_ERR(0, 435, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 4: if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_centerY)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("make2DConvexhullBG2", 1, 7, 7, 4); __PYX_ERR(0, 435, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 5: if (likely((values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_rmin)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("make2DConvexhullBG2", 1, 7, 7, 5); __PYX_ERR(0, 435, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 6: if (likely((values[6] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_rmax)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("make2DConvexhullBG2", 1, 7, 7, 6); __PYX_ERR(0, 435, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "make2DConvexhullBG2") < 0)) __PYX_ERR(0, 435, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 7) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); values[2] = PyTuple_GET_ITEM(__pyx_args, 2); values[3] = PyTuple_GET_ITEM(__pyx_args, 3); values[4] = PyTuple_GET_ITEM(__pyx_args, 4); values[5] = PyTuple_GET_ITEM(__pyx_args, 5); values[6] = PyTuple_GET_ITEM(__pyx_args, 6); } __pyx_v_pchipLines = ((PyArrayObject *)values[0]); __pyx_v_width = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_width == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 435, __pyx_L3_error) __pyx_v_height = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_height == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 435, __pyx_L3_error) __pyx_v_centerX = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_centerX == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 435, __pyx_L3_error) __pyx_v_centerY = __Pyx_PyInt_As_int(values[4]); if (unlikely((__pyx_v_centerY == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 435, __pyx_L3_error) __pyx_v_rmin = __Pyx_PyInt_As_int(values[5]); if (unlikely((__pyx_v_rmin == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 435, __pyx_L3_error) __pyx_v_rmax = __Pyx_PyInt_As_int(values[6]); if (unlikely((__pyx_v_rmax == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 435, __pyx_L3_error) } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("make2DConvexhullBG2", 1, 7, 7, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 435, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("QF_utilities.make2DConvexhullBG2", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_pchipLines), __pyx_ptype_5numpy_ndarray, 1, "pchipLines", 0))) __PYX_ERR(0, 435, __pyx_L1_error) __pyx_r = __pyx_pf_12QF_utilities_20make2DConvexhullBG2(__pyx_self, __pyx_v_pchipLines, __pyx_v_width, __pyx_v_height, __pyx_v_centerX, __pyx_v_centerY, __pyx_v_rmin, __pyx_v_rmax); /* function exit code */ goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_12QF_utilities_20make2DConvexhullBG2(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_pchipLines, int __pyx_v_width, int __pyx_v_height, int __pyx_v_centerX, int __pyx_v_centerY, int __pyx_v_rmin, int __pyx_v_rmax) { PyArrayObject *__pyx_v_backgound = 0; int __pyx_v_x; int __pyx_v_y; CYTHON_UNUSED int __pyx_v_irad; int __pyx_v_irad_floor; int __pyx_v_irad_ceil; __pyx_t_5numpy_float32_t __pyx_v_deg; __pyx_t_5numpy_float32_t __pyx_v_slope; __pyx_t_5numpy_float32_t __pyx_v_floor_deg; __pyx_t_5numpy_float32_t __pyx_v_alpha; __pyx_t_5numpy_float32_t __pyx_v_ceil_deg; __pyx_t_5numpy_float32_t __pyx_v_beta; __pyx_t_5numpy_float32_t __pyx_v_deltay; __pyx_t_5numpy_float32_t __pyx_v_deltax; __pyx_t_5numpy_float32_t __pyx_v_rad; __pyx_t_5numpy_float32_t __pyx_v_ceil_rad; __pyx_t_5numpy_float32_t __pyx_v_floor_rad; __pyx_t_5numpy_float32_t __pyx_v_alpha_rad; __pyx_t_5numpy_float32_t __pyx_v_beta_rad; __pyx_t_5numpy_float32_t __pyx_v_zero; CYTHON_UNUSED int __pyx_v_intzero; int __pyx_v_pos1; int __pyx_v_pos2; int __pyx_v_ifloor; int __pyx_v_iceil; CYTHON_UNUSED int __pyx_v_ideg; __Pyx_LocalBuf_ND __pyx_pybuffernd_backgound; __Pyx_Buffer __pyx_pybuffer_backgound; __Pyx_LocalBuf_ND __pyx_pybuffernd_pchipLines; __Pyx_Buffer __pyx_pybuffer_pchipLines; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("make2DConvexhullBG2", 0); __pyx_pybuffer_backgound.pybuffer.buf = NULL; __pyx_pybuffer_backgound.refcount = 0; __pyx_pybuffernd_backgound.data = NULL; __pyx_pybuffernd_backgound.rcbuffer = &__pyx_pybuffer_backgound; __pyx_pybuffer_pchipLines.pybuffer.buf = NULL; __pyx_pybuffer_pchipLines.refcount = 0; __pyx_pybuffernd_pchipLines.data = NULL; __pyx_pybuffernd_pchipLines.rcbuffer = &__pyx_pybuffer_pchipLines; { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_pchipLines.rcbuffer->pybuffer, (PyObject*)__pyx_v_pchipLines, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 435, __pyx_L1_error) } __pyx_pybuffernd_pchipLines.diminfo[0].strides = __pyx_pybuffernd_pchipLines.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_pchipLines.diminfo[0].shape = __pyx_pybuffernd_pchipLines.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_pchipLines.diminfo[1].strides = __pyx_pybuffernd_pchipLines.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_pchipLines.diminfo[1].shape = __pyx_pybuffernd_pchipLines.rcbuffer->pybuffer.shape[1]; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; __Pyx_PyThreadState_declare __Pyx_PyThreadState_assign __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_backgound.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_pchipLines.rcbuffer->pybuffer); __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} __Pyx_AddTraceback("QF_utilities.make2DConvexhullBG2", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; goto __pyx_L2; __pyx_L0:; __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_backgound.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_pchipLines.rcbuffer->pybuffer); __pyx_L2:; __Pyx_XDECREF((PyObject *)__pyx_v_backgound); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_tuple__28 = PyTuple_Pack(36, __pyx_n_s_pchipLines, __pyx_n_s_width, __pyx_n_s_height, __pyx_n_s_centerX, __pyx_n_s_centerY, __pyx_n_s_rmin, __pyx_n_s_rmax, __pyx_n_s_backgound, __pyx_n_s_x, __pyx_n_s_y, __pyx_n_s_irad, __pyx_n_s_irad_floor, __pyx_n_s_irad_ceil, __pyx_n_s_deg, __pyx_n_s_slope, __pyx_n_s_floor_deg, __pyx_n_s_alpha, __pyx_n_s_ceil_deg, __pyx_n_s_beta, __pyx_n_s_round_deg, __pyx_n_s_deltay, __pyx_n_s_deltax, __pyx_n_s_subv, __pyx_n_s_tmpdeg, __pyx_n_s_rad, __pyx_n_s_ceil_rad, __pyx_n_s_floor_rad, __pyx_n_s_alpha_rad, __pyx_n_s_beta_rad, __pyx_n_s_zero, __pyx_n_s_intzero, __pyx_n_s_pos1, __pyx_n_s_pos2, __pyx_n_s_ifloor, __pyx_n_s_iceil, __pyx_n_s_ideg); if (unlikely(!__pyx_tuple__28)) __PYX_ERR(0, 435, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__28); __Pyx_GIVEREF(__pyx_tuple__28); /* … */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_12QF_utilities_21make2DConvexhullBG2, NULL, __pyx_n_s_QF_utilities); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 435, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_make2DConvexhullBG2, __pyx_t_1) < 0) __PYX_ERR(0, 435, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_codeobj__29 = (PyObject*)__Pyx_PyCode_New(7, 0, 36, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__28, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_QF_utilities_pyx, __pyx_n_s_make2DConvexhullBG2, 435, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__29)) __PYX_ERR(0, 435, __pyx_L1_error)
+436: cdef np.ndarray[np.float32_t, ndim=2] backgound = np.zeros((height, width), dtype = np.float32)
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 436, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 436, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_height); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 436, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_width); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 436, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 436, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); __pyx_t_1 = 0; __pyx_t_3 = 0; __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 436, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 436, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 436, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_float32); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 436, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 436, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 436, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 436, __pyx_L1_error) __pyx_t_6 = ((PyArrayObject *)__pyx_t_5); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_backgound.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) { __pyx_v_backgound = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_backgound.rcbuffer->pybuffer.buf = NULL; __PYX_ERR(0, 436, __pyx_L1_error) } else {__pyx_pybuffernd_backgound.diminfo[0].strides = __pyx_pybuffernd_backgound.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_backgound.diminfo[0].shape = __pyx_pybuffernd_backgound.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_backgound.diminfo[1].strides = __pyx_pybuffernd_backgound.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_backgound.diminfo[1].shape = __pyx_pybuffernd_backgound.rcbuffer->pybuffer.shape[1]; } } __pyx_t_6 = 0; __pyx_v_backgound = ((PyArrayObject *)__pyx_t_5); __pyx_t_5 = 0;
437: cdef int x, y
438: cdef int irad, irad_floor, irad_ceil
439: cdef np.float32_t deg, slope, floor_deg, alpha, ceil_deg, beta, round_deg, deltay, deltax, subv, tmpdeg
440: cdef np.float32_t rad, ceil_rad, floor_rad, alpha_rad, beta_rad
+441: cdef np.float32_t zero = 0.0
__pyx_v_zero = 0.0;
+442: cdef int intzero = 0
__pyx_v_intzero = 0;
443: cdef int pos1, pos2
444: cdef int ifloor, iceil, ideg
445:
+446: for x in range(width):
__pyx_t_7 = __pyx_v_width; for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) { __pyx_v_x = __pyx_t_8;
+447: for y in range(height):
__pyx_t_9 = __pyx_v_height; for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) { __pyx_v_y = __pyx_t_10;
448:
+449: rad = distance(centerX, centerY, x, y)
__pyx_v_rad = __pyx_f_12QF_utilities_distance(__pyx_v_centerX, __pyx_v_centerY, __pyx_v_x, __pyx_v_y, 0);
+450: irad = int(round(rad))
__pyx_v_irad = ((int)round(__pyx_v_rad));
+451: ceil_rad = ceil(rad)
__pyx_v_ceil_rad = ceil(__pyx_v_rad);
+452: floor_rad = floor(rad)
__pyx_v_floor_rad = floor(__pyx_v_rad);
+453: irad_ceil = int(ceil_rad)
__pyx_v_irad_ceil = ((int)__pyx_v_ceil_rad);
+454: irad_floor = int(floor_rad)
__pyx_v_irad_floor = ((int)__pyx_v_floor_rad);
455:
+456: if irad_floor == irad_ceil:
__pyx_t_11 = ((__pyx_v_irad_floor == __pyx_v_irad_ceil) != 0); if (__pyx_t_11) { /* … */ goto __pyx_L7; }
+457: beta_rad = 0.5
__pyx_v_beta_rad = 0.5;
+458: alpha_rad = 0.5
__pyx_v_alpha_rad = 0.5;
459: else:
+460: alpha_rad = 1. - (rad - floor_rad)
/*else*/ { __pyx_v_alpha_rad = (1. - (__pyx_v_rad - __pyx_v_floor_rad));
+461: beta_rad = 1. - (ceil_rad - rad)
__pyx_v_beta_rad = (1. - (__pyx_v_ceil_rad - __pyx_v_rad)); } __pyx_L7:;
462:
+463: deltax = float(abs(x - centerX))
__pyx_t_12 = abs((__pyx_v_x - __pyx_v_centerX)); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 463, __pyx_L1_error)
__pyx_v_deltax = ((double)__pyx_t_12);
+464: if deltax == zero:
__pyx_t_11 = ((__pyx_v_deltax == __pyx_v_zero) != 0); if (__pyx_t_11) { /* … */ goto __pyx_L8; }
+465: deg = 90.0
__pyx_v_deg = 90.0;
466: else:
+467: deltay = float(abs(y - centerY))
/*else*/ {
__pyx_t_12 = abs((__pyx_v_y - __pyx_v_centerY)); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 467, __pyx_L1_error)
__pyx_v_deltay = ((double)__pyx_t_12);
+468: slope = deltay / deltax
__pyx_v_slope = (__pyx_v_deltay / __pyx_v_deltax);
+469: deg = atan(slope)*180.0/M_PI
__pyx_v_deg = ((atan(__pyx_v_slope) * 180.0) / M_PI); } __pyx_L8:;
470:
+471: ideg = int(round(deg))
__pyx_v_ideg = ((int)round(__pyx_v_deg));
+472: floor_deg = floor(deg)
__pyx_v_floor_deg = floor(__pyx_v_deg);
+473: ceil_deg = ceil(deg)
__pyx_v_ceil_deg = ceil(__pyx_v_deg);
+474: ifloor = int(floor_deg)
__pyx_v_ifloor = ((int)__pyx_v_floor_deg);
+475: iceil = int(ceil_deg)
__pyx_v_iceil = ((int)__pyx_v_ceil_deg);
476:
+477: if ifloor == iceil:
__pyx_t_11 = ((__pyx_v_ifloor == __pyx_v_iceil) != 0); if (__pyx_t_11) { /* … */ goto __pyx_L9; }
+478: alpha = 0.5
__pyx_v_alpha = 0.5;
+479: beta = 0.5
__pyx_v_beta = 0.5;
480: else:
+481: alpha = 1. - (deg - floor_deg)
/*else*/ { __pyx_v_alpha = (1. - (__pyx_v_deg - __pyx_v_floor_deg));
+482: beta = 1. - (ceil_deg - deg)
__pyx_v_beta = (1. - (__pyx_v_ceil_deg - __pyx_v_deg)); } __pyx_L9:;
483:
+484: if irad_ceil < rmax and irad_floor >= rmin:
__pyx_t_13 = ((__pyx_v_irad_ceil < __pyx_v_rmax) != 0); if (__pyx_t_13) { } else { __pyx_t_11 = __pyx_t_13; goto __pyx_L11_bool_binop_done; } __pyx_t_13 = ((__pyx_v_irad_floor >= __pyx_v_rmin) != 0); __pyx_t_11 = __pyx_t_13; __pyx_L11_bool_binop_done:; if (__pyx_t_11) { /* … */ } } }
+485: pos1 = irad_floor - rmin
__pyx_v_pos1 = (__pyx_v_irad_floor - __pyx_v_rmin);
+486: pos2 = irad_ceil - rmin
__pyx_v_pos2 = (__pyx_v_irad_ceil - __pyx_v_rmin);
+487: backgound[y, x] = alpha * (alpha_rad * pchipLines[ifloor, pos1] + beta_rad * pchipLines[ifloor, pos2]) \
__pyx_t_14 = __pyx_v_ifloor; __pyx_t_15 = __pyx_v_pos1; __pyx_t_16 = __pyx_v_ifloor; __pyx_t_17 = __pyx_v_pos2; /* … */ __pyx_t_22 = __pyx_v_y; __pyx_t_23 = __pyx_v_x; *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_backgound.rcbuffer->pybuffer.buf, __pyx_t_22, __pyx_pybuffernd_backgound.diminfo[0].strides, __pyx_t_23, __pyx_pybuffernd_backgound.diminfo[1].strides) = ((__pyx_v_alpha * ((__pyx_v_alpha_rad * (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_pchipLines.rcbuffer->pybuffer.buf, __pyx_t_14, __pyx_pybuffernd_pchipLines.diminfo[0].strides, __pyx_t_15, __pyx_pybuffernd_pchipLines.diminfo[1].strides))) + (__pyx_v_beta_rad * (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_pchipLines.rcbuffer->pybuffer.buf, __pyx_t_16, __pyx_pybuffernd_pchipLines.diminfo[0].strides, __pyx_t_17, __pyx_pybuffernd_pchipLines.diminfo[1].strides))))) + (__pyx_v_beta * ((__pyx_v_alpha_rad * (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_pchipLines.rcbuffer->pybuffer.buf, __pyx_t_18, __pyx_pybuffernd_pchipLines.diminfo[0].strides, __pyx_t_19, __pyx_pybuffernd_pchipLines.diminfo[1].strides))) + (__pyx_v_beta_rad * (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_pchipLines.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_pchipLines.diminfo[0].strides, __pyx_t_21, __pyx_pybuffernd_pchipLines.diminfo[1].strides))))));
+488: + beta * (alpha_rad * pchipLines[iceil, pos1] + beta_rad * pchipLines[iceil, pos2])
__pyx_t_18 = __pyx_v_iceil; __pyx_t_19 = __pyx_v_pos1; __pyx_t_20 = __pyx_v_iceil; __pyx_t_21 = __pyx_v_pos2;
+489: return backgound
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_backgound)); __pyx_r = ((PyObject *)__pyx_v_backgound); goto __pyx_L0;
490:
491:
492: @cython.cdivision(True)
+493: def createAngularBG(int width, int height, np.ndarray[np.float32_t, ndim=2] subtr, int nBins):
/* Python wrapper */ static PyObject *__pyx_pw_12QF_utilities_23createAngularBG(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyMethodDef __pyx_mdef_12QF_utilities_23createAngularBG = {"createAngularBG", (PyCFunction)__pyx_pw_12QF_utilities_23createAngularBG, METH_VARARGS|METH_KEYWORDS, 0}; static PyObject *__pyx_pw_12QF_utilities_23createAngularBG(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { int __pyx_v_width; int __pyx_v_height; PyArrayObject *__pyx_v_subtr = 0; int __pyx_v_nBins; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("createAngularBG (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_width,&__pyx_n_s_height,&__pyx_n_s_subtr,&__pyx_n_s_nBins,0}; PyObject* values[4] = {0,0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); CYTHON_FALLTHROUGH; case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_width)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_height)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("createAngularBG", 1, 4, 4, 1); __PYX_ERR(0, 493, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_subtr)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("createAngularBG", 1, 4, 4, 2); __PYX_ERR(0, 493, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 3: if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_nBins)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("createAngularBG", 1, 4, 4, 3); __PYX_ERR(0, 493, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "createAngularBG") < 0)) __PYX_ERR(0, 493, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 4) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); values[2] = PyTuple_GET_ITEM(__pyx_args, 2); values[3] = PyTuple_GET_ITEM(__pyx_args, 3); } __pyx_v_width = __Pyx_PyInt_As_int(values[0]); if (unlikely((__pyx_v_width == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 493, __pyx_L3_error) __pyx_v_height = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_height == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 493, __pyx_L3_error) __pyx_v_subtr = ((PyArrayObject *)values[2]); __pyx_v_nBins = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_nBins == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 493, __pyx_L3_error) } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("createAngularBG", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 493, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("QF_utilities.createAngularBG", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_subtr), __pyx_ptype_5numpy_ndarray, 1, "subtr", 0))) __PYX_ERR(0, 493, __pyx_L1_error) __pyx_r = __pyx_pf_12QF_utilities_22createAngularBG(__pyx_self, __pyx_v_width, __pyx_v_height, __pyx_v_subtr, __pyx_v_nBins); /* function exit code */ goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_12QF_utilities_22createAngularBG(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_width, int __pyx_v_height, PyArrayObject *__pyx_v_subtr, int __pyx_v_nBins) { PyArrayObject *__pyx_v_backgound = 0; int __pyx_v_x; int __pyx_v_y; CYTHON_UNUSED int __pyx_v_irad; int __pyx_v_centerX; int __pyx_v_centerY; __pyx_t_5numpy_float32_t __pyx_v_rad; __pyx_t_5numpy_float32_t __pyx_v_deg; __pyx_t_5numpy_float32_t __pyx_v_slope; __pyx_t_5numpy_float32_t __pyx_v_deltax; __pyx_t_5numpy_float32_t __pyx_v_deltay; CYTHON_UNUSED __pyx_t_5numpy_float32_t __pyx_v_bgsub; __pyx_t_5numpy_float32_t __pyx_v_fbin; __pyx_t_5numpy_float32_t __pyx_v_floor_bin; __pyx_t_5numpy_float32_t __pyx_v_ceil_bin; __pyx_t_5numpy_float32_t __pyx_v_alpha; __pyx_t_5numpy_float32_t __pyx_v_beta; __pyx_t_5numpy_float32_t __pyx_v_floor_rad; __pyx_t_5numpy_float32_t __pyx_v_ceil_rad; __pyx_t_5numpy_float32_t __pyx_v_alpha_rad; __pyx_t_5numpy_float32_t __pyx_v_beta_rad; __pyx_t_5numpy_float32_t __pyx_v_theta_size; int __pyx_v_ifloor; int __pyx_v_iceil; int __pyx_v_ibin; int __pyx_v_ifloor_rad; int __pyx_v_iceil_rad; __Pyx_LocalBuf_ND __pyx_pybuffernd_backgound; __Pyx_Buffer __pyx_pybuffer_backgound; __Pyx_LocalBuf_ND __pyx_pybuffernd_subtr; __Pyx_Buffer __pyx_pybuffer_subtr; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("createAngularBG", 0); __pyx_pybuffer_backgound.pybuffer.buf = NULL; __pyx_pybuffer_backgound.refcount = 0; __pyx_pybuffernd_backgound.data = NULL; __pyx_pybuffernd_backgound.rcbuffer = &__pyx_pybuffer_backgound; __pyx_pybuffer_subtr.pybuffer.buf = NULL; __pyx_pybuffer_subtr.refcount = 0; __pyx_pybuffernd_subtr.data = NULL; __pyx_pybuffernd_subtr.rcbuffer = &__pyx_pybuffer_subtr; { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_subtr.rcbuffer->pybuffer, (PyObject*)__pyx_v_subtr, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 493, __pyx_L1_error) } __pyx_pybuffernd_subtr.diminfo[0].strides = __pyx_pybuffernd_subtr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_subtr.diminfo[0].shape = __pyx_pybuffernd_subtr.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_subtr.diminfo[1].strides = __pyx_pybuffernd_subtr.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_subtr.diminfo[1].shape = __pyx_pybuffernd_subtr.rcbuffer->pybuffer.shape[1]; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; __Pyx_PyThreadState_declare __Pyx_PyThreadState_assign __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_backgound.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_subtr.rcbuffer->pybuffer); __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} __Pyx_AddTraceback("QF_utilities.createAngularBG", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; goto __pyx_L2; __pyx_L0:; __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_backgound.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_subtr.rcbuffer->pybuffer); __pyx_L2:; __Pyx_XDECREF((PyObject *)__pyx_v_backgound); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_tuple__30 = PyTuple_Pack(32, __pyx_n_s_width, __pyx_n_s_height, __pyx_n_s_subtr, __pyx_n_s_nBins, __pyx_n_s_backgound, __pyx_n_s_x, __pyx_n_s_y, __pyx_n_s_irad, __pyx_n_s_ideg, __pyx_n_s_centerX, __pyx_n_s_centerY, __pyx_n_s_rad, __pyx_n_s_deg, __pyx_n_s_slope, __pyx_n_s_deltax, __pyx_n_s_deltay, __pyx_n_s_bgsub, __pyx_n_s_fbin, __pyx_n_s_floor_bin, __pyx_n_s_ceil_bin, __pyx_n_s_alpha, __pyx_n_s_beta, __pyx_n_s_floor_rad, __pyx_n_s_ceil_rad, __pyx_n_s_alpha_rad, __pyx_n_s_beta_rad, __pyx_n_s_theta_size, __pyx_n_s_ifloor, __pyx_n_s_iceil, __pyx_n_s_ibin, __pyx_n_s_ifloor_rad, __pyx_n_s_iceil_rad); if (unlikely(!__pyx_tuple__30)) __PYX_ERR(0, 493, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__30); __Pyx_GIVEREF(__pyx_tuple__30); /* … */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_12QF_utilities_23createAngularBG, NULL, __pyx_n_s_QF_utilities); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 493, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_createAngularBG, __pyx_t_1) < 0) __PYX_ERR(0, 493, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_codeobj__31 = (PyObject*)__Pyx_PyCode_New(4, 0, 32, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__30, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_QF_utilities_pyx, __pyx_n_s_createAngularBG, 493, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__31)) __PYX_ERR(0, 493, __pyx_L1_error)
+494: cdef np.ndarray[np.float32_t, ndim=2] backgound = np.zeros((height, width), dtype = np.float32)
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 494, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 494, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_height); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 494, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_width); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 494, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 494, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); __pyx_t_1 = 0; __pyx_t_3 = 0; __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 494, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 494, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 494, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_float32); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 494, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 494, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 494, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 494, __pyx_L1_error) __pyx_t_6 = ((PyArrayObject *)__pyx_t_5); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_backgound.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) { __pyx_v_backgound = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_backgound.rcbuffer->pybuffer.buf = NULL; __PYX_ERR(0, 494, __pyx_L1_error) } else {__pyx_pybuffernd_backgound.diminfo[0].strides = __pyx_pybuffernd_backgound.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_backgound.diminfo[0].shape = __pyx_pybuffernd_backgound.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_backgound.diminfo[1].strides = __pyx_pybuffernd_backgound.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_backgound.diminfo[1].shape = __pyx_pybuffernd_backgound.rcbuffer->pybuffer.shape[1]; } } __pyx_t_6 = 0; __pyx_v_backgound = ((PyArrayObject *)__pyx_t_5); __pyx_t_5 = 0;
495: cdef int x,y, irad, ideg
+496: cdef int centerX = width - 1
__pyx_v_centerX = (__pyx_v_width - 1);
+497: cdef int centerY = height - 1
__pyx_v_centerY = (__pyx_v_height - 1);
498: cdef np.float32_t rad, deg, slope, deltax, deltay, bgsub, fbin, floor_bin, ceil_bin, alpha, beta, floor_rad, ceil_rad, alpha_rad, beta_rad
+499: cdef np.float32_t theta_size = 90./nBins
__pyx_v_theta_size = (90. / __pyx_v_nBins);
500: cdef int ifloor, iceil, ibin, ifloor_rad, iceil_rad
501:
+502: for x in range(0, width):
__pyx_t_7 = __pyx_v_width; for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) { __pyx_v_x = __pyx_t_8;
+503: for y in range(0, height):
__pyx_t_9 = __pyx_v_height; for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) { __pyx_v_y = __pyx_t_10;
+504: rad = distance(centerX, centerY, x, y)
__pyx_v_rad = __pyx_f_12QF_utilities_distance(__pyx_v_centerX, __pyx_v_centerY, __pyx_v_x, __pyx_v_y, 0);
+505: floor_rad = floor(rad)
__pyx_v_floor_rad = floor(__pyx_v_rad);
+506: ceil_rad = ceil(rad)
__pyx_v_ceil_rad = ceil(__pyx_v_rad);
+507: ifloor_rad = int(floor_rad)
__pyx_v_ifloor_rad = ((int)__pyx_v_floor_rad);
+508: iceil_rad = int(ceil_rad)
__pyx_v_iceil_rad = ((int)__pyx_v_ceil_rad);
509:
+510: if ifloor_rad == iceil_rad:
__pyx_t_11 = ((__pyx_v_ifloor_rad == __pyx_v_iceil_rad) != 0); if (__pyx_t_11) { /* … */ goto __pyx_L7; }
+511: beta_rad = 0.5
__pyx_v_beta_rad = 0.5;
+512: alpha_rad = 0.5
__pyx_v_alpha_rad = 0.5;
513: else:
+514: alpha_rad = 1. - (rad - floor_rad)
/*else*/ { __pyx_v_alpha_rad = (1. - (__pyx_v_rad - __pyx_v_floor_rad));
+515: beta_rad = 1. - (ceil_rad - rad)
__pyx_v_beta_rad = (1. - (__pyx_v_ceil_rad - __pyx_v_rad)); } __pyx_L7:;
516:
+517: irad = int(round(rad))
__pyx_v_irad = ((int)round(__pyx_v_rad));
518:
+519: deltax = float(abs(x - centerX))
__pyx_t_12 = abs((__pyx_v_x - __pyx_v_centerX)); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 519, __pyx_L1_error)
__pyx_v_deltax = ((double)__pyx_t_12);
+520: bgsub = 0.0
__pyx_v_bgsub = 0.0;
+521: if deltax == 0.0:
__pyx_t_11 = ((__pyx_v_deltax == 0.0) != 0); if (__pyx_t_11) { /* … */ goto __pyx_L8; }
+522: deg = 90.0
__pyx_v_deg = 90.0;
523: else:
+524: deltay = float(abs(y - centerY))
/*else*/ {
__pyx_t_12 = abs((__pyx_v_y - __pyx_v_centerY)); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 524, __pyx_L1_error)
__pyx_v_deltay = ((double)__pyx_t_12);
+525: slope = deltay / deltax
__pyx_v_slope = (__pyx_v_deltay / __pyx_v_deltax);
+526: deg = atan(slope)*180.0/M_PI
__pyx_v_deg = ((atan(__pyx_v_slope) * 180.0) / M_PI); } __pyx_L8:;
527:
+528: fbin = 1.*deg/theta_size
__pyx_v_fbin = ((1. * __pyx_v_deg) / __pyx_v_theta_size);
+529: ibin = int(round(fbin))
__pyx_v_ibin = ((int)round(__pyx_v_fbin));
530:
+531: if ibin == 0:
__pyx_t_11 = ((__pyx_v_ibin == 0) != 0); if (__pyx_t_11) { /* … */ goto __pyx_L9; }
+532: backgound[y, x] = alpha_rad*subtr[ibin, ifloor_rad] + beta_rad*subtr[ibin, iceil_rad]
__pyx_t_13 = __pyx_v_ibin; __pyx_t_14 = __pyx_v_ifloor_rad; __pyx_t_15 = __pyx_v_ibin; __pyx_t_16 = __pyx_v_iceil_rad; __pyx_t_17 = __pyx_v_y; __pyx_t_18 = __pyx_v_x; *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_backgound.rcbuffer->pybuffer.buf, __pyx_t_17, __pyx_pybuffernd_backgound.diminfo[0].strides, __pyx_t_18, __pyx_pybuffernd_backgound.diminfo[1].strides) = ((__pyx_v_alpha_rad * (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_subtr.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_subtr.diminfo[0].strides, __pyx_t_14, __pyx_pybuffernd_subtr.diminfo[1].strides))) + (__pyx_v_beta_rad * (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_subtr.rcbuffer->pybuffer.buf, __pyx_t_15, __pyx_pybuffernd_subtr.diminfo[0].strides, __pyx_t_16, __pyx_pybuffernd_subtr.diminfo[1].strides))));
+533: elif ibin == nBins:
__pyx_t_11 = ((__pyx_v_ibin == __pyx_v_nBins) != 0); if (__pyx_t_11) { /* … */ goto __pyx_L9; }
+534: backgound[y, x] = alpha_rad*subtr[ibin-1, ifloor_rad] + beta_rad*subtr[ibin-1, iceil_rad]
__pyx_t_19 = (__pyx_v_ibin - 1); __pyx_t_20 = __pyx_v_ifloor_rad; __pyx_t_21 = (__pyx_v_ibin - 1); __pyx_t_22 = __pyx_v_iceil_rad; __pyx_t_23 = __pyx_v_y; __pyx_t_24 = __pyx_v_x; *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_backgound.rcbuffer->pybuffer.buf, __pyx_t_23, __pyx_pybuffernd_backgound.diminfo[0].strides, __pyx_t_24, __pyx_pybuffernd_backgound.diminfo[1].strides) = ((__pyx_v_alpha_rad * (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_subtr.rcbuffer->pybuffer.buf, __pyx_t_19, __pyx_pybuffernd_subtr.diminfo[0].strides, __pyx_t_20, __pyx_pybuffernd_subtr.diminfo[1].strides))) + (__pyx_v_beta_rad * (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_subtr.rcbuffer->pybuffer.buf, __pyx_t_21, __pyx_pybuffernd_subtr.diminfo[0].strides, __pyx_t_22, __pyx_pybuffernd_subtr.diminfo[1].strides))));
535: else:
+536: floor_bin = floor(fbin)
/*else*/ { __pyx_v_floor_bin = floor(__pyx_v_fbin);
+537: ceil_bin = ceil(fbin)
__pyx_v_ceil_bin = ceil(__pyx_v_fbin);
+538: alpha = 1. - (fbin - floor_bin)
__pyx_v_alpha = (1. - (__pyx_v_fbin - __pyx_v_floor_bin));
+539: beta = 1. - (ceil_bin - fbin)
__pyx_v_beta = (1. - (__pyx_v_ceil_bin - __pyx_v_fbin));
540:
+541: if alpha == 1.0 and beta == 1.0:
__pyx_t_25 = ((__pyx_v_alpha == 1.0) != 0); if (__pyx_t_25) { } else { __pyx_t_11 = __pyx_t_25; goto __pyx_L11_bool_binop_done; } __pyx_t_25 = ((__pyx_v_beta == 1.0) != 0); __pyx_t_11 = __pyx_t_25; __pyx_L11_bool_binop_done:; if (__pyx_t_11) { /* … */ goto __pyx_L10; }
+542: alpha = 0.5
__pyx_v_alpha = 0.5;
+543: beta = 0.5
__pyx_v_beta = 0.5;
+544: ifloor = int(floor_bin - 1.0)
__pyx_v_ifloor = ((int)(__pyx_v_floor_bin - 1.0));
+545: iceil = int(ceil_bin)
__pyx_v_iceil = ((int)__pyx_v_ceil_bin);
+546: elif alpha > beta :
__pyx_t_11 = ((__pyx_v_alpha > __pyx_v_beta) != 0); if (__pyx_t_11) { /* … */ goto __pyx_L10; }
+547: floor_bin = floor_bin - 0.5
__pyx_v_floor_bin = (__pyx_v_floor_bin - 0.5);
+548: ceil_bin = ceil_bin - 0.5
__pyx_v_ceil_bin = (__pyx_v_ceil_bin - 0.5);
+549: alpha = 1. - (fbin - floor_bin)
__pyx_v_alpha = (1. - (__pyx_v_fbin - __pyx_v_floor_bin));
+550: beta = 1. - (ceil_bin - fbin)
__pyx_v_beta = (1. - (__pyx_v_ceil_bin - __pyx_v_fbin));
+551: ifloor = int(floor(floor_bin))
__pyx_v_ifloor = ((int)floor(__pyx_v_floor_bin));
+552: iceil = int(floor(ceil_bin))
__pyx_v_iceil = ((int)floor(__pyx_v_ceil_bin));
553: else:
+554: floor_bin = floor_bin + 0.5
/*else*/ { __pyx_v_floor_bin = (__pyx_v_floor_bin + 0.5);
+555: ceil_bin = ceil_bin + 0.5
__pyx_v_ceil_bin = (__pyx_v_ceil_bin + 0.5);
+556: alpha = 1. - (fbin - floor_bin)
__pyx_v_alpha = (1. - (__pyx_v_fbin - __pyx_v_floor_bin));
+557: beta = 1. - (ceil_bin - fbin)
__pyx_v_beta = (1. - (__pyx_v_ceil_bin - __pyx_v_fbin));
+558: ifloor = int(floor(floor_bin))
__pyx_v_ifloor = ((int)floor(__pyx_v_floor_bin));
+559: iceil = int(floor(ceil_bin))
__pyx_v_iceil = ((int)floor(__pyx_v_ceil_bin)); } __pyx_L10:;
560:
+561: backgound[y, x] = alpha * (alpha_rad * subtr[ifloor, ifloor_rad] + beta_rad * subtr[ifloor, iceil_rad])+ beta * (alpha_rad * subtr[iceil, ifloor_rad] + beta_rad * subtr[iceil, iceil_rad])
__pyx_t_26 = __pyx_v_ifloor; __pyx_t_27 = __pyx_v_ifloor_rad; __pyx_t_28 = __pyx_v_ifloor; __pyx_t_29 = __pyx_v_iceil_rad; __pyx_t_30 = __pyx_v_iceil; __pyx_t_31 = __pyx_v_ifloor_rad; __pyx_t_32 = __pyx_v_iceil; __pyx_t_33 = __pyx_v_iceil_rad; __pyx_t_34 = __pyx_v_y; __pyx_t_35 = __pyx_v_x; *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_backgound.rcbuffer->pybuffer.buf, __pyx_t_34, __pyx_pybuffernd_backgound.diminfo[0].strides, __pyx_t_35, __pyx_pybuffernd_backgound.diminfo[1].strides) = ((__pyx_v_alpha * ((__pyx_v_alpha_rad * (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_subtr.rcbuffer->pybuffer.buf, __pyx_t_26, __pyx_pybuffernd_subtr.diminfo[0].strides, __pyx_t_27, __pyx_pybuffernd_subtr.diminfo[1].strides))) + (__pyx_v_beta_rad * (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_subtr.rcbuffer->pybuffer.buf, __pyx_t_28, __pyx_pybuffernd_subtr.diminfo[0].strides, __pyx_t_29, __pyx_pybuffernd_subtr.diminfo[1].strides))))) + (__pyx_v_beta * ((__pyx_v_alpha_rad * (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_subtr.rcbuffer->pybuffer.buf, __pyx_t_30, __pyx_pybuffernd_subtr.diminfo[0].strides, __pyx_t_31, __pyx_pybuffernd_subtr.diminfo[1].strides))) + (__pyx_v_beta_rad * (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_subtr.rcbuffer->pybuffer.buf, __pyx_t_32, __pyx_pybuffernd_subtr.diminfo[0].strides, __pyx_t_33, __pyx_pybuffernd_subtr.diminfo[1].strides)))))); } __pyx_L9:; } }
562:
+563: return backgound
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_backgound)); __pyx_r = ((PyObject *)__pyx_v_backgound); goto __pyx_L0;
564:
565: @cython.cdivision(True)
+566: def createCircularlySymBG(int width, int height, np.ndarray[np.float32_t, ndim=1] spline):
/* Python wrapper */ static PyObject *__pyx_pw_12QF_utilities_25createCircularlySymBG(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyMethodDef __pyx_mdef_12QF_utilities_25createCircularlySymBG = {"createCircularlySymBG", (PyCFunction)__pyx_pw_12QF_utilities_25createCircularlySymBG, METH_VARARGS|METH_KEYWORDS, 0}; static PyObject *__pyx_pw_12QF_utilities_25createCircularlySymBG(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { int __pyx_v_width; int __pyx_v_height; PyArrayObject *__pyx_v_spline = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("createCircularlySymBG (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_width,&__pyx_n_s_height,&__pyx_n_s_spline,0}; PyObject* values[3] = {0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_width)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_height)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("createCircularlySymBG", 1, 3, 3, 1); __PYX_ERR(0, 566, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_spline)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("createCircularlySymBG", 1, 3, 3, 2); __PYX_ERR(0, 566, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "createCircularlySymBG") < 0)) __PYX_ERR(0, 566, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); values[2] = PyTuple_GET_ITEM(__pyx_args, 2); } __pyx_v_width = __Pyx_PyInt_As_int(values[0]); if (unlikely((__pyx_v_width == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 566, __pyx_L3_error) __pyx_v_height = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_height == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 566, __pyx_L3_error) __pyx_v_spline = ((PyArrayObject *)values[2]); } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("createCircularlySymBG", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 566, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("QF_utilities.createCircularlySymBG", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_spline), __pyx_ptype_5numpy_ndarray, 1, "spline", 0))) __PYX_ERR(0, 566, __pyx_L1_error) __pyx_r = __pyx_pf_12QF_utilities_24createCircularlySymBG(__pyx_self, __pyx_v_width, __pyx_v_height, __pyx_v_spline); /* function exit code */ goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_12QF_utilities_24createCircularlySymBG(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_width, int __pyx_v_height, PyArrayObject *__pyx_v_spline) { PyArrayObject *__pyx_v_backgound = 0; int __pyx_v_x; int __pyx_v_y; int __pyx_v_ifloor; int __pyx_v_iceil; CYTHON_UNUSED int __pyx_v_irad; __pyx_t_5numpy_float32_t __pyx_v_centerX; __pyx_t_5numpy_float32_t __pyx_v_centerY; __pyx_t_5numpy_float32_t __pyx_v_rad; __pyx_t_5numpy_float32_t __pyx_v_alpha; __pyx_t_5numpy_float32_t __pyx_v_beta; __pyx_t_5numpy_float32_t __pyx_v_ffloor; __pyx_t_5numpy_float32_t __pyx_v_fceil; __pyx_t_5numpy_float32_t __pyx_v_fx; __pyx_t_5numpy_float32_t __pyx_v_fy; __Pyx_LocalBuf_ND __pyx_pybuffernd_backgound; __Pyx_Buffer __pyx_pybuffer_backgound; __Pyx_LocalBuf_ND __pyx_pybuffernd_spline; __Pyx_Buffer __pyx_pybuffer_spline; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("createCircularlySymBG", 0); __pyx_pybuffer_backgound.pybuffer.buf = NULL; __pyx_pybuffer_backgound.refcount = 0; __pyx_pybuffernd_backgound.data = NULL; __pyx_pybuffernd_backgound.rcbuffer = &__pyx_pybuffer_backgound; __pyx_pybuffer_spline.pybuffer.buf = NULL; __pyx_pybuffer_spline.refcount = 0; __pyx_pybuffernd_spline.data = NULL; __pyx_pybuffernd_spline.rcbuffer = &__pyx_pybuffer_spline; { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_spline.rcbuffer->pybuffer, (PyObject*)__pyx_v_spline, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 566, __pyx_L1_error) } __pyx_pybuffernd_spline.diminfo[0].strides = __pyx_pybuffernd_spline.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_spline.diminfo[0].shape = __pyx_pybuffernd_spline.rcbuffer->pybuffer.shape[0]; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; __Pyx_PyThreadState_declare __Pyx_PyThreadState_assign __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_backgound.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_spline.rcbuffer->pybuffer); __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} __Pyx_AddTraceback("QF_utilities.createCircularlySymBG", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; goto __pyx_L2; __pyx_L0:; __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_backgound.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_spline.rcbuffer->pybuffer); __pyx_L2:; __Pyx_XDECREF((PyObject *)__pyx_v_backgound); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_tuple__32 = PyTuple_Pack(18, __pyx_n_s_width, __pyx_n_s_height, __pyx_n_s_spline, __pyx_n_s_backgound, __pyx_n_s_x, __pyx_n_s_y, __pyx_n_s_ifloor, __pyx_n_s_iceil, __pyx_n_s_irad, __pyx_n_s_centerX, __pyx_n_s_centerY, __pyx_n_s_rad, __pyx_n_s_alpha, __pyx_n_s_beta, __pyx_n_s_ffloor, __pyx_n_s_fceil, __pyx_n_s_fx, __pyx_n_s_fy); if (unlikely(!__pyx_tuple__32)) __PYX_ERR(0, 566, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__32); __Pyx_GIVEREF(__pyx_tuple__32); /* … */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_12QF_utilities_25createCircularlySymBG, NULL, __pyx_n_s_QF_utilities); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 566, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_createCircularlySymBG, __pyx_t_1) < 0) __PYX_ERR(0, 566, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_codeobj__33 = (PyObject*)__Pyx_PyCode_New(3, 0, 18, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__32, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_QF_utilities_pyx, __pyx_n_s_createCircularlySymBG, 566, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__33)) __PYX_ERR(0, 566, __pyx_L1_error)
+567: cdef np.ndarray[np.float32_t, ndim=2] backgound = np.zeros((height, width), dtype = np.float32)
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 567, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 567, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_height); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 567, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_width); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 567, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 567, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); __pyx_t_1 = 0; __pyx_t_3 = 0; __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 567, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 567, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 567, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_float32); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 567, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 567, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 567, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 567, __pyx_L1_error) __pyx_t_6 = ((PyArrayObject *)__pyx_t_5); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_backgound.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) { __pyx_v_backgound = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_backgound.rcbuffer->pybuffer.buf = NULL; __PYX_ERR(0, 567, __pyx_L1_error) } else {__pyx_pybuffernd_backgound.diminfo[0].strides = __pyx_pybuffernd_backgound.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_backgound.diminfo[0].shape = __pyx_pybuffernd_backgound.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_backgound.diminfo[1].strides = __pyx_pybuffernd_backgound.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_backgound.diminfo[1].shape = __pyx_pybuffernd_backgound.rcbuffer->pybuffer.shape[1]; } } __pyx_t_6 = 0; __pyx_v_backgound = ((PyArrayObject *)__pyx_t_5); __pyx_t_5 = 0;
568: cdef int x, y, ifloor, iceil, irad
+569: cdef np.float32_t centerX = width - 0.5
__pyx_v_centerX = (__pyx_v_width - 0.5);
+570: cdef np.float32_t centerY = height - 0.5
__pyx_v_centerY = (__pyx_v_height - 0.5);
571: cdef np.float32_t rad, alpha, beta, ffloor, fceil
572: cdef np.float32_t fx, fy
573:
+574: for x in range(width):
__pyx_t_7 = __pyx_v_width; for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) { __pyx_v_x = __pyx_t_8;
+575: for y in range(height):
__pyx_t_9 = __pyx_v_height; for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) { __pyx_v_y = __pyx_t_10;
+576: fx = float(x)
__pyx_v_fx = ((double)__pyx_v_x);
+577: fy = float(y)
__pyx_v_fy = ((double)__pyx_v_y);
+578: rad = sqrt((fx-centerX)**2+(fy-centerY)**2)
__pyx_v_rad = sqrt((powf((__pyx_v_fx - __pyx_v_centerX), 2.0) + powf((__pyx_v_fy - __pyx_v_centerY), 2.0)));
+579: irad = int(round(rad))
__pyx_v_irad = ((int)round(__pyx_v_rad));
+580: ffloor = floor(rad)
__pyx_v_ffloor = floor(__pyx_v_rad);
+581: fceil = ceil(rad)
__pyx_v_fceil = ceil(__pyx_v_rad);
+582: alpha = 1.-(rad-ffloor)
__pyx_v_alpha = (1. - (__pyx_v_rad - __pyx_v_ffloor));
+583: beta = 1.-(fceil-rad)
__pyx_v_beta = (1. - (__pyx_v_fceil - __pyx_v_rad));
+584: ifloor = int(ffloor)
__pyx_v_ifloor = ((int)__pyx_v_ffloor);
+585: iceil = int(fceil)
__pyx_v_iceil = ((int)__pyx_v_fceil);
586:
+587: if ifloor == iceil:
__pyx_t_11 = ((__pyx_v_ifloor == __pyx_v_iceil) != 0); if (__pyx_t_11) { /* … */ }
+588: alpha = 0.5
__pyx_v_alpha = 0.5;
+589: beta = 0.5
__pyx_v_beta = 0.5;
590:
+591: backgound[y, x] = alpha*spline[ifloor] + beta*spline[iceil]
__pyx_t_12 = __pyx_v_ifloor; __pyx_t_13 = __pyx_v_iceil; __pyx_t_14 = __pyx_v_y; __pyx_t_15 = __pyx_v_x; *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_backgound.rcbuffer->pybuffer.buf, __pyx_t_14, __pyx_pybuffernd_backgound.diminfo[0].strides, __pyx_t_15, __pyx_pybuffernd_backgound.diminfo[1].strides) = ((__pyx_v_alpha * (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_spline.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_spline.diminfo[0].strides))) + (__pyx_v_beta * (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_spline.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_spline.diminfo[0].strides)))); } }
592:
+593: return backgound
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_backgound)); __pyx_r = ((PyObject *)__pyx_v_backgound); goto __pyx_L0;
594:
595: @cython.cdivision(True)
+596: def getCircularDiscreteBackground(np.ndarray[np.float32_t, ndim=2] img, int rmin, float start_p, float end_p, int radial_bin, int nBin, int max_pts):
/* Python wrapper */ static PyObject *__pyx_pw_12QF_utilities_27getCircularDiscreteBackground(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyMethodDef __pyx_mdef_12QF_utilities_27getCircularDiscreteBackground = {"getCircularDiscreteBackground", (PyCFunction)__pyx_pw_12QF_utilities_27getCircularDiscreteBackground, METH_VARARGS|METH_KEYWORDS, 0}; static PyObject *__pyx_pw_12QF_utilities_27getCircularDiscreteBackground(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyArrayObject *__pyx_v_img = 0; int __pyx_v_rmin; float __pyx_v_start_p; float __pyx_v_end_p; int __pyx_v_radial_bin; int __pyx_v_nBin; int __pyx_v_max_pts; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("getCircularDiscreteBackground (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_img,&__pyx_n_s_rmin,&__pyx_n_s_start_p,&__pyx_n_s_end_p,&__pyx_n_s_radial_bin,&__pyx_n_s_nBin,&__pyx_n_s_max_pts,0}; PyObject* values[7] = {0,0,0,0,0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); CYTHON_FALLTHROUGH; case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); CYTHON_FALLTHROUGH; case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); CYTHON_FALLTHROUGH; case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); CYTHON_FALLTHROUGH; case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_img)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_rmin)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("getCircularDiscreteBackground", 1, 7, 7, 1); __PYX_ERR(0, 596, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_start_p)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("getCircularDiscreteBackground", 1, 7, 7, 2); __PYX_ERR(0, 596, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 3: if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_end_p)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("getCircularDiscreteBackground", 1, 7, 7, 3); __PYX_ERR(0, 596, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 4: if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_radial_bin)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("getCircularDiscreteBackground", 1, 7, 7, 4); __PYX_ERR(0, 596, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 5: if (likely((values[5] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_nBin)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("getCircularDiscreteBackground", 1, 7, 7, 5); __PYX_ERR(0, 596, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 6: if (likely((values[6] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_max_pts)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("getCircularDiscreteBackground", 1, 7, 7, 6); __PYX_ERR(0, 596, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "getCircularDiscreteBackground") < 0)) __PYX_ERR(0, 596, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 7) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); values[2] = PyTuple_GET_ITEM(__pyx_args, 2); values[3] = PyTuple_GET_ITEM(__pyx_args, 3); values[4] = PyTuple_GET_ITEM(__pyx_args, 4); values[5] = PyTuple_GET_ITEM(__pyx_args, 5); values[6] = PyTuple_GET_ITEM(__pyx_args, 6); } __pyx_v_img = ((PyArrayObject *)values[0]); __pyx_v_rmin = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_rmin == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 596, __pyx_L3_error) __pyx_v_start_p = __pyx_PyFloat_AsFloat(values[2]); if (unlikely((__pyx_v_start_p == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 596, __pyx_L3_error) __pyx_v_end_p = __pyx_PyFloat_AsFloat(values[3]); if (unlikely((__pyx_v_end_p == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 596, __pyx_L3_error) __pyx_v_radial_bin = __Pyx_PyInt_As_int(values[4]); if (unlikely((__pyx_v_radial_bin == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 596, __pyx_L3_error) __pyx_v_nBin = __Pyx_PyInt_As_int(values[5]); if (unlikely((__pyx_v_nBin == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 596, __pyx_L3_error) __pyx_v_max_pts = __Pyx_PyInt_As_int(values[6]); if (unlikely((__pyx_v_max_pts == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 596, __pyx_L3_error) } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("getCircularDiscreteBackground", 1, 7, 7, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 596, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("QF_utilities.getCircularDiscreteBackground", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_img), __pyx_ptype_5numpy_ndarray, 1, "img", 0))) __PYX_ERR(0, 596, __pyx_L1_error) __pyx_r = __pyx_pf_12QF_utilities_26getCircularDiscreteBackground(__pyx_self, __pyx_v_img, __pyx_v_rmin, __pyx_v_start_p, __pyx_v_end_p, __pyx_v_radial_bin, __pyx_v_nBin, __pyx_v_max_pts); /* function exit code */ goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_12QF_utilities_26getCircularDiscreteBackground(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_img, int __pyx_v_rmin, float __pyx_v_start_p, float __pyx_v_end_p, int __pyx_v_radial_bin, int __pyx_v_nBin, int __pyx_v_max_pts) { int __pyx_v_height; int __pyx_v_width; PyArrayObject *__pyx_v_xs = 0; PyArrayObject *__pyx_v_ys = 0; PyArrayObject *__pyx_v_all_pts = 0; __pyx_t_5numpy_float32_t __pyx_v_centerX; __pyx_t_5numpy_float32_t __pyx_v_centerY; int __pyx_v_nPoints; int __pyx_v_bin; int __pyx_v_start_ind; int __pyx_v_end_ind; int __pyx_v_x; int __pyx_v_y; int __pyx_v_i; __pyx_t_5numpy_float32_t __pyx_v_float_x; __pyx_t_5numpy_float32_t __pyx_v_float_y; __pyx_t_5numpy_float32_t __pyx_v_distance; __pyx_t_5numpy_float32_t __pyx_v_d1; __pyx_t_5numpy_float32_t __pyx_v_d2; __pyx_t_5numpy_float32_t __pyx_v_sumVal; PyObject *__pyx_v_sorted_pts = NULL; __Pyx_LocalBuf_ND __pyx_pybuffernd_all_pts; __Pyx_Buffer __pyx_pybuffer_all_pts; __Pyx_LocalBuf_ND __pyx_pybuffernd_img; __Pyx_Buffer __pyx_pybuffer_img; __Pyx_LocalBuf_ND __pyx_pybuffernd_xs; __Pyx_Buffer __pyx_pybuffer_xs; __Pyx_LocalBuf_ND __pyx_pybuffernd_ys; __Pyx_Buffer __pyx_pybuffer_ys; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("getCircularDiscreteBackground", 0); __pyx_pybuffer_xs.pybuffer.buf = NULL; __pyx_pybuffer_xs.refcount = 0; __pyx_pybuffernd_xs.data = NULL; __pyx_pybuffernd_xs.rcbuffer = &__pyx_pybuffer_xs; __pyx_pybuffer_ys.pybuffer.buf = NULL; __pyx_pybuffer_ys.refcount = 0; __pyx_pybuffernd_ys.data = NULL; __pyx_pybuffernd_ys.rcbuffer = &__pyx_pybuffer_ys; __pyx_pybuffer_all_pts.pybuffer.buf = NULL; __pyx_pybuffer_all_pts.refcount = 0; __pyx_pybuffernd_all_pts.data = NULL; __pyx_pybuffernd_all_pts.rcbuffer = &__pyx_pybuffer_all_pts; __pyx_pybuffer_img.pybuffer.buf = NULL; __pyx_pybuffer_img.refcount = 0; __pyx_pybuffernd_img.data = NULL; __pyx_pybuffernd_img.rcbuffer = &__pyx_pybuffer_img; { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_img.rcbuffer->pybuffer, (PyObject*)__pyx_v_img, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 596, __pyx_L1_error) } __pyx_pybuffernd_img.diminfo[0].strides = __pyx_pybuffernd_img.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_img.diminfo[0].shape = __pyx_pybuffernd_img.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_img.diminfo[1].strides = __pyx_pybuffernd_img.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_img.diminfo[1].shape = __pyx_pybuffernd_img.rcbuffer->pybuffer.shape[1]; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; __Pyx_PyThreadState_declare __Pyx_PyThreadState_assign __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_all_pts.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_img.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_xs.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ys.rcbuffer->pybuffer); __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} __Pyx_AddTraceback("QF_utilities.getCircularDiscreteBackground", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; goto __pyx_L2; __pyx_L0:; __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_all_pts.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_img.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_xs.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ys.rcbuffer->pybuffer); __pyx_L2:; __Pyx_XDECREF((PyObject *)__pyx_v_xs); __Pyx_XDECREF((PyObject *)__pyx_v_ys); __Pyx_XDECREF((PyObject *)__pyx_v_all_pts); __Pyx_XDECREF(__pyx_v_sorted_pts); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_tuple__34 = PyTuple_Pack(29, __pyx_n_s_img, __pyx_n_s_rmin, __pyx_n_s_start_p, __pyx_n_s_end_p, __pyx_n_s_radial_bin, __pyx_n_s_nBin, __pyx_n_s_max_pts, __pyx_n_s_height, __pyx_n_s_width, __pyx_n_s_xs, __pyx_n_s_ys, __pyx_n_s_all_pts, __pyx_n_s_centerX, __pyx_n_s_centerY, __pyx_n_s_nPoints, __pyx_n_s_rad, __pyx_n_s_bin, __pyx_n_s_start_ind, __pyx_n_s_end_ind, __pyx_n_s_x, __pyx_n_s_y, __pyx_n_s_i, __pyx_n_s_float_x, __pyx_n_s_float_y, __pyx_n_s_distance, __pyx_n_s_d1, __pyx_n_s_d2, __pyx_n_s_sumVal, __pyx_n_s_sorted_pts); if (unlikely(!__pyx_tuple__34)) __PYX_ERR(0, 596, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__34); __Pyx_GIVEREF(__pyx_tuple__34); /* … */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_12QF_utilities_27getCircularDiscreteBackground, NULL, __pyx_n_s_QF_utilities); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 596, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_getCircularDiscreteBackground, __pyx_t_1) < 0) __PYX_ERR(0, 596, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_codeobj__35 = (PyObject*)__Pyx_PyCode_New(7, 0, 29, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__34, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_QF_utilities_pyx, __pyx_n_s_getCircularDiscreteBackground, 596, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__35)) __PYX_ERR(0, 596, __pyx_L1_error)
+597: cdef int height = img.shape[0]
__pyx_v_height = (__pyx_v_img->dimensions[0]);
+598: cdef int width = img.shape[1]
__pyx_v_width = (__pyx_v_img->dimensions[1]);
+599: cdef np.ndarray[np.float32_t, ndim=1] xs = np.zeros(nBin, dtype = np.float32)
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 599, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 599, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_nBin); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 599, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 599, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 599, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 599, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_float32); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 599, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 599, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 599, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 599, __pyx_L1_error) __pyx_t_6 = ((PyArrayObject *)__pyx_t_5); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_xs.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { __pyx_v_xs = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_xs.rcbuffer->pybuffer.buf = NULL; __PYX_ERR(0, 599, __pyx_L1_error) } else {__pyx_pybuffernd_xs.diminfo[0].strides = __pyx_pybuffernd_xs.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_xs.diminfo[0].shape = __pyx_pybuffernd_xs.rcbuffer->pybuffer.shape[0]; } } __pyx_t_6 = 0; __pyx_v_xs = ((PyArrayObject *)__pyx_t_5); __pyx_t_5 = 0;
+600: cdef np.ndarray[np.float32_t, ndim=1] ys = np.zeros(nBin, dtype = np.float32)
__pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 600, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_zeros); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 600, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_nBin); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 600, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 600, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 600, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 600, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float32); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 600, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 600, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 600, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 600, __pyx_L1_error) __pyx_t_7 = ((PyArrayObject *)__pyx_t_4); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ys.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { __pyx_v_ys = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_ys.rcbuffer->pybuffer.buf = NULL; __PYX_ERR(0, 600, __pyx_L1_error) } else {__pyx_pybuffernd_ys.diminfo[0].strides = __pyx_pybuffernd_ys.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_ys.diminfo[0].shape = __pyx_pybuffernd_ys.rcbuffer->pybuffer.shape[0]; } } __pyx_t_7 = 0; __pyx_v_ys = ((PyArrayObject *)__pyx_t_4); __pyx_t_4 = 0;
+601: cdef np.ndarray[np.float32_t, ndim=1] all_pts = np.zeros(max_pts, dtype = np.float32)
__pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 601, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_zeros); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 601, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_max_pts); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 601, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 601, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 601, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 601, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_float32); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 601, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 601, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 601, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 601, __pyx_L1_error) __pyx_t_8 = ((PyArrayObject *)__pyx_t_2); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_all_pts.rcbuffer->pybuffer, (PyObject*)__pyx_t_8, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { __pyx_v_all_pts = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_all_pts.rcbuffer->pybuffer.buf = NULL; __PYX_ERR(0, 601, __pyx_L1_error) } else {__pyx_pybuffernd_all_pts.diminfo[0].strides = __pyx_pybuffernd_all_pts.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_all_pts.diminfo[0].shape = __pyx_pybuffernd_all_pts.rcbuffer->pybuffer.shape[0]; } } __pyx_t_8 = 0; __pyx_v_all_pts = ((PyArrayObject *)__pyx_t_2); __pyx_t_2 = 0;
+602: cdef np.float32_t centerX = width - 0.5
__pyx_v_centerX = (__pyx_v_width - 0.5);
+603: cdef np.float32_t centerY = height - 0.5
__pyx_v_centerY = (__pyx_v_height - 0.5);
+604: cdef int nPoints = 0
__pyx_v_nPoints = 0;
605: cdef int rad, bin, start_ind, end_ind
606: cdef int x, y, i
607: cdef np.float32_t float_x, float_y, distance, d1, d2, sumVal
608:
+609: for bin in range(0, nBin):
__pyx_t_9 = __pyx_v_nBin; for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) { __pyx_v_bin = __pyx_t_10;
+610: nPoints = 0
__pyx_v_nPoints = 0;
+611: d1 = float(rmin + bin*radial_bin)
__pyx_v_d1 = ((double)(__pyx_v_rmin + (__pyx_v_bin * __pyx_v_radial_bin)));
+612: d2 = d1 + float(radial_bin)
__pyx_v_d2 = (__pyx_v_d1 + ((double)__pyx_v_radial_bin));
613:
614: # Get all points in a bin
+615: for x in range(width):
__pyx_t_11 = __pyx_v_width; for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) { __pyx_v_x = __pyx_t_12;
+616: float_x = float(x)
__pyx_v_float_x = ((double)__pyx_v_x);
+617: for y in range(height):
__pyx_t_13 = __pyx_v_height; for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_13; __pyx_t_14+=1) { __pyx_v_y = __pyx_t_14;
+618: float_y = float(y)
__pyx_v_float_y = ((double)__pyx_v_y);
+619: distance = sqrt((float_x-centerX)**2+(float_y-centerY)**2)
__pyx_v_distance = sqrt((powf((__pyx_v_float_x - __pyx_v_centerX), 2.0) + powf((__pyx_v_float_y - __pyx_v_centerY), 2.0)));
+620: if d1 <= distance and distance < d2 and nPoints < max_pts:
__pyx_t_16 = ((__pyx_v_d1 <= __pyx_v_distance) != 0); if (__pyx_t_16) { } else { __pyx_t_15 = __pyx_t_16; goto __pyx_L10_bool_binop_done; } __pyx_t_16 = ((__pyx_v_distance < __pyx_v_d2) != 0); if (__pyx_t_16) { } else { __pyx_t_15 = __pyx_t_16; goto __pyx_L10_bool_binop_done; } __pyx_t_16 = ((__pyx_v_nPoints < __pyx_v_max_pts) != 0); __pyx_t_15 = __pyx_t_16; __pyx_L10_bool_binop_done:; if (__pyx_t_15) { /* … */ } } }
+621: all_pts[nPoints] = img[y, x]
__pyx_t_17 = __pyx_v_y; __pyx_t_18 = __pyx_v_x; __pyx_t_19 = __pyx_v_nPoints; *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_all_pts.rcbuffer->pybuffer.buf, __pyx_t_19, __pyx_pybuffernd_all_pts.diminfo[0].strides) = (*__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_img.rcbuffer->pybuffer.buf, __pyx_t_17, __pyx_pybuffernd_img.diminfo[0].strides, __pyx_t_18, __pyx_pybuffernd_img.diminfo[1].strides));
+622: nPoints = nPoints+1
__pyx_v_nPoints = (__pyx_v_nPoints + 1);
623:
624: # Sort all pixels
+625: sorted_pts = all_pts[:nPoints]
__pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_nPoints); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 625, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = PySlice_New(Py_None, __pyx_t_2, Py_None); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 625, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = PyObject_GetItem(((PyObject *)__pyx_v_all_pts), __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 625, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_XDECREF_SET(__pyx_v_sorted_pts, __pyx_t_2); __pyx_t_2 = 0;
+626: sorted_pts.sort()
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_sorted_pts, __pyx_n_s_sort); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 626, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4); if (likely(__pyx_t_3)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_4, function); } } if (__pyx_t_3) { __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 626, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 626, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
627: # print sorted_pts
628:
629: # Get background value from all points (between percentage of start_p and end_p)
+630: start_ind = int(round(float(nPoints)*start_p/100))
__pyx_v_start_ind = ((int)round(((((double)__pyx_v_nPoints) * __pyx_v_start_p) / 100.0)));
+631: end_ind = int(round(float(nPoints)*end_p/100.))
__pyx_v_end_ind = ((int)round(((((double)__pyx_v_nPoints) * __pyx_v_end_p) / 100.)));
+632: print nPoints, start_ind, end_ind
__pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_nPoints); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 632, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_start_ind); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 632, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_end_ind); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 632, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 632, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_3); __pyx_t_2 = 0; __pyx_t_4 = 0; __pyx_t_3 = 0; if (__Pyx_Print(0, __pyx_t_5, 1) < 0) __PYX_ERR(0, 632, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
633:
+634: if start_ind < end_ind:
__pyx_t_15 = ((__pyx_v_start_ind < __pyx_v_end_ind) != 0); if (__pyx_t_15) { /* … */ goto __pyx_L13; }
+635: sumVal = 0.0
__pyx_v_sumVal = 0.0;
+636: for i in range(start_ind, end_ind):
__pyx_t_11 = __pyx_v_end_ind; for (__pyx_t_12 = __pyx_v_start_ind; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) { __pyx_v_i = __pyx_t_12;
+637: sumVal = sumVal + sorted_pts[i]
__pyx_t_5 = PyFloat_FromDouble(__pyx_v_sumVal); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 637, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_sorted_pts, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 0, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 637, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyNumber_Add(__pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 637, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_20 = __pyx_PyFloat_AsFloat(__pyx_t_4); if (unlikely((__pyx_t_20 == ((npy_float32)-1)) && PyErr_Occurred())) __PYX_ERR(0, 637, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_v_sumVal = __pyx_t_20; }
+638: ys[bin] = sumVal/float(end_ind-start_ind)
__pyx_t_21 = __pyx_v_bin; *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_ys.rcbuffer->pybuffer.buf, __pyx_t_21, __pyx_pybuffernd_ys.diminfo[0].strides) = (__pyx_v_sumVal / ((double)(__pyx_v_end_ind - __pyx_v_start_ind)));
639: else:
+640: ys[bin] = all_pts[start_ind]
/*else*/ { __pyx_t_22 = __pyx_v_start_ind; __pyx_t_23 = __pyx_v_bin; *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_ys.rcbuffer->pybuffer.buf, __pyx_t_23, __pyx_pybuffernd_ys.diminfo[0].strides) = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_all_pts.rcbuffer->pybuffer.buf, __pyx_t_22, __pyx_pybuffernd_all_pts.diminfo[0].strides)); } __pyx_L13:;
641:
+642: xs[bin] = (d1+d2)/2.
__pyx_t_24 = __pyx_v_bin; *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_xs.rcbuffer->pybuffer.buf, __pyx_t_24, __pyx_pybuffernd_xs.diminfo[0].strides) = ((__pyx_v_d1 + __pyx_v_d2) / 2.); }
643:
+644: return xs, ys
__Pyx_XDECREF(__pyx_r); __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 644, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(((PyObject *)__pyx_v_xs)); __Pyx_GIVEREF(((PyObject *)__pyx_v_xs)); PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_xs)); __Pyx_INCREF(((PyObject *)__pyx_v_ys)); __Pyx_GIVEREF(((PyObject *)__pyx_v_ys)); PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)__pyx_v_ys)); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
645:
646: @cython.cdivision(True)
+647: def replaceRmin(np.ndarray[np.float32_t, ndim=2] img, int rmin, double val):
/* Python wrapper */ static PyObject *__pyx_pw_12QF_utilities_29replaceRmin(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyMethodDef __pyx_mdef_12QF_utilities_29replaceRmin = {"replaceRmin", (PyCFunction)__pyx_pw_12QF_utilities_29replaceRmin, METH_VARARGS|METH_KEYWORDS, 0}; static PyObject *__pyx_pw_12QF_utilities_29replaceRmin(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyArrayObject *__pyx_v_img = 0; int __pyx_v_rmin; double __pyx_v_val; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("replaceRmin (wrapper)", 0); { static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_img,&__pyx_n_s_rmin,&__pyx_n_s_val,0}; PyObject* values[3] = {0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); CYTHON_FALLTHROUGH; case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (pos_args) { case 0: if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_img)) != 0)) kw_args--; else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_rmin)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("replaceRmin", 1, 3, 3, 1); __PYX_ERR(0, 647, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_val)) != 0)) kw_args--; else { __Pyx_RaiseArgtupleInvalid("replaceRmin", 1, 3, 3, 2); __PYX_ERR(0, 647, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "replaceRmin") < 0)) __PYX_ERR(0, 647, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); values[2] = PyTuple_GET_ITEM(__pyx_args, 2); } __pyx_v_img = ((PyArrayObject *)values[0]); __pyx_v_rmin = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_rmin == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 647, __pyx_L3_error) __pyx_v_val = __pyx_PyFloat_AsDouble(values[2]); if (unlikely((__pyx_v_val == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 647, __pyx_L3_error) } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("replaceRmin", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 647, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("QF_utilities.replaceRmin", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_img), __pyx_ptype_5numpy_ndarray, 1, "img", 0))) __PYX_ERR(0, 647, __pyx_L1_error) __pyx_r = __pyx_pf_12QF_utilities_28replaceRmin(__pyx_self, __pyx_v_img, __pyx_v_rmin, __pyx_v_val); /* function exit code */ goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_12QF_utilities_28replaceRmin(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_img, int __pyx_v_rmin, double __pyx_v_val) { int __pyx_v_x; int __pyx_v_y; int __pyx_v_height; int __pyx_v_width; __pyx_t_5numpy_float32_t __pyx_v_centerX; __pyx_t_5numpy_float32_t __pyx_v_centerY; __pyx_t_5numpy_float32_t __pyx_v_distance; __pyx_t_5numpy_float32_t __pyx_v_frmin; PyArrayObject *__pyx_v_result = 0; __pyx_t_5numpy_float32_t __pyx_v_replace_val; double __pyx_v_float_x; double __pyx_v_float_y; __Pyx_LocalBuf_ND __pyx_pybuffernd_img; __Pyx_Buffer __pyx_pybuffer_img; __Pyx_LocalBuf_ND __pyx_pybuffernd_result; __Pyx_Buffer __pyx_pybuffer_result; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("replaceRmin", 0); __pyx_pybuffer_result.pybuffer.buf = NULL; __pyx_pybuffer_result.refcount = 0; __pyx_pybuffernd_result.data = NULL; __pyx_pybuffernd_result.rcbuffer = &__pyx_pybuffer_result; __pyx_pybuffer_img.pybuffer.buf = NULL; __pyx_pybuffer_img.refcount = 0; __pyx_pybuffernd_img.data = NULL; __pyx_pybuffernd_img.rcbuffer = &__pyx_pybuffer_img; { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_img.rcbuffer->pybuffer, (PyObject*)__pyx_v_img, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) __PYX_ERR(0, 647, __pyx_L1_error) } __pyx_pybuffernd_img.diminfo[0].strides = __pyx_pybuffernd_img.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_img.diminfo[0].shape = __pyx_pybuffernd_img.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_img.diminfo[1].strides = __pyx_pybuffernd_img.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_img.diminfo[1].shape = __pyx_pybuffernd_img.rcbuffer->pybuffer.shape[1]; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; __Pyx_PyThreadState_declare __Pyx_PyThreadState_assign __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_img.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_result.rcbuffer->pybuffer); __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} __Pyx_AddTraceback("QF_utilities.replaceRmin", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; goto __pyx_L2; __pyx_L0:; __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_img.rcbuffer->pybuffer); __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_result.rcbuffer->pybuffer); __pyx_L2:; __Pyx_XDECREF((PyObject *)__pyx_v_result); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_tuple__36 = PyTuple_Pack(15, __pyx_n_s_img, __pyx_n_s_rmin, __pyx_n_s_val, __pyx_n_s_x, __pyx_n_s_y, __pyx_n_s_height, __pyx_n_s_width, __pyx_n_s_centerX, __pyx_n_s_centerY, __pyx_n_s_distance, __pyx_n_s_frmin, __pyx_n_s_result, __pyx_n_s_replace_val, __pyx_n_s_float_x, __pyx_n_s_float_y); if (unlikely(!__pyx_tuple__36)) __PYX_ERR(0, 647, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__36); __Pyx_GIVEREF(__pyx_tuple__36); /* … */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_12QF_utilities_29replaceRmin, NULL, __pyx_n_s_QF_utilities); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 647, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_replaceRmin, __pyx_t_1) < 0) __PYX_ERR(0, 647, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
648: cdef int x, y
+649: cdef int height = img.shape[0]
__pyx_v_height = (__pyx_v_img->dimensions[0]);
+650: cdef int width = img.shape[1]
__pyx_v_width = (__pyx_v_img->dimensions[1]);
+651: cdef np.float32_t centerX = width
__pyx_v_centerX = __pyx_v_width;
+652: cdef np.float32_t centerY = height
__pyx_v_centerY = __pyx_v_height;
653: cdef np.float32_t distance
+654: cdef np.float32_t frmin = float(rmin)
__pyx_v_frmin = ((double)__pyx_v_rmin);
+655: cdef np.ndarray[np.float32_t, ndim=2] result = np.array(img, dtype = np.float32)
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 655, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_array); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 655, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 655, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(((PyObject *)__pyx_v_img)); __Pyx_GIVEREF(((PyObject *)__pyx_v_img)); PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_img)); __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 655, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 655, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_float32); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 655, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_5) < 0) __PYX_ERR(0, 655, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 655, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 655, __pyx_L1_error) __pyx_t_6 = ((PyArrayObject *)__pyx_t_5); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_result.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) { __pyx_v_result = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_result.rcbuffer->pybuffer.buf = NULL; __PYX_ERR(0, 655, __pyx_L1_error) } else {__pyx_pybuffernd_result.diminfo[0].strides = __pyx_pybuffernd_result.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_result.diminfo[0].shape = __pyx_pybuffernd_result.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_result.diminfo[1].strides = __pyx_pybuffernd_result.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_result.diminfo[1].shape = __pyx_pybuffernd_result.rcbuffer->pybuffer.shape[1]; } } __pyx_t_6 = 0; __pyx_v_result = ((PyArrayObject *)__pyx_t_5); __pyx_t_5 = 0;
+656: cdef np.float32_t replace_val = float(val)
__pyx_v_replace_val = __pyx_v_val;
657:
+658: for x in range(width-rmin-1, width):
__pyx_t_7 = __pyx_v_width; for (__pyx_t_8 = ((__pyx_v_width - __pyx_v_rmin) - 1); __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) { __pyx_v_x = __pyx_t_8;
+659: float_x = float(x)
__pyx_v_float_x = ((double)__pyx_v_x);
+660: for y in range(height-rmin-1, height):
__pyx_t_9 = __pyx_v_height; for (__pyx_t_10 = ((__pyx_v_height - __pyx_v_rmin) - 1); __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) { __pyx_v_y = __pyx_t_10;
+661: float_y = float(y)
__pyx_v_float_y = ((double)__pyx_v_y);
+662: distance = sqrt((float_x-centerX)**2+(float_y-centerY)**2)
__pyx_v_distance = sqrt((pow((__pyx_v_float_x - __pyx_v_centerX), 2.0) + pow((__pyx_v_float_y - __pyx_v_centerY), 2.0)));
+663: if distance <= frmin:
__pyx_t_11 = ((__pyx_v_distance <= __pyx_v_frmin) != 0); if (__pyx_t_11) { /* … */ } } }
+664: result[y, x] = replace_val
__pyx_t_12 = __pyx_v_y; __pyx_t_13 = __pyx_v_x; *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float32_t *, __pyx_pybuffernd_result.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_result.diminfo[0].strides, __pyx_t_13, __pyx_pybuffernd_result.diminfo[1].strides) = __pyx_v_replace_val;
665:
+666: return result
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_result)); __pyx_r = ((PyObject *)__pyx_v_result); goto __pyx_L0;