parameters
[imago.git] / pcf.c
diff --git a/pcf.c b/pcf.c
index 8cb8a4b..cc41aa3 100644 (file)
--- a/pcf.c
+++ b/pcf.c
@@ -1,6 +1,39 @@
 #include <Python.h>
 #include <math.h>
 
+/* TODO delete or document this
+ *
+ */
+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);
+}
+
+/* Hough transform
+ *
+ * Takes dimentions of the image, the image, initial angle and TODO dt is what?.
+ * Computes Hough transform of the image. TODO size etc.
+ *
+ */
 static PyObject* py_hough(PyObject* self, PyObject* args)
 {
        const unsigned char *image;
@@ -24,6 +57,9 @@ static PyObject* py_hough(PyObject* self, PyObject* args)
        PyObject *result;
 
        if (!PyArg_ParseTuple(args, "(ii)s#dd", &x, &y, &image, &size, &init_angle, &dt)) return NULL;
+       // x and y are width and height of the image as ints
+       // Python sends image as (byte)string and since it is not null-terminated, must send its size
+       // init_angle and dt are doubles
        
 
        matrix = (int*) malloc(size * sizeof(int));
@@ -71,6 +107,10 @@ static PyObject* py_hough(PyObject* self, PyObject* args)
        return result;
 }
 
+/* Edge detection
+ *
+ * Takes image size, the image, and the size of TODO what?
+ */
 static PyObject* py_edge(PyObject* self, PyObject* args)
 {
        const unsigned char *image;
@@ -86,6 +126,8 @@ static PyObject* py_edge(PyObject* self, PyObject* args)
        PyObject *result;
 
        if (!PyArg_ParseTuple(args, "(ii)s#", &x, &y, &image, &size)) return NULL;
+       // x and y are width and height of the image as ints
+       // Python sends image as (byte)string and since it is not null-terminated, must send its size
 
        n_image = (char*) malloc(size);
        for (i=0; i < 2 * x; i++) {
@@ -112,7 +154,7 @@ static PyObject* py_edge(PyObject* self, PyObject* args)
                                image[x * (j + 2) + i + 1] + image[x * (j + 2) + i + 2] +
                                image[x * (j + 1) + i - 2] + image[x * (j + 1) + i - 1] + image[x * (j + 1) + i] + 
                                image[x * (j + 1) + i + 1] + image[x * (j + 1) + i + 2] 
-                               - (25 * image[x * j + i]);
+                               - (24 * image[x * j + i]);
                        if (sum < 0) sum = 0;
                        if (sum > 255) sum = 255;
                        n_image[x * j + i] = sum;
@@ -128,6 +170,7 @@ static PyObject* py_edge(PyObject* self, PyObject* args)
 
 
 static PyMethodDef myModule_methods[] = {
+       {"combine", py_combine, METH_VARARGS},
        {"edge", py_edge, METH_VARARGS},
        {"hough", py_hough, METH_VARARGS},
        {NULL, NULL}