[Scipy-svn] r3956 - trunk/scipy/ndimage/src/register

scipy-svn@scip... scipy-svn@scip...
Fri Feb 22 19:41:58 CST 2008


Author: tom.waite
Date: 2008-02-22 19:41:56 -0600 (Fri, 22 Feb 2008)
New Revision: 3956

Modified:
   trunk/scipy/ndimage/src/register/Register_EXT.c
Log:
added integrated histogram based volume thresholding

Modified: trunk/scipy/ndimage/src/register/Register_EXT.c
===================================================================
--- trunk/scipy/ndimage/src/register/Register_EXT.c	2008-02-23 01:41:38 UTC (rev 3955)
+++ trunk/scipy/ndimage/src/register/Register_EXT.c	2008-02-23 01:41:56 UTC (rev 3956)
@@ -250,12 +250,58 @@
 
 }
 
+
+static PyObject *Register_ImageThreshold(PyObject *self, PyObject *args)
+{
+
+    /* set threshold from the volume integrated histogram */
+    int num;
+    int nd;
+    int type;
+    int itype;
+    int histogram_elements;
+    int	tindex;
+    npy_intp *dimsImage;
+    npy_intp *dimsHistogram;
+    unsigned short *image;
+    double *H;
+    double *IH;
+    double threshold;
+    PyObject *imgArray   = NULL;
+    PyObject *histogram  = NULL;
+    PyObject *ihistogram = NULL;
+	
+    if(!PyArg_ParseTuple(args, "OOOd", &imgArray, &histogram, &ihistogram, &threshold))
+	goto exit;
+
+    image = (unsigned short *)PyArray_DATA(imgArray);
+    /* reads dims as 0 = layers, 1 = rows, 2 = cols */
+    nd        = PyArray_NDIM(imgArray);
+    dimsImage = PyArray_DIMS(imgArray);
+    type      = PyArray_TYPE(imgArray);
+    num       = PyArray_SIZE(imgArray);
+
+    H  = (double *)PyArray_DATA(histogram);
+    IH = (double *)PyArray_DATA(ihistogram);
+    histogram_elements = PyArray_SIZE(histogram);
+
+    if(!NI_ImageThreshold((int)dimsImage[0], (int)dimsImage[1], (int)dimsImage[2], 
+		               image, H, IH, histogram_elements, threshold, &tindex))
+	    goto exit;
+
+exit:
+
+    return PyErr_Occurred() ? NULL : (PyObject*)Py_BuildValue("i", tindex); 
+
+}
+
 static PyMethodDef RegisterMethods[] =
 {
     { "register_histogram",       Register_Histogram,      METH_VARARGS, NULL },
     { "register_histogram_lite",  Register_HistogramLite,  METH_VARARGS, NULL },
     { "register_linear_resample", Register_LinearResample, METH_VARARGS, NULL },
     { "register_cubic_resample",  Register_CubicResample,  METH_VARARGS, NULL },
+    { "register_image_threshold", Register_ImageThreshold, METH_VARARGS, NULL },
     {  NULL, NULL, 0, NULL},
 };
 



More information about the Scipy-svn mailing list