better peak extraction
[imago.git] / pcf.c
diff --git a/pcf.c b/pcf.c
index 2a43188..1682dbb 100644 (file)
--- a/pcf.c
+++ b/pcf.c
@@ -1,6 +1,30 @@
 #include <Python.h>
 #include <math.h>
 
 #include <Python.h>
 #include <math.h>
 
+static PyObject* py_combine(PyObject* self, PyObject* args)
+{
+       const unsigned char *im_bg;
+       const unsigned char *im_fg;
+       int size;
+
+       int i;
+       long int sum;
+       int area;
+
+       if (!PyArg_ParseTuple(args, "s#s#", &im_bg, &size, &im_fg, &size)) return NULL;
+
+       sum = 0;
+       area = 0;
+       for (i=0; i < size; i++) {
+               if (im_fg[i]){
+                       sum += im_bg[i];
+                       area++;
+               }
+       }
+
+       return Py_BuildValue("d", ((double) sum) / area);
+}
+
 static PyObject* py_hough(PyObject* self, PyObject* args)
 {
        const unsigned char *image;
 static PyObject* py_hough(PyObject* self, PyObject* args)
 {
        const unsigned char *image;
@@ -128,6 +152,7 @@ static PyObject* py_edge(PyObject* self, PyObject* args)
 
 
 static PyMethodDef myModule_methods[] = {
 
 
 static PyMethodDef myModule_methods[] = {
+       {"combine", py_combine, METH_VARARGS},
        {"edge", py_edge, METH_VARARGS},
        {"hough", py_hough, METH_VARARGS},
        {NULL, NULL}
        {"edge", py_edge, METH_VARARGS},
        {"hough", py_hough, METH_VARARGS},
        {NULL, NULL}