MCPcopy Create free account
hub / github.com/HiLab-git/SimpleCRF / interactive_maxflow2d_wrapper

Function interactive_maxflow2d_wrapper

maxflow_python/maxflow.cpp:61–116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59}
60
61static PyObject *
62interactive_maxflow2d_wrapper(PyObject *self, PyObject *args)
63{
64 PyObject *I=NULL, *P=NULL, *S=NULL, *param=NULL;
65 PyArrayObject *arr_I=NULL, *arr_P=NULL, *arr_S=NULL;
66 if (!PyArg_ParseTuple(args, "OOOO", &I, &P, &S, &param)) return NULL;
67
68 arr_I = (PyArrayObject*)PyArray_FROM_OTF(I, NPY_FLOAT32, NPY_IN_ARRAY);
69 arr_P = (PyArrayObject*)PyArray_FROM_OTF(P, NPY_FLOAT32, NPY_IN_ARRAY);
70 arr_S = (PyArrayObject*)PyArray_FROM_OTF(S, NPY_UINT8, NPY_IN_ARRAY);
71 if (arr_I == NULL || arr_P == NULL || arr_S == NULL) return NULL;
72 float lambda = PyFloat_AsDouble(PyTuple_GET_ITEM(param, 0));
73 float sigma = PyFloat_AsDouble(PyTuple_GET_ITEM(param, 1));
74
75 /*vv* code that makes use of arguments *vv*/
76 int dimI = PyArray_NDIM(arr_I); // number of dimensions
77 int dimP = PyArray_NDIM(arr_P);
78 int dimS = PyArray_NDIM(arr_S);
79 npy_intp * shapeI = PyArray_DIMS(arr_I); // npy_intp array of length nd showing length in each dim.
80 npy_intp * shapeP = PyArray_DIMS(arr_P);
81 npy_intp * shapeS = PyArray_DIMS(arr_S);
82
83 if(dimI > 3){
84 cout << "the input dimension can only be 2 or 3"<<endl;
85 return NULL;
86 }
87 if(dimP != 3 || dimS != 3){
88 cout << "dimension of probabilily map and seed map should be 3"<<endl;
89 return NULL;
90 }
91 if(shapeI[0] != shapeP[0] || shapeI[1] != shapeP[1] ||
92 shapeI[0] != shapeS[0] || shapeI[1] != shapeS[1]){
93 cout << "image, probability map, and seed map should have the same spatial size"<<endl;
94 return NULL;
95 }
96 if(shapeP[2] != 2 || shapeS[2] !=2){
97 cout << "probabilily map and seed map should have two channels"<<endl;
98 return NULL;
99 }
100
101 int chns = 1;
102 if(dimI == 3) chns = shapeI[2];
103 npy_intp outshape[2];
104 outshape[0]=shapeI[0];
105 outshape[1]=shapeI[1];
106 PyArrayObject * arr_L = (PyArrayObject*) PyArray_SimpleNew(2, outshape, NPY_INT8);
107 maxflow_inference((unsigned char *) arr_L->data, (const float *) arr_I->data,
108 (const float *) arr_P->data, (const unsigned char *) arr_S->data,
109 shapeI[0], shapeI[1], chns, 2, lambda, sigma);
110
111 Py_DECREF(arr_I);
112 Py_DECREF(arr_P);
113 Py_DECREF(arr_S);
114 Py_INCREF(arr_L);
115 return PyArray_Return(arr_L);
116}
117
118static PyObject *

Callers

nothing calls this directly

Calls 1

maxflow_inferenceFunction · 0.85

Tested by

no test coverage detected