diff options
author | Daniil Kazantsev <dkazanc@hotmail.com> | 2018-02-16 14:09:52 +0000 |
---|---|---|
committer | Edoardo Pasca <edo.paskino@gmail.com> | 2018-02-20 16:18:46 +0000 |
commit | deac578f1919cba530d4dd0a92ea4975eb8ed43b (patch) | |
tree | 8e01f61286ee33a9c48d33a3fb362b6b7d4caf38 /Wrappers/Python | |
parent | fe095e13aed4831c372a542ba83c409f6c71af87 (diff) | |
download | regularization-deac578f1919cba530d4dd0a92ea4975eb8ed43b.tar.gz regularization-deac578f1919cba530d4dd0a92ea4975eb8ed43b.tar.bz2 regularization-deac578f1919cba530d4dd0a92ea4975eb8ed43b.tar.xz regularization-deac578f1919cba530d4dd0a92ea4975eb8ed43b.zip |
ROF_TV modified and GPU code added, all cython related files updated, but not testes
Diffstat (limited to 'Wrappers/Python')
-rw-r--r-- | Wrappers/Python/src/cpu_regularizers.pyx | 57 | ||||
-rw-r--r-- | Wrappers/Python/src/gpu_regularizers.pyx | 62 |
2 files changed, 73 insertions, 46 deletions
diff --git a/Wrappers/Python/src/cpu_regularizers.pyx b/Wrappers/Python/src/cpu_regularizers.pyx index b22e603..e306ab3 100644 --- a/Wrappers/Python/src/cpu_regularizers.pyx +++ b/Wrappers/Python/src/cpu_regularizers.pyx @@ -18,12 +18,7 @@ import cython import numpy as np cimport numpy as np -cdef extern float TV_main(float *D1, float *D2, float *D3, float *B, float *A, - float lambda, float tau, int dimY, int dimX, int dimZ); -cdef extern float D1_func(float *A, float *D1, int dimY, int dimX, int dimZ); -cdef extern float D2_func(float *A, float *D2, int dimY, int dimX, int dimZ); -cdef extern float D3_func(float *A, float *D3, int dimY, int dimX, int dimZ); -cdef extern void copyIm (float *A, float *U, int dimX, int dimY, int dimZ); +cdef extern float TV_ROF(float *A, float *B, int dimX, int dimY, int dimZ, int iterationsNumb, float tau, float lambda); def ROF_TV(inputData, iterations, regularization_parameter, marching_step_parameter): @@ -39,30 +34,17 @@ def ROF_TV_2D(np.ndarray[np.float32_t, ndim=2, mode="c"] inputData, float regularization_parameter 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 = \ np.zeros([dims[0],dims[1]], dtype='float32') - cdef np.ndarray[np.float32_t, ndim=2, mode="c"] D1 = \ - np.zeros([dims[0],dims[1]], dtype='float32') - cdef np.ndarray[np.float32_t, ndim=2, mode="c"] D2 = \ - np.zeros([dims[0],dims[1]], dtype='float32') - - copyIm(&inputData[0,0], &B[0,0], dims[0], dims[1], 1); - #/* start TV iterations */ - cdef int i = 0; - for i in range(iterations): - - #/* calculate differences */ - D1_func(&B[0,0], &D1[0,0], dims[0], dims[1], 1); - D2_func(&B[0,0], &D2[0,0], dims[0], dims[1], 1); - - #/* calculate divergence and image update*/ - TV_main(&D1[0,0], &D2[0,0], &D2[0,0], &B[0,0], &A[0,0], - regularization_parameter, marching_step_parameter, - dims[0], dims[1], 1) + + #/* Run ROF iterations for 2D data */ + TV_ROF(&A[0,0], &B[0,0], dims[0], dims[1], 1, iterations, marching_step_parameter, regularization_parameter) + return B @@ -78,26 +60,9 @@ def ROF_TV_3D(np.ndarray[np.float32_t, ndim=3, mode="c"] inputData, cdef np.ndarray[np.float32_t, ndim=3, mode="c"] B = \ np.zeros([dims[0],dims[1],dims[2]], dtype='float32') - cdef np.ndarray[np.float32_t, ndim=3, mode="c"] D1 = \ - np.zeros([dims[0],dims[1],dims[2]], dtype='float32') - cdef np.ndarray[np.float32_t, ndim=3, mode="c"] D2 = \ - np.zeros([dims[0],dims[1],dims[2]], dtype='float32') - cdef np.ndarray[np.float32_t, ndim=3, mode="c"] D3 = \ - np.zeros([dims[0],dims[1],dims[2]], dtype='float32') - - copyIm(&inputData[0,0,0], &B[0,0,0], dims[0], dims[1], dims[2]); - #/* start TV iterations */ - cdef int i = 0; - for i in range(iterations): - - #/* calculate differences */ - D1_func(&B[0,0,0], &D1[0,0,0], dims[0], dims[1], dims[2]); - D2_func(&B[0,0,0], &D2[0,0,0], dims[0], dims[1], dims[2]); - D3_func(&B[0,0,0], &D3[0,0,0], dims[0], dims[1], dims[2]); - - #/* calculate divergence and image update*/ - TV_main(&D1[0,0,0], &D2[0,0,0], &D3[0,0,0], &B[0,0,0], &A[0,0,0], - regularization_parameter, marching_step_parameter, - dims[0], dims[1], dims[2]) + + #/* Run ROF iterations for 3D data */ + TV_ROF(&A[0,0, 0], &B[0,0, 0], dims[0], dims[1], dims[2], iterations, marching_step_parameter, regularization_parameter) + return B -
\ No newline at end of file + diff --git a/Wrappers/Python/src/gpu_regularizers.pyx b/Wrappers/Python/src/gpu_regularizers.pyx index 84fc30a..649015e 100644 --- a/Wrappers/Python/src/gpu_regularizers.pyx +++ b/Wrappers/Python/src/gpu_regularizers.pyx @@ -25,6 +25,7 @@ cdef extern void NLM_GPU_kernel(float *A, float* B, float *Eucl_Vec, int N, int M, int Z, int dimension, int SearchW, int SimilW, int SearchW_real, float denh2, float lambdaf); +cdef extern void TV_ROF_GPU(float* A, float* B, int N, int M, int Z, int iter, float tau, float lambdaf); cdef extern float pad_crop(float *A, float *Ap, int OldSizeX, int OldSizeY, int OldSizeZ, int NewSizeX, int NewSizeY, int NewSizeZ, @@ -65,6 +66,22 @@ def NML(inputData, SimilW, h, lambdaf) + +def ROF_TV(inputData, + iterations, + time_marching_parameter, + regularization_parameter): + if inputData.ndim == 2: + return ROFTV2D(inputData, + iterations, + time_marching_parameter, + regularization_parameter) + elif inputData.ndim == 3: + return ROFTV3D(inputData, + iterations, + time_marching_parameter, + regularization_parameter) + def Diff4thHajiaboli2D(np.ndarray[np.float32_t, ndim=2, mode="c"] inputData, float edge_preserv_parameter, @@ -311,4 +328,49 @@ def NML3D(np.ndarray[np.float32_t, ndim=3, mode="c"] inputData, padXY, switchpad_crop) + return B + +def ROFTV2D(np.ndarray[np.float32_t, ndim=2, mode="c"] inputData, + int iterations, + float time_marching_parameter, + float regularization_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 = \ + np.zeros([dims[0],dims[1]], dtype='float32') + + # Running CUDA code here + TV_ROF_GPU( + &inputData[0,0], &B[0,0], + dims[0], dims[1], 0, + iterations , + time_marching_parameter, + regularization_parameter); + + return B + +def ROFTV3D(np.ndarray[np.float32_t, ndim=3, mode="c"] inputData, + int iterations, + float time_marching_parameter, + float regularization_parameter): + + 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 = \ + np.zeros([dims[0],dims[1],dims[2]], dtype='float32') + + # Running CUDA code here + TV_ROF_GPU( + &inputData[0,0,0], &B[0,0,0], + dims[0], dims[1], dims[2], + iterations , + time_marching_parameter, + regularization_parameter); + return B |