summaryrefslogtreecommitdiffstats
path: root/Wrappers/Python
diff options
context:
space:
mode:
Diffstat (limited to 'Wrappers/Python')
-rw-r--r--Wrappers/Python/demo/test_cpu_regularizers.py25
-rw-r--r--Wrappers/Python/src/cpu_regularizers.cpp1
-rw-r--r--Wrappers/Python/src/cpu_regularizers.pyx25
-rw-r--r--Wrappers/Python/src/gpu_regularizers.pyx2
-rw-r--r--Wrappers/Python/test/test_cpu_vs_gpu_regularizers.py9
5 files changed, 32 insertions, 30 deletions
diff --git a/Wrappers/Python/demo/test_cpu_regularizers.py b/Wrappers/Python/demo/test_cpu_regularizers.py
index b08c418..53b8538 100644
--- a/Wrappers/Python/demo/test_cpu_regularizers.py
+++ b/Wrappers/Python/demo/test_cpu_regularizers.py
@@ -11,10 +11,9 @@ import numpy as np
import os
from enum import Enum
import timeit
-from ccpi.filters.cpu_regularizers_boost import SplitBregman_TV , FGP_TV ,\
- LLT_model, PatchBased_Regul ,\
+from ccpi.filters.cpu_regularizers_boost import SplitBregman_TV, LLT_model, PatchBased_Regul ,\
TGV_PD
-from ccpi.filters.cpu_regularizers_cython import ROF_TV
+from ccpi.filters.cpu_regularizers_cython import TV_ROF_CPU, TV_FGP_CPU
###############################################################################
#https://stackoverflow.com/questions/13875989/comparing-image-in-url-to-image-in-filesystem-in-python/13884956#13884956
@@ -128,21 +127,25 @@ imgplot = plt.imshow(splitbregman,\
)
###################### FGP_TV #########################################
-# u = FGP_TV(single(u0), 0.05, 100, 1e-04);
+
start_time = timeit.default_timer()
-pars = {'algorithm' : FGP_TV , \
+pars = {'algorithm' : TV_FGP_CPU , \
'input' : u0,
'regularization_parameter':0.05, \
'number_of_iterations' :200 ,\
- 'tolerance_constant':1e-4,\
- 'TV_penalty': 0
+ 'tolerance_constant':1e-5,\
+ 'methodTV': 0 ,\
+ 'nonneg': 0 ,\
+ 'printingOut': 0
}
-out = FGP_TV (pars['input'],
+out = TV_FGP_CPU (pars['input'],
pars['regularization_parameter'],
pars['number_of_iterations'],
pars['tolerance_constant'],
- pars['TV_penalty'])
+ pars['methodTV'],
+ pars['nonneg'],
+ pars['printingOut'])
fgp = out[0]
rms = rmse(Im, fgp)
@@ -282,13 +285,13 @@ imgplot = plt.imshow(tgv, cmap="gray")
start_time = timeit.default_timer()
-pars = {'algorithm': ROF_TV , \
+pars = {'algorithm': TV_ROF_CPU , \
'input' : u0,\
'regularization_parameter':0.04,\
'marching_step': 0.0025,\
'number_of_iterations': 300
}
-rof = ROF_TV(pars['input'],
+rof = TV_ROF_CPU(pars['input'],
pars['number_of_iterations'],
pars['regularization_parameter'],
pars['marching_step']
diff --git a/Wrappers/Python/src/cpu_regularizers.cpp b/Wrappers/Python/src/cpu_regularizers.cpp
index 43d5d11..b8156d5 100644
--- a/Wrappers/Python/src/cpu_regularizers.cpp
+++ b/Wrappers/Python/src/cpu_regularizers.cpp
@@ -1040,7 +1040,6 @@ BOOST_PYTHON_MODULE(cpu_regularizers_boost)
np::dtype dt2 = np::dtype::get_builtin<uint16_t>();
def("SplitBregman_TV", SplitBregman_TV);
- def("FGP_TV", FGP_TV);
def("LLT_model", LLT_model);
def("PatchBased_Regul", PatchBased_Regul);
def("TGV_PD", TGV_PD);
diff --git a/Wrappers/Python/src/cpu_regularizers.pyx b/Wrappers/Python/src/cpu_regularizers.pyx
index b8089a8..448da31 100644
--- a/Wrappers/Python/src/cpu_regularizers.pyx
+++ b/Wrappers/Python/src/cpu_regularizers.pyx
@@ -18,8 +18,8 @@ import cython
import numpy as np
cimport numpy as np
-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);
+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);
# Can we use the same name here in "def" as the C function?
def TV_ROF_CPU(inputData, iterations, regularization_parameter,
@@ -45,11 +45,10 @@ def TV_ROF_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_CPU(&inputData[0,0], &B[0,0], dims[0], dims[1], 1, iterations,
+ TV_ROF_CPU_main(&inputData[0,0], &B[0,0], dims[0], dims[1], 1, iterations,
marching_step_parameter, regularization_parameter)
- return B
-
+ return B
def TV_ROF_3D(np.ndarray[np.float32_t, ndim=3, mode="c"] inputData,
int iterations,
@@ -65,7 +64,7 @@ def TV_ROF_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_FGP_CPU(&inputData[0,0,0], &B[0,0,0], dims[0], dims[1], dims[2], iterations,
+ TV_ROF_CPU_main(&inputData[0,0,0], &B[0,0,0], dims[0], dims[1], dims[2], iterations,
marching_step_parameter, regularization_parameter)
return B
@@ -88,11 +87,11 @@ def TV_FGP_2D(np.ndarray[np.float32_t, ndim=2, mode="c"] inputData,
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_FGP_CPU(&inputData[0,0], &B[0,0], regularization_parameter,
+ TV_FGP_CPU_main(&inputData[0,0], &outputData[0,0], regularization_parameter,
iterations,
tolerance_param,
methodTV,
@@ -100,8 +99,7 @@ def TV_FGP_2D(np.ndarray[np.float32_t, ndim=2, mode="c"] inputData,
printM,
dims[0], dims[1], 1)
- return B
-
+ return outputData
def TV_FGP_3D(np.ndarray[np.float32_t, ndim=3, mode="c"] inputData,
float regularization_parameter,
@@ -115,15 +113,16 @@ def TV_FGP_3D(np.ndarray[np.float32_t, ndim=3, mode="c"] inputData,
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_FGP_CPU(&inputData[0,0, 0], &B[0,0, 0], iterations,
+ TV_FGP_CPU_main(&inputData[0,0,0], &outputData[0,0, 0], regularization_parameter,
+ iterations,
tolerance_param,
methodTV,
nonneg,
printM,
dims[0], dims[1], dims[2])
- return B
+ return outputData
diff --git a/Wrappers/Python/src/gpu_regularizers.pyx b/Wrappers/Python/src/gpu_regularizers.pyx
index a14a20d..e99bfa7 100644
--- a/Wrappers/Python/src/gpu_regularizers.pyx
+++ b/Wrappers/Python/src/gpu_regularizers.pyx
@@ -26,7 +26,7 @@ cdef extern void NLM_GPU_kernel(float *A, float* B, float *Eucl_Vec,
int SearchW, int SimilW,
int SearchW_real, float denh2, float lambdaf);
cdef extern void TV_ROF_GPU(float* Input, float* Output, int N, int M, int Z, int iter, float tau, float lambdaf);
-cdef extern void TV_FGP_GPU(float *Input, float *Output, float lambda, int iter, float epsil, int methodTV, int nonneg, int printM, int N, int M, int Z);
+cdef extern void TV_FGP_GPU(float *Input, float *Output, float lambdaPar, int iter, float epsil, int methodTV, int nonneg, int printM, int N, int M, int Z);
cdef extern float pad_crop(float *A, float *Ap,
int OldSizeX, int OldSizeY, int OldSizeZ,
diff --git a/Wrappers/Python/test/test_cpu_vs_gpu_regularizers.py b/Wrappers/Python/test/test_cpu_vs_gpu_regularizers.py
index 6344021..e162afa 100644
--- a/Wrappers/Python/test/test_cpu_vs_gpu_regularizers.py
+++ b/Wrappers/Python/test/test_cpu_vs_gpu_regularizers.py
@@ -12,7 +12,7 @@ import matplotlib.pyplot as plt
import numpy as np
import os
import timeit
-from ccpi.filters.gpu_regularizers import Diff4thHajiaboli, NML, TV_ROF_GPU
+from ccpi.filters.gpu_regularizers import Diff4thHajiaboli, NML, GPU_ROF_TV
from ccpi.filters.cpu_regularizers_cython import TV_ROF_CPU
###############################################################################
def printParametersToString(pars):
@@ -56,11 +56,11 @@ imgplot = plt.imshow(u0,cmap="gray")
# set parameters
-pars = {'algorithm': ROF_TV , \
+pars = {'algorithm': TV_ROF_CPU , \
'input' : u0,\
'regularization_parameter':0.04,\
'time_marching_parameter': 0.0025,\
- 'number_of_iterations': 600
+ 'number_of_iterations': 1200
}
print ("#################ROF TV CPU#####################")
start_time = timeit.default_timer()
@@ -89,13 +89,14 @@ plt.title('{}'.format('CPU results'))
print ("#################ROF TV GPU#####################")
start_time = timeit.default_timer()
-rof_gpu = TV_ROF_GPU(pars['input'],
+rof_gpu = GPU_ROF_TV(pars['input'],
pars['number_of_iterations'],
pars['time_marching_parameter'],
pars['regularization_parameter'])
rms = rmse(Im, rof_gpu)
pars['rmse'] = rms
+pars['algorithm'] = GPU_ROF_TV
txtstr = printParametersToString(pars)
txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time)
print (txtstr)