| 166 | } |
| 167 | |
| 168 | static PyObject * |
| 169 | interactive_maxflow3d_wrapper(PyObject *self, PyObject *args) |
| 170 | { |
| 171 | PyObject *I=NULL, *P=NULL, *S=NULL, *param=NULL; |
| 172 | PyArrayObject *arr_I=NULL, *arr_P=NULL, *arr_S=NULL; |
| 173 | if (!PyArg_ParseTuple(args, "OOOO", &I, &P, &S, ¶m)) return NULL; |
| 174 | |
| 175 | arr_I = (PyArrayObject*)PyArray_FROM_OTF(I, NPY_FLOAT32, NPY_IN_ARRAY); |
| 176 | arr_P = (PyArrayObject*)PyArray_FROM_OTF(P, NPY_FLOAT32, NPY_IN_ARRAY); |
| 177 | arr_S = (PyArrayObject*)PyArray_FROM_OTF(S, NPY_UINT8, NPY_IN_ARRAY); |
| 178 | if (arr_I == NULL || arr_P == NULL || arr_S == NULL) return NULL; |
| 179 | float lambda = PyFloat_AsDouble(PyTuple_GET_ITEM(param, 0)); |
| 180 | float sigma = PyFloat_AsDouble(PyTuple_GET_ITEM(param, 1)); |
| 181 | |
| 182 | /*vv* code that makes use of arguments *vv*/ |
| 183 | int dimI = PyArray_NDIM(arr_I); // number of dimensions |
| 184 | int dimP = PyArray_NDIM(arr_P); |
| 185 | int dimS = PyArray_NDIM(arr_S); |
| 186 | npy_intp * shapeI = PyArray_DIMS(arr_I); // npy_intp array of length nd showing length in each dim. |
| 187 | npy_intp * shapeP = PyArray_DIMS(arr_P); |
| 188 | npy_intp * shapeS = PyArray_DIMS(arr_S); |
| 189 | |
| 190 | if(dimI !=3 && dimI != 4){ |
| 191 | cout << "the input dimension can only be 3 or 4"<<endl; |
| 192 | return NULL; |
| 193 | } |
| 194 | if(dimP != 4 || dimS != 4){ |
| 195 | cout << "dimension of probabilily map and seed map should be 4"<<endl; |
| 196 | return NULL; |
| 197 | } |
| 198 | if(shapeI[0] != shapeP[0] || shapeI[1] != shapeP[1] || shapeI[2] != shapeP[2] || |
| 199 | shapeI[0] != shapeS[0] || shapeI[1] != shapeS[1] || shapeI[2] != shapeS[2]){ |
| 200 | cout << "image, probability map, and seed map should have the same spatial size"<<endl; |
| 201 | return NULL; |
| 202 | } |
| 203 | if(shapeP[3] != 2 || shapeS[3] !=2){ |
| 204 | cout << "probabilily map and seed map should have two channels"<<endl; |
| 205 | return NULL; |
| 206 | } |
| 207 | |
| 208 | int chns = 1; |
| 209 | if(dimI == 4) chns = shapeI[3]; |
| 210 | npy_intp outshape[3] = {shapeI[0], shapeI[1], shapeI[2]}; |
| 211 | PyArrayObject * arr_L = (PyArrayObject*) PyArray_SimpleNew(3, outshape, NPY_INT8); |
| 212 | maxflow3d_inference((unsigned char *) arr_L->data, (const float *) arr_I->data, |
| 213 | (const float *) arr_P->data, (const unsigned char *) arr_S->data, |
| 214 | shapeI[0], shapeI[1], shapeI[2], chns, 2, lambda, sigma); |
| 215 | |
| 216 | Py_DECREF(arr_I); |
| 217 | Py_DECREF(arr_P); |
| 218 | Py_DECREF(arr_S); |
| 219 | Py_INCREF(arr_L); |
| 220 | return PyArray_Return(arr_L); |
| 221 | } |
| 222 | |
| 223 | static PyMethodDef Methods[] = { |
| 224 | {"maxflow2d", maxflow2d_wrapper, METH_VARARGS, "computing 2D max flow"}, |
nothing calls this directly
no test coverage detected