summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordkazanc <dkazanc@hotmail.com>2019-11-27 18:38:59 +0000
committerdkazanc <dkazanc@hotmail.com>2019-11-27 18:38:59 +0000
commitcdef6a981f1772ed04fe44bbe2b8251983a4ba7a (patch)
tree8a839450703c9b2c3284cea7c5298e86fa91267f
parentccd5ef48846c613d29c6f3a33d99aa69d636a47c (diff)
downloadregularization-cdef6a981f1772ed04fe44bbe2b8251983a4ba7a.tar.gz
regularization-cdef6a981f1772ed04fe44bbe2b8251983a4ba7a.tar.bz2
regularization-cdef6a981f1772ed04fe44bbe2b8251983a4ba7a.tar.xz
regularization-cdef6a981f1772ed04fe44bbe2b8251983a4ba7a.zip
modifications in pdtv
-rw-r--r--demos/demo_cpu_regularisers.py6
-rw-r--r--src/Core/regularisers_CPU/PD_TV_core.c6
-rw-r--r--src/Core/regularisers_CPU/PD_TV_core.h2
-rw-r--r--src/Python/ccpi/filters/regularisers.py8
-rw-r--r--src/Python/src/cpu_regularisers.pyx18
5 files changed, 24 insertions, 16 deletions
diff --git a/demos/demo_cpu_regularisers.py b/demos/demo_cpu_regularisers.py
index 9888743..09781d5 100644
--- a/demos/demo_cpu_regularisers.py
+++ b/demos/demo_cpu_regularisers.py
@@ -179,7 +179,8 @@ pars = {'algorithm' : PD_TV, \
'tolerance_constant':1e-06,\
'methodTV': 0 ,\
'nonneg': 1,
- 'lipschitz_const' : 6}
+ 'lipschitz_const' : 8,
+ 'tau' : 0.0025}
print ("#############PD TV CPU####################")
start_time = timeit.default_timer()
@@ -189,7 +190,8 @@ start_time = timeit.default_timer()
pars['tolerance_constant'],
pars['methodTV'],
pars['nonneg'],
- pars['lipschitz_const'], 'cpu')
+ pars['lipschitz_const'],
+ pars['tau'],'cpu')
Qtools = QualityTools(Im, pd_cpu)
pars['rmse'] = Qtools.rmse()
diff --git a/src/Core/regularisers_CPU/PD_TV_core.c b/src/Core/regularisers_CPU/PD_TV_core.c
index cdce71b..65b8711 100644
--- a/src/Core/regularisers_CPU/PD_TV_core.c
+++ b/src/Core/regularisers_CPU/PD_TV_core.c
@@ -29,6 +29,7 @@
* 5. lipschitz_const: convergence related parameter
* 6. TV-type: methodTV - 'iso' (0) or 'l1' (1)
* 7. nonneg: 'nonnegativity (0 is OFF by default, 1 is ON)
+ * 8. tau: time marching parameter
* Output:
* [1] TV - Filtered/regularized image/volume
@@ -37,17 +38,16 @@
* [1] Antonin Chambolle, Thomas Pock. "A First-Order Primal-Dual Algorithm for Convex Problems with Applications to Imaging", 2010
*/
-float PDTV_CPU_main(float *Input, float *U, float *infovector, float lambdaPar, int iterationsNumb, float epsil, float lipschitz_const, int methodTV, int nonneg, int dimX, int dimY, int dimZ)
+float PDTV_CPU_main(float *Input, float *U, float *infovector, float lambdaPar, int iterationsNumb, float epsil, float lipschitz_const, int methodTV, int nonneg, float tau, int dimX, int dimY, int dimZ)
{
int ll;
long j, DimTotal;
- float re, re1, tau, sigma, theta, lt;
+ float re, re1, sigma, theta, lt;
re = 0.0f; re1 = 0.0f;
int count = 0;
//tau = 1.0/powf(lipschitz_const,0.5);
//sigma = 1.0/powf(lipschitz_const,0.5);
- tau = 0.02;
sigma = 1.0/(lipschitz_const*tau);
theta = 1.0f;
lt = tau/lambdaPar;
diff --git a/src/Core/regularisers_CPU/PD_TV_core.h b/src/Core/regularisers_CPU/PD_TV_core.h
index b4e8a75..97edc05 100644
--- a/src/Core/regularisers_CPU/PD_TV_core.h
+++ b/src/Core/regularisers_CPU/PD_TV_core.h
@@ -47,7 +47,7 @@ limitations under the License.
#ifdef __cplusplus
extern "C" {
#endif
-CCPI_EXPORT float PDTV_CPU_main(float *Input, float *U, float *infovector, float lambdaPar, int iterationsNumb, float epsil, float lipschitz_const, int methodTV, int nonneg, int dimX, int dimY, int dimZ);
+float PDTV_CPU_main(float *Input, float *U, float *infovector, float lambdaPar, int iterationsNumb, float epsil, float lipschitz_const, int methodTV, int nonneg, float tau, int dimX, int dimY, int dimZ);
CCPI_EXPORT float DualP2D(float *U, float *P1, float *P2, long dimX, long dimY, float sigma);
CCPI_EXPORT float DivProj2D(float *U, float *Input, float *P1, float *P2, long dimX, long dimY, float lt, float tau);
diff --git a/src/Python/ccpi/filters/regularisers.py b/src/Python/ccpi/filters/regularisers.py
index d65c0b9..bc745fe 100644
--- a/src/Python/ccpi/filters/regularisers.py
+++ b/src/Python/ccpi/filters/regularisers.py
@@ -53,7 +53,7 @@ def FGP_TV(inputData, regularisation_parameter,iterations,
.format(device))
def PD_TV(inputData, regularisation_parameter, iterations,
- tolerance_param, methodTV, nonneg, lipschitz_const, device='cpu'):
+ tolerance_param, methodTV, nonneg, lipschitz_const, tau, device='cpu'):
if device == 'cpu':
return TV_PD_CPU(inputData,
regularisation_parameter,
@@ -61,7 +61,8 @@ def PD_TV(inputData, regularisation_parameter, iterations,
tolerance_param,
methodTV,
nonneg,
- lipschitz_const)
+ lipschitz_const,
+ tau)
elif device == 'gpu' and gpu_enabled:
return TV_PD_CPU(inputData,
regularisation_parameter,
@@ -69,7 +70,8 @@ def PD_TV(inputData, regularisation_parameter, iterations,
tolerance_param,
methodTV,
nonneg,
- lipschitz_const)
+ lipschitz_const,
+ tau)
else:
if not gpu_enabled and device == 'gpu':
raise ValueError ('GPU is not available')
diff --git a/src/Python/src/cpu_regularisers.pyx b/src/Python/src/cpu_regularisers.pyx
index 08e247c..8de6aea 100644
--- a/src/Python/src/cpu_regularisers.pyx
+++ b/src/Python/src/cpu_regularisers.pyx
@@ -20,7 +20,7 @@ cimport numpy as np
cdef extern float TV_ROF_CPU_main(float *Input, float *Output, float *infovector, float *lambdaPar, int lambda_is_arr, int iterationsNumb, float tau, float epsil, int dimX, int dimY, int dimZ);
cdef extern float TV_FGP_CPU_main(float *Input, float *Output, float *infovector, float lambdaPar, int iterationsNumb, float epsil, int methodTV, int nonneg, int dimX, int dimY, int dimZ);
-cdef extern float PDTV_CPU_main(float *Input, float *U, float *infovector, float lambdaPar, int iterationsNumb, float epsil, float lipschitz_const, int methodTV, int nonneg, int dimX, int dimY, int dimZ);
+cdef extern float PDTV_CPU_main(float *Input, float *U, float *infovector, float lambdaPar, int iterationsNumb, float epsil, float lipschitz_const, int methodTV, int nonneg, float tau, int dimX, int dimY, int dimZ);
cdef extern float SB_TV_CPU_main(float *Input, float *Output, float *infovector, float mu, int iter, float epsil, int methodTV, int dimX, int dimY, int dimZ);
cdef extern float LLT_ROF_CPU_main(float *Input, float *Output, float *infovector, float lambdaROF, float lambdaLLT, int iterationsNumb, float tau, float epsil, int dimX, int dimY, int dimZ);
cdef extern float TGV_main(float *Input, float *Output, float *infovector, float lambdaPar, float alpha1, float alpha0, int iterationsNumb, float L2, float epsil, int dimX, int dimY, int dimZ);
@@ -159,11 +159,11 @@ def TV_FGP_3D(np.ndarray[np.float32_t, ndim=3, mode="c"] inputData,
#****************************************************************#
#****************** Total-variation Primal-dual *****************#
#****************************************************************#
-def TV_PD_CPU(inputData, regularisation_parameter, iterationsNumb, tolerance_param, methodTV, nonneg, lipschitz_const):
+def TV_PD_CPU(inputData, regularisation_parameter, iterationsNumb, tolerance_param, methodTV, nonneg, lipschitz_const, tau):
if inputData.ndim == 2:
- return TV_PD_2D(inputData, regularisation_parameter, iterationsNumb, tolerance_param, methodTV, nonneg, lipschitz_const)
+ return TV_PD_2D(inputData, regularisation_parameter, iterationsNumb, tolerance_param, methodTV, nonneg, lipschitz_const, tau)
elif inputData.ndim == 3:
- return TV_PD_3D(inputData, regularisation_parameter, iterationsNumb, tolerance_param, methodTV, nonneg, lipschitz_const)
+ return TV_PD_3D(inputData, regularisation_parameter, iterationsNumb, tolerance_param, methodTV, nonneg, lipschitz_const, tau)
def TV_PD_2D(np.ndarray[np.float32_t, ndim=2, mode="c"] inputData,
float regularisation_parameter,
@@ -171,7 +171,8 @@ def TV_PD_2D(np.ndarray[np.float32_t, ndim=2, mode="c"] inputData,
float tolerance_param,
int methodTV,
int nonneg,
- float lipschitz_const):
+ float lipschitz_const,
+ float tau):
cdef long dims[2]
dims[0] = inputData.shape[0]
@@ -190,6 +191,7 @@ def TV_PD_2D(np.ndarray[np.float32_t, ndim=2, mode="c"] inputData,
lipschitz_const,
methodTV,
nonneg,
+ tau,
dims[1],dims[0], 1)
return (outputData,infovec)
@@ -198,8 +200,9 @@ def TV_PD_3D(np.ndarray[np.float32_t, ndim=3, mode="c"] inputData,
int iterationsNumb,
float tolerance_param,
int methodTV,
- int nonneg,
- float lipschitz_const):
+ int nonneg,
+ float lipschitz_const,
+ float tau):
cdef long dims[3]
dims[0] = inputData.shape[0]
@@ -218,6 +221,7 @@ def TV_PD_3D(np.ndarray[np.float32_t, ndim=3, mode="c"] inputData,
lipschitz_const,
methodTV,
nonneg,
+ tau,
dims[2], dims[1], dims[0])
return (outputData,infovec)