summaryrefslogtreecommitdiffstats
path: root/Wrappers/Python
diff options
context:
space:
mode:
authorDaniil Kazantsev <dkazanc@hotmail.com>2018-02-26 13:20:33 +0000
committerDaniil Kazantsev <dkazanc@hotmail.com>2018-02-26 13:20:33 +0000
commit8082a76d4dfd9588590bab3fd26eae976b744a94 (patch)
treebcb96c1a5f4d0d0450a83102bf73063a5b88753c /Wrappers/Python
parentbcdf186ccdca54a3df383512ad5a117004500a60 (diff)
downloadregularization-8082a76d4dfd9588590bab3fd26eae976b744a94.tar.gz
regularization-8082a76d4dfd9588590bab3fd26eae976b744a94.tar.bz2
regularization-8082a76d4dfd9588590bab3fd26eae976b744a94.tar.xz
regularization-8082a76d4dfd9588590bab3fd26eae976b744a94.zip
cpu-related cython file updated #33
Diffstat (limited to 'Wrappers/Python')
-rw-r--r--Wrappers/Python/src/cpu_regularizers.pyx77
-rw-r--r--Wrappers/Python/src/gpu_regularizers.pyx2
2 files changed, 68 insertions, 11 deletions
diff --git a/Wrappers/Python/src/cpu_regularizers.pyx b/Wrappers/Python/src/cpu_regularizers.pyx
index e7ff78c..b8089a8 100644
--- a/Wrappers/Python/src/cpu_regularizers.pyx
+++ b/Wrappers/Python/src/cpu_regularizers.pyx
@@ -18,20 +18,20 @@ import cython
import numpy as np
cimport numpy as np
-cdef extern float TV_ROF(float *A, float *B, int dimX, int dimY, int dimZ,
- int iterationsNumb, float tau, float flambda);
+cdef extern float TV_ROF_CPU(float *Input, float *Output, int dimX, int dimY, int dimZ, int iterationsNumb, float tau, float flambda);
+cdef extern float TV_FGP_CPU(float *Input, float *Output, float lambda, int iter, float epsil, int methodTV, int nonneg, int printM, int dimX, int dimY, int dimZ);
-
-def ROF_TV(inputData, iterations, regularization_parameter,
+# Can we use the same name here in "def" as the C function?
+def TV_ROF_CPU(inputData, iterations, regularization_parameter,
marching_step_parameter):
if inputData.ndim == 2:
- return ROF_TV_2D(inputData, iterations, regularization_parameter,
+ return TV_ROF_2D(inputData, iterations, regularization_parameter,
marching_step_parameter)
elif inputData.ndim == 3:
- return ROF_TV_3D(inputData, iterations, regularization_parameter,
+ return TV_ROF_3D(inputData, iterations, regularization_parameter,
marching_step_parameter)
-def ROF_TV_2D(np.ndarray[np.float32_t, ndim=2, mode="c"] inputData,
+def TV_ROF_2D(np.ndarray[np.float32_t, ndim=2, mode="c"] inputData,
int iterations,
float regularization_parameter,
float marching_step_parameter
@@ -45,13 +45,13 @@ def ROF_TV_2D(np.ndarray[np.float32_t, ndim=2, mode="c"] inputData,
np.zeros([dims[0],dims[1]], dtype='float32')
#/* Run ROF iterations for 2D data */
- TV_ROF(&inputData[0,0], &B[0,0], dims[0], dims[1], 1, iterations,
+ TV_ROF_CPU(&inputData[0,0], &B[0,0], dims[0], dims[1], 1, iterations,
marching_step_parameter, regularization_parameter)
return B
-def ROF_TV_3D(np.ndarray[np.float32_t, ndim=3, mode="c"] inputData,
+def TV_ROF_3D(np.ndarray[np.float32_t, ndim=3, mode="c"] inputData,
int iterations,
float regularization_parameter,
float marching_step_parameter
@@ -65,8 +65,65 @@ def ROF_TV_3D(np.ndarray[np.float32_t, ndim=3, mode="c"] inputData,
np.zeros([dims[0],dims[1],dims[2]], dtype='float32')
#/* Run ROF iterations for 3D data */
- TV_ROF(&inputData[0,0, 0], &B[0,0, 0], dims[0], dims[1], dims[2], iterations,
+ TV_FGP_CPU(&inputData[0,0,0], &B[0,0,0], dims[0], dims[1], dims[2], iterations,
marching_step_parameter, regularization_parameter)
return B
+def TV_FGP_CPU(inputData, regularization_parameter, iterations, tolerance_param, methodTV, nonneg, printM):
+ if inputData.ndim == 2:
+ return TV_FGP_2D(inputData, regularization_parameter, iterations, tolerance_param, methodTV, nonneg, printM)
+ elif inputData.ndim == 3:
+ return TV_FGP_3D(inputData, regularization_parameter, iterations, tolerance_param, methodTV, nonneg, printM)
+
+def TV_FGP_2D(np.ndarray[np.float32_t, ndim=2, mode="c"] inputData,
+ float regularization_parameter,
+ int iterations,
+ float tolerance_param,
+ int methodTV,
+ int nonneg,
+ int printM):
+
+ cdef long dims[2]
+ dims[0] = inputData.shape[0]
+ dims[1] = inputData.shape[1]
+
+ cdef np.ndarray[np.float32_t, ndim=2, mode="c"] B = \
+ np.zeros([dims[0],dims[1]], dtype='float32')
+
+ #/* Run ROF iterations for 2D data */
+ TV_FGP_CPU(&inputData[0,0], &B[0,0], regularization_parameter,
+ iterations,
+ tolerance_param,
+ methodTV,
+ nonneg,
+ printM,
+ dims[0], dims[1], 1)
+
+ return B
+
+
+def TV_FGP_3D(np.ndarray[np.float32_t, ndim=3, mode="c"] inputData,
+ float regularization_parameter,
+ int iterations,
+ float tolerance_param,
+ int methodTV,
+ int nonneg,
+ int printM):
+ cdef long dims[2]
+ dims[0] = inputData.shape[0]
+ dims[1] = inputData.shape[1]
+ dims[2] = inputData.shape[2]
+
+ cdef np.ndarray[np.float32_t, ndim=3, mode="c"] B = \
+ np.zeros([dims[0],dims[1],dims[2]], dtype='float32')
+
+ #/* Run ROF iterations for 3D data */
+ TV_FGP_CPU(&inputData[0,0, 0], &B[0,0, 0], iterations,
+ tolerance_param,
+ methodTV,
+ nonneg,
+ printM,
+ dims[0], dims[1], dims[2])
+
+ return B
diff --git a/Wrappers/Python/src/gpu_regularizers.pyx b/Wrappers/Python/src/gpu_regularizers.pyx
index 263fa4a..a14a20d 100644
--- a/Wrappers/Python/src/gpu_regularizers.pyx
+++ b/Wrappers/Python/src/gpu_regularizers.pyx
@@ -396,7 +396,7 @@ def TVFGP2D(np.ndarray[np.float32_t, ndim=2, mode="c"] inputData,
# Running CUDA code here
TV_FGP_GPU(
&inputData[0,0], &B[0,0],
- regularization_parameter ,
+ regularization_parameter,
iterations,
tolerance_param,
methodTV,