diff options
author | algol <dkazanc@hotmail.com> | 2018-03-06 11:45:53 +0000 |
---|---|---|
committer | algol <dkazanc@hotmail.com> | 2018-03-06 11:45:53 +0000 |
commit | 8d310478254f3cda63f3663729b416f425ad70b6 (patch) | |
tree | 63d5132feec37d5b99ca8f6879363d9dd88520a9 | |
parent | ccf9b61bba1004af783c6333d58ea9611c0f81f2 (diff) | |
download | regularization-8d310478254f3cda63f3663729b416f425ad70b6.tar.gz regularization-8d310478254f3cda63f3663729b416f425ad70b6.tar.bz2 regularization-8d310478254f3cda63f3663729b416f425ad70b6.tar.xz regularization-8d310478254f3cda63f3663729b416f425ad70b6.zip |
work on FGP intergration
-rw-r--r-- | Core/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Core/regularizers_CPU/ROF_TV_core.c | 22 | ||||
-rw-r--r-- | Core/regularizers_CPU/utils.c | 8 | ||||
-rw-r--r-- | Wrappers/Python/demo/test_cpu_regularizers.py | 17 | ||||
-rw-r--r-- | Wrappers/Python/src/cpu_regularizers.pyx | 14 |
5 files changed, 30 insertions, 33 deletions
diff --git a/Core/CMakeLists.txt b/Core/CMakeLists.txt index 68b7111..4e85002 100644 --- a/Core/CMakeLists.txt +++ b/Core/CMakeLists.txt @@ -88,7 +88,7 @@ add_library(cilreg SHARED ${CMAKE_CURRENT_SOURCE_DIR}/regularizers_CPU/PatchBased_Regul_core.c ${CMAKE_CURRENT_SOURCE_DIR}/regularizers_CPU/SplitBregman_TV_core.c ${CMAKE_CURRENT_SOURCE_DIR}/regularizers_CPU/TGV_PD_core.c - ${CMAKE_CURRENT_SOURCE_DIR}/regularizers_CPU/ROF_TV_core.c + ${CMAKE_CURRENT_SOURCE_DIR}/regularizers_CPU/ROF_TV_core.c ${CMAKE_CURRENT_SOURCE_DIR}/regularizers_CPU/utils.c ) target_link_libraries(cilreg ${EXTRA_LIBRARIES} ) diff --git a/Core/regularizers_CPU/ROF_TV_core.c b/Core/regularizers_CPU/ROF_TV_core.c index a59a3c6..a4f82a6 100644 --- a/Core/regularizers_CPU/ROF_TV_core.c +++ b/Core/regularizers_CPU/ROF_TV_core.c @@ -46,7 +46,7 @@ int sign(float x) { */ /* Running iterations of TV-ROF function */ -float TV_ROF_CPU_mainfloat TV_ROF_CPU_main(float *Input, float *Output, float lambdaPar, int iterationsNumb, float tau, int dimX, int dimY, int dimZ) +float TV_ROF_CPU_main(float *Input, float *Output, float lambdaPar, int iterationsNumb, float tau, int dimX, int dimY, int dimZ) { float *D1, *D2, *D3; int i, DimTotal; @@ -132,9 +132,9 @@ float D1_func(float *A, float *D1, int dimX, int dimY, int dimZ) NOMy_0 = A[index] - A[(j)*dimX + i2]; /* y- */ denom1 = NOMx_1*NOMx_1; - denom2 = 0.5*(sign(NOMy_1) + sign(NOMy_0))*(MIN(fabs(NOMy_1),fabs(NOMy_0))); + denom2 = 0.5f*(sign(NOMy_1) + sign(NOMy_0))*(MIN(fabs(NOMy_1),fabs(NOMy_0))); denom2 = denom2*denom2; - T1 = sqrt(denom1 + denom2 + EPS); + T1 = sqrtf(denom1 + denom2 + EPS); D1[index] = NOMx_1/T1; }} } @@ -170,11 +170,11 @@ float D2_func(float *A, float *D2, int dimX, int dimY, int dimZ) denom1 = NOMy_1*NOMy_1; - denom2 = 0.5*(sign(NOMx_1) + sign(NOMx_0))*(MIN(fabs(NOMx_1),fabs(NOMx_0))); + denom2 = 0.5f*(sign(NOMx_1) + sign(NOMx_0))*(MIN(fabs(NOMx_1),fabs(NOMx_0))); denom2 = denom2*denom2; - denom3 = 0.5*(sign(NOMz_1) + sign(NOMz_0))*(MIN(fabs(NOMz_1),fabs(NOMz_0))); + denom3 = 0.5f*(sign(NOMz_1) + sign(NOMz_0))*(MIN(fabs(NOMz_1),fabs(NOMz_0))); denom3 = denom3*denom3; - T2 = sqrt(denom1 + denom2 + denom3 + EPS); + T2 = sqrtf(denom1 + denom2 + denom3 + EPS); D2[index] = NOMy_1/T2; }}} } @@ -196,9 +196,9 @@ float D2_func(float *A, float *D2, int dimX, int dimY, int dimZ) /*NOMy_0 = A[(i)*dimY + j] - A[(i)*dimY + j2]; */ /* y- */ denom1 = NOMy_1*NOMy_1; - denom2 = 0.5*(sign(NOMx_1) + sign(NOMx_0))*(MIN(fabs(NOMx_1),fabs(NOMx_0))); + denom2 = 0.5f*(sign(NOMx_1) + sign(NOMx_0))*(MIN(fabs(NOMx_1),fabs(NOMx_0))); denom2 = denom2*denom2; - T2 = sqrt(denom1 + denom2 + EPS); + T2 = sqrtf(denom1 + denom2 + EPS); D2[index] = NOMy_1/T2; }} } @@ -233,11 +233,11 @@ float D3_func(float *A, float *D3, int dimY, int dimX, int dimZ) /*NOMz_0 = A[(dimX*dimY)*k + (i)*dimY + j] - A[(dimX*dimY)*k2 + (i)*dimY + j]; */ /* z- */ denom1 = NOMz_1*NOMz_1; - denom2 = 0.5*(sign(NOMx_1) + sign(NOMx_0))*(MIN(fabs(NOMx_1),fabs(NOMx_0))); + denom2 = 0.5f*(sign(NOMx_1) + sign(NOMx_0))*(MIN(fabs(NOMx_1),fabs(NOMx_0))); denom2 = denom2*denom2; - denom3 = 0.5*(sign(NOMy_1) + sign(NOMy_0))*(MIN(fabs(NOMy_1),fabs(NOMy_0))); + denom3 = 0.5f*(sign(NOMy_1) + sign(NOMy_0))*(MIN(fabs(NOMy_1),fabs(NOMy_0))); denom3 = denom3*denom3; - T3 = sqrt(denom1 + denom2 + denom3 + EPS); + T3 = sqrtf(denom1 + denom2 + denom3 + EPS); D3[index] = NOMz_1/T3; }}} return *D3; diff --git a/Core/regularizers_CPU/utils.c b/Core/regularizers_CPU/utils.c index 951fb91..cdf3d0e 100644 --- a/Core/regularizers_CPU/utils.c +++ b/Core/regularizers_CPU/utils.c @@ -45,10 +45,10 @@ float TV_energy2D(float *U, float *U0, float *E_val, float lambda, int dimX, int j1 = j + 1; if (j == dimY-1) j1 = j; /* Forward differences */ - NOMx_2 = pow(U[j1*dimX + i] - U[index],2); /* x+ */ - NOMy_2 = pow(U[j*dimX + i1] - U[index],2); /* y+ */ - E_Grad += sqrt(NOMx_2 + NOMy_2); /* gradient term energy */ - E_Data += 0.5f * lambda*(pow((U[index]-U0[index]),2)); /* fidelity term energy */ + NOMx_2 = powf(U[j1*dimX + i] - U[index],2); /* x+ */ + NOMy_2 = powf(U[j*dimX + i1] - U[index],2); /* y+ */ + E_Grad += sqrtf(NOMx_2 + NOMy_2); /* gradient term energy */ + E_Data += 0.5f * lambda*(powf((U[index]-U0[index]),2)); /* fidelity term energy */ } } E_val[0] = E_Grad + E_Data; diff --git a/Wrappers/Python/demo/test_cpu_regularizers.py b/Wrappers/Python/demo/test_cpu_regularizers.py index 53b8538..f1eb3c3 100644 --- a/Wrappers/Python/demo/test_cpu_regularizers.py +++ b/Wrappers/Python/demo/test_cpu_regularizers.py @@ -131,9 +131,9 @@ imgplot = plt.imshow(splitbregman,\ start_time = timeit.default_timer() pars = {'algorithm' : TV_FGP_CPU , \ 'input' : u0, - 'regularization_parameter':0.05, \ - 'number_of_iterations' :200 ,\ - 'tolerance_constant':1e-5,\ + 'regularization_parameter':0.07, \ + 'number_of_iterations' :300 ,\ + 'tolerance_constant':0.00001,\ 'methodTV': 0 ,\ 'nonneg': 0 ,\ 'printingOut': 0 @@ -156,7 +156,7 @@ txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time) print (txtstr) -a=fig.add_subplot(2,4,3) +a=fig.add_subplot(2,4,4) # these are matplotlib.patch.Patch properties props = dict(boxstyle='round', facecolor='wheat', alpha=0.5) @@ -168,8 +168,9 @@ imgplot = plt.imshow(fgp, \ a.text(0.05, 0.95, txtstr, transform=a.transAxes, fontsize=14, verticalalignment='top', bbox=props) -###################### LLT_model ######################################### +###################### LLT_model ######################################### +""" start_time = timeit.default_timer() pars = {'algorithm': LLT_model , \ @@ -204,7 +205,7 @@ a.text(0.05, 0.95, txtstr, transform=a.transAxes, fontsize=14, imgplot = plt.imshow(llt,\ cmap="gray" ) - +""" # ###################### PatchBased_Regul ######################################### # # Quick 2D denoising example in Matlab: @@ -292,8 +293,8 @@ pars = {'algorithm': TV_ROF_CPU , \ 'number_of_iterations': 300 } rof = TV_ROF_CPU(pars['input'], - pars['number_of_iterations'], - pars['regularization_parameter'], + pars['regularization_parameter'], + pars['number_of_iterations'], pars['marching_step'] ) #tgv = out diff --git a/Wrappers/Python/src/cpu_regularizers.pyx b/Wrappers/Python/src/cpu_regularizers.pyx index 2654831..d62ca59 100644 --- a/Wrappers/Python/src/cpu_regularizers.pyx +++ b/Wrappers/Python/src/cpu_regularizers.pyx @@ -21,14 +21,11 @@ cimport numpy as np 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); -def TV_ROF_CPU(inputData, regularization_parameter, iterationsNumb - marching_step_parameter): +def TV_ROF_CPU(inputData, regularization_parameter, iterationsNumb, marching_step_parameter): if inputData.ndim == 2: - return TV_ROF_2D(inputData, regularization_parameter, iterationsNumb - marching_step_parameter) + return TV_ROF_2D(inputData, regularization_parameter, iterationsNumb, marching_step_parameter) elif inputData.ndim == 3: - return TV_ROF_3D(inputData, regularization_parameter, iterationsNumb - marching_step_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, float regularization_parameter, @@ -47,10 +44,9 @@ def TV_ROF_2D(np.ndarray[np.float32_t, ndim=2, mode="c"] inputData, return outputData def TV_ROF_3D(np.ndarray[np.float32_t, ndim=3, mode="c"] inputData, - int iterations, + int iterationsNumb, float regularization_parameter, - float marching_step_parameter - ): + float marching_step_parameter): cdef long dims[3] dims[0] = inputData.shape[0] dims[1] = inputData.shape[1] |