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

scipy-svn@scip... scipy-svn@scip...
Thu Apr 24 17:53:31 CDT 2008


Author: tom.waite
Date: 2008-04-24 17:53:28 -0500 (Thu, 24 Apr 2008)
New Revision: 4173

Modified:
   trunk/scipy/ndimage/src/register/Register_EXT.c
Log:
resample_with_gradient to work with numpy.mgrid coordinates

Modified: trunk/scipy/ndimage/src/register/Register_EXT.c
===================================================================
--- trunk/scipy/ndimage/src/register/Register_EXT.c	2008-04-24 21:41:27 UTC (rev 4172)
+++ trunk/scipy/ndimage/src/register/Register_EXT.c	2008-04-24 22:53:28 UTC (rev 4173)
@@ -421,15 +421,110 @@
 
 
 
+static PyObject *Register_ResampleWGradientWCoords(PyObject *self, PyObject *args)
+{
+
+    int num;
+    int size;
+    int nd;
+    int type;
+    int itype;
+    int nd_rotmatrix;
+    int nd_S;
+    npy_intp *dimsScale;
+    npy_intp *dimsOffset;
+    npy_intp *dimsS;
+    npy_intp *dimsD;
+    npy_intp *dims_rotmatrix;
+    npy_intp *dims_S;
+    npy_intp *dims_Coords;
+    unsigned char *imageS;
+    unsigned char *imageD;
+    double        *M;
+    double        *X;
+    double        *Y;
+    double        *Z;
+    int           *S;
+    double        *scale;
+    int           *offset;
+    double        *gradientX;
+    double        *gradientY;
+    double        *gradientZ;
+    PyObject *imgArrayS    = NULL;
+    PyObject *imgArrayD    = NULL;
+    PyObject *rotArray     = NULL;
+    PyObject *SArray       = NULL;
+    PyObject *scaleArray   = NULL;
+    PyObject *offsetArray  = NULL;
+    PyObject *gradXArray   = NULL;
+    PyObject *gradYArray   = NULL;
+    PyObject *gradZArray   = NULL;
+    PyObject *coordXArray  = NULL;
+    PyObject *coordYArray  = NULL;
+    PyObject *coordZArray  = NULL;
+	
+    if(!PyArg_ParseTuple(args, "OOOOOOOOOOOO", &coordZArray, &coordYArray, &coordXArray,
+                                &imgArrayS, &imgArrayD, &rotArray, &SArray, &scaleArray,
+			        &offsetArray, &gradXArray, &gradYArray, &gradZArray))
+	goto exit;
+
+    /* check in the Python code that S and D are the same dims, type */
+    imageS = (unsigned char *)PyArray_DATA(imgArrayS);
+    imageD = (unsigned char *)PyArray_DATA(imgArrayD);
+    /* reads dims as 0 = layers, 1 = rows, 2 = cols */
+    nd     = PyArray_NDIM(imgArrayS);
+    dimsS  = PyArray_DIMS(imgArrayS);
+    dimsD  = PyArray_DIMS(imgArrayD);
+    type   = PyArray_TYPE(imgArrayS);
+    num    = PyArray_SIZE(imgArrayS);
+
+    M = (double *)PyArray_DATA(rotArray);
+    nd_rotmatrix   = PyArray_NDIM(rotArray);
+    dims_rotmatrix = PyArray_DIMS(rotArray);
+
+    S = (int *)PyArray_DATA(SArray);
+    nd_S   = PyArray_NDIM(SArray);
+    dims_S = PyArray_DIMS(SArray);
+
+    scale  = (double *)PyArray_DATA(scaleArray);
+    offset = (int *)PyArray_DATA(offsetArray);
+    dimsScale  = PyArray_DIMS(scaleArray);
+    dimsOffset = PyArray_DIMS(offsetArray);
+
+    gradientX = (double *)PyArray_DATA(gradXArray);
+    gradientY = (double *)PyArray_DATA(gradYArray);
+    gradientZ = (double *)PyArray_DATA(gradZArray);
+
+    X = (double *)PyArray_DATA(coordXArray);
+    Y = (double *)PyArray_DATA(coordYArray);
+    Z = (double *)PyArray_DATA(coordZArray);
+
+    dims_Coords = PyArray_DIMS(coordXArray);
+    size = PyArray_SIZE(coordXArray);
+
+    if(!NI_ResampleWGradientWCoords(size, (int)dimsS[0], (int)dimsS[1], (int)dimsS[2], (int)dimsD[0], 
+			            (int)dimsD[1], (int)dimsD[2], S, X, Y, Z, M, imageD, imageS, scale, 
+				    offset, gradientX, gradientY, gradientZ))
+	    goto exit;
+
+exit:
+
+    return PyErr_Occurred() ? NULL : (PyObject*)Py_BuildValue(""); 
+
+}
+
+
+
 static PyMethodDef RegisterMethods[] =
 {
-    { "register_resample_w_gradient", Register_ResampleWithGradient, METH_VARARGS, NULL },
-    { "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_volume_resample",     Register_VolumeResample,       METH_VARARGS, NULL },
-    { "register_image_threshold",     Register_ImageThreshold,       METH_VARARGS, NULL },
+    { "register_resample_w_gradient_w_coords", Register_ResampleWGradientWCoords, METH_VARARGS, NULL },
+    { "register_resample_w_gradient",          Register_ResampleWithGradient,     METH_VARARGS, NULL },
+    { "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_volume_resample",              Register_VolumeResample,           METH_VARARGS, NULL },
+    { "register_image_threshold",              Register_ImageThreshold,           METH_VARARGS, NULL },
     {  NULL, NULL, 0, NULL},
 };
 



More information about the Scipy-svn mailing list