From ccf9b61bba1004af783c6333d58ea9611c0f81f2 Mon Sep 17 00:00:00 2001 From: Daniil Kazantsev Date: Tue, 6 Mar 2018 11:16:41 +0000 Subject: ROF_FGP_unified syntax --- Wrappers/Python/src/cpu_regularizers.pyx | 59 +++++++++++++++----------------- 1 file changed, 27 insertions(+), 32 deletions(-) (limited to 'Wrappers/Python') diff --git a/Wrappers/Python/src/cpu_regularizers.pyx b/Wrappers/Python/src/cpu_regularizers.pyx index 448da31..2654831 100644 --- a/Wrappers/Python/src/cpu_regularizers.pyx +++ b/Wrappers/Python/src/cpu_regularizers.pyx @@ -11,73 +11,68 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -Author: Edoardo Pasca +Author: Edoardo Pasca, Daniil Kazantsev """ import cython import numpy as np cimport numpy as np -cdef extern float TV_ROF_CPU_main(float *Input, float *Output, int dimX, int dimY, int dimZ, int iterationsNumb, float tau, float flambda); -cdef extern float TV_FGP_CPU_main(float *Input, float *Output, float lambdaPar, int iter, float epsil, int methodTV, int nonneg, int printM, int dimX, int dimY, int dimZ); +cdef extern float TV_ROF_CPU_main(float *Input, float *Output, float lambdaPar, int iterationsNumb, float tau, int dimX, int dimY, int dimZ); +cdef extern float TV_FGP_CPU_main(float *Input, float *Output, float lambdaPar, int iterationsNumb, float epsil, int methodTV, int nonneg, int printM, int dimX, int dimY, int dimZ); -# Can we use the same name here in "def" as the C function? -def TV_ROF_CPU(inputData, iterations, regularization_parameter, +def TV_ROF_CPU(inputData, regularization_parameter, iterationsNumb marching_step_parameter): if inputData.ndim == 2: - return TV_ROF_2D(inputData, iterations, regularization_parameter, + return TV_ROF_2D(inputData, regularization_parameter, iterationsNumb marching_step_parameter) elif inputData.ndim == 3: - return TV_ROF_3D(inputData, iterations, regularization_parameter, + return TV_ROF_3D(inputData, regularization_parameter, iterationsNumb marching_step_parameter) def TV_ROF_2D(np.ndarray[np.float32_t, ndim=2, mode="c"] inputData, - int iterations, float regularization_parameter, - float marching_step_parameter - ): - + int iterationsNumb, + float marching_step_parameter): 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 = \ + cdef np.ndarray[np.float32_t, ndim=2, mode="c"] outputData = \ np.zeros([dims[0],dims[1]], dtype='float32') - #/* Run ROF iterations for 2D data */ - TV_ROF_CPU_main(&inputData[0,0], &B[0,0], dims[0], dims[1], 1, iterations, - marching_step_parameter, regularization_parameter) + # Run ROF iterations for 2D data + TV_ROF_CPU_main(&inputData[0,0], &outputData[0,0], regularization_parameter, iterationsNumb, marching_step_parameter, dims[0], dims[1], 1) - return B + return outputData def TV_ROF_3D(np.ndarray[np.float32_t, ndim=3, mode="c"] inputData, int iterations, float regularization_parameter, float marching_step_parameter ): - cdef long dims[2] + cdef long dims[3] 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 = \ + cdef np.ndarray[np.float32_t, ndim=3, mode="c"] outputData = \ np.zeros([dims[0],dims[1],dims[2]], dtype='float32') - #/* Run ROF iterations for 3D data */ - TV_ROF_CPU_main(&inputData[0,0,0], &B[0,0,0], dims[0], dims[1], dims[2], iterations, - marching_step_parameter, regularization_parameter) + # Run ROF iterations for 3D data + TV_ROF_CPU_main(&inputData[0,0,0], &outputData[0,0,0], regularization_parameter, iterationsNumb, marching_step_parameter, dims[0], dims[1], dims[2]) - return B + return outputData -def TV_FGP_CPU(inputData, regularization_parameter, iterations, tolerance_param, methodTV, nonneg, printM): +def TV_FGP_CPU(inputData, regularization_parameter, iterationsNumb, tolerance_param, methodTV, nonneg, printM): if inputData.ndim == 2: - return TV_FGP_2D(inputData, regularization_parameter, iterations, tolerance_param, methodTV, nonneg, printM) + return TV_FGP_2D(inputData, regularization_parameter, iterationsNumb, tolerance_param, methodTV, nonneg, printM) elif inputData.ndim == 3: - return TV_FGP_3D(inputData, regularization_parameter, iterations, tolerance_param, methodTV, nonneg, printM) + return TV_FGP_3D(inputData, regularization_parameter, iterationsNumb, tolerance_param, methodTV, nonneg, printM) def TV_FGP_2D(np.ndarray[np.float32_t, ndim=2, mode="c"] inputData, float regularization_parameter, - int iterations, + int iterationsNumb, float tolerance_param, int methodTV, int nonneg, @@ -92,7 +87,7 @@ def TV_FGP_2D(np.ndarray[np.float32_t, ndim=2, mode="c"] inputData, #/* Run ROF iterations for 2D data */ TV_FGP_CPU_main(&inputData[0,0], &outputData[0,0], regularization_parameter, - iterations, + iterationsNumb, tolerance_param, methodTV, nonneg, @@ -103,22 +98,22 @@ def TV_FGP_2D(np.ndarray[np.float32_t, ndim=2, mode="c"] inputData, def TV_FGP_3D(np.ndarray[np.float32_t, ndim=3, mode="c"] inputData, float regularization_parameter, - int iterations, + int iterationsNumb, float tolerance_param, int methodTV, int nonneg, int printM): - cdef long dims[2] + cdef long dims[3] 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"] outputData = \ - np.zeros([dims[0],dims[1],dims[2]], dtype='float32') + np.zeros([dims[0], dims[1], dims[2]], dtype='float32') #/* Run ROF iterations for 3D data */ - TV_FGP_CPU_main(&inputData[0,0,0], &outputData[0,0, 0], regularization_parameter, - iterations, + TV_FGP_CPU_main(&inputData[0,0,0], &outputData[0,0,0], regularization_parameter, + iterationsNumb, tolerance_param, methodTV, nonneg, -- cgit v1.2.3