| 116 | } |
| 117 | |
| 118 | static PyObject * |
| 119 | maxflow3d_wrapper(PyObject *self, PyObject *args) |
| 120 | { |
| 121 | PyObject *I=NULL, *P=NULL, *param=NULL; |
| 122 | PyArrayObject *arr_I=NULL, *arr_P=NULL; |
| 123 | if (!PyArg_ParseTuple(args, "OOO", &I, &P, ¶m)) return NULL; |
| 124 | |
| 125 | arr_I = (PyArrayObject*)PyArray_FROM_OTF(I, NPY_FLOAT32, NPY_IN_ARRAY); |
| 126 | arr_P = (PyArrayObject*)PyArray_FROM_OTF(P, NPY_FLOAT32, NPY_IN_ARRAY); |
| 127 | if (arr_I == NULL || arr_P == NULL) return NULL; |
| 128 | float lambda = PyFloat_AsDouble(PyTuple_GET_ITEM(param, 0)); |
| 129 | float sigma = PyFloat_AsDouble(PyTuple_GET_ITEM(param, 1)); |
| 130 | |
| 131 | /*vv* code that makes use of arguments *vv*/ |
| 132 | int dimI = PyArray_NDIM(arr_I); // number of dimensions |
| 133 | int dimP = PyArray_NDIM(arr_P); |
| 134 | npy_intp * shapeI = PyArray_DIMS(arr_I); // npy_intp array of length nd showing length in each dim |
| 135 | npy_intp * shapeP = PyArray_DIMS(arr_P); |
| 136 | |
| 137 | if(dimI !=3 && dimI != 4){ |
| 138 | cout << "the input dimension can only be 3 or 4"<<endl; |
| 139 | return NULL; |
| 140 | } |
| 141 | if(dimP != 4){ |
| 142 | cout << "dimension of probabilily map should be 4"<<endl; |
| 143 | return NULL; |
| 144 | } |
| 145 | if(shapeI[0] != shapeP[0] || shapeI[1] != shapeP[1] || shapeI[2] != shapeP[2]){ |
| 146 | cout << "image and probability map have different sizes"<<endl; |
| 147 | return NULL; |
| 148 | } |
| 149 | if(shapeP[3] != 2){ |
| 150 | cout << "probabilily map should have two channels"<<endl; |
| 151 | return NULL; |
| 152 | } |
| 153 | |
| 154 | int chns = 1; |
| 155 | if(dimI == 4) chns = shapeI[3]; |
| 156 | npy_intp outshape[3] = {shapeI[0], shapeI[1], shapeI[2]}; |
| 157 | PyArrayObject * arr_L = (PyArrayObject*) PyArray_SimpleNew(3, outshape, NPY_INT8); |
| 158 | maxflow3d_inference((unsigned char *) arr_L->data, (const float *) arr_I->data, |
| 159 | (const float *) arr_P->data, NULL, |
| 160 | shapeI[0], shapeI[1], shapeI[2], chns, 2, lambda, sigma); |
| 161 | |
| 162 | Py_DECREF(arr_I); |
| 163 | Py_DECREF(arr_P); |
| 164 | Py_INCREF(arr_L); |
| 165 | return PyArray_Return(arr_L); |
| 166 | } |
| 167 | |
| 168 | static PyObject * |
| 169 | interactive_maxflow3d_wrapper(PyObject *self, PyObject *args) |
nothing calls this directly
no test coverage detected