summaryrefslogtreecommitdiffstats
path: root/Wrappers
diff options
context:
space:
mode:
authoralgol <dkazanc@hotmail.com>2018-04-12 11:56:54 +0100
committeralgol <dkazanc@hotmail.com>2018-04-12 11:56:54 +0100
commit22f6e22cbe6db04c6bbe8d259ce761e3748d7102 (patch)
tree225dcf0db9dc7e0f0fc5fc001a7efb14c19658f8 /Wrappers
parent58f5ce047b063d53906e38047b6ae744ccdbd4eb (diff)
downloadregularization-22f6e22cbe6db04c6bbe8d259ce761e3748d7102.tar.gz
regularization-22f6e22cbe6db04c6bbe8d259ce761e3748d7102.tar.bz2
regularization-22f6e22cbe6db04c6bbe8d259ce761e3748d7102.tar.xz
regularization-22f6e22cbe6db04c6bbe8d259ce761e3748d7102.zip
dTV some bugs in cython
Diffstat (limited to 'Wrappers')
-rw-r--r--Wrappers/Python/ccpi/filters/regularisers.py4
-rw-r--r--Wrappers/Python/conda-recipe/run_test.py.in (renamed from Wrappers/Python/conda-recipe/run_test.py)17
-rw-r--r--Wrappers/Python/conda-recipe/testLena.npybin0 -> 1048656 bytes
-rw-r--r--Wrappers/Python/demos/demo_cpu_regularisers.py9
-rw-r--r--Wrappers/Python/demos/demo_cpu_vs_gpu_regularisers.py2
-rw-r--r--Wrappers/Python/demos/demo_gpu_regularisers.py8
-rw-r--r--Wrappers/Python/src/cpu_regularisers.pyx2
-rw-r--r--Wrappers/Python/src/gpu_regularisers.pyx7
8 files changed, 27 insertions, 22 deletions
diff --git a/Wrappers/Python/ccpi/filters/regularisers.py b/Wrappers/Python/ccpi/filters/regularisers.py
index c6723fa..376cc9c 100644
--- a/Wrappers/Python/ccpi/filters/regularisers.py
+++ b/Wrappers/Python/ccpi/filters/regularisers.py
@@ -2,8 +2,8 @@
script which assigns a proper device core function based on a flag ('cpu' or 'gpu')
"""
-from ccpi.filters.cpu_regularisers_cython import TV_ROF_CPU, TV_FGP_CPU dTV_FGP_CPU
-from ccpi.filters.gpu_regularisers import TV_ROF_GPU, TV_FGP_GPU dTV_FGP_GPU
+from ccpi.filters.cpu_regularisers_cython import TV_ROF_CPU, TV_FGP_CPU, dTV_FGP_CPU
+from ccpi.filters.gpu_regularisers import TV_ROF_GPU, TV_FGP_GPU, dTV_FGP_GPU
def ROF_TV(inputData, regularisation_parameter, iterations,
time_marching_parameter,device='cpu'):
diff --git a/Wrappers/Python/conda-recipe/run_test.py b/Wrappers/Python/conda-recipe/run_test.py.in
index 04bbd40..9a6f4de 100644
--- a/Wrappers/Python/conda-recipe/run_test.py
+++ b/Wrappers/Python/conda-recipe/run_test.py.in
@@ -1,8 +1,6 @@
import unittest
import numpy as np
-import os
from ccpi.filters.regularisers import ROF_TV, FGP_TV
-import matplotlib.pyplot as plt
def rmse(im1, im2):
rmse = np.sqrt(np.sum((im1 - im2) ** 2) / float(im1.size))
@@ -14,13 +12,16 @@ class TestRegularisers(unittest.TestCase):
pass
def test_cpu_regularisers(self):
- filename = os.path.join(".." , ".." , ".." , "data" ,"lena_gray_512.tif")
+ #filename = os.path.join(".." , ".." , ".." , "data" ,"testLena.npy")
+ Im = np.load('testLena.npy');
+ """
# read noiseless image
Im = plt.imread(filename)
Im = np.asarray(Im, dtype='float32')
Im = Im/255
+ """
tolerance = 1e-05
rms_rof_exp = 0.006812507 #expected value for ROF model
rms_fgp_exp = 0.019152347 #expected value for FGP model
@@ -80,13 +81,11 @@ class TestRegularisers(unittest.TestCase):
"""
self.assertTrue(res)
def test_gpu_regularisers(self):
- filename = os.path.join(".." , ".." , ".." , "data" ,"lena_gray_512.tif")
+ #filename = os.path.join(".." , ".." , ".." , "data" ,"testLena.npy")
- # read noiseless image
- Im = plt.imread(filename)
- Im = np.asarray(Im, dtype='float32')
+ Im = np.load('testLena.npy');
- Im = Im/255
+ #Im = Im/255
tolerance = 1e-05
rms_rof_exp = 0.006812507 #expected value for ROF model
rms_fgp_exp = 0.019152347 #expected value for FGP model
@@ -146,4 +145,4 @@ class TestRegularisers(unittest.TestCase):
"""
self.assertTrue(res)
if __name__ == '__main__':
- unittest.main() \ No newline at end of file
+ unittest.main()
diff --git a/Wrappers/Python/conda-recipe/testLena.npy b/Wrappers/Python/conda-recipe/testLena.npy
new file mode 100644
index 0000000..14bc0e3
--- /dev/null
+++ b/Wrappers/Python/conda-recipe/testLena.npy
Binary files differ
diff --git a/Wrappers/Python/demos/demo_cpu_regularisers.py b/Wrappers/Python/demos/demo_cpu_regularisers.py
index fd3050c..00beb0b 100644
--- a/Wrappers/Python/demos/demo_cpu_regularisers.py
+++ b/Wrappers/Python/demos/demo_cpu_regularisers.py
@@ -22,6 +22,8 @@ def printParametersToString(pars):
txt += "{0} = {1}".format(key, value.__name__)
elif key == 'input':
txt += "{0} = {1}".format(key, np.shape(value))
+ elif key == 'refdata':
+ txt += "{0} = {1}".format(key, np.shape(value))
else:
txt += "{0} = {1}".format(key, value)
txt += '\n'
@@ -196,7 +198,7 @@ plt.title('{}'.format('CPU results'))
# Uncomment to test 3D regularisation performance
#%%
-
+"""
N = 512
slices = 20
@@ -318,8 +320,8 @@ a.set_title('Noisy Image')
imgplot = plt.imshow(noisyVol[10,:,:],cmap="gray")
# set parameters
-pars = {'algorithm' : FGP_dTV, \
- 'input' : noisyVol,\
+pars = {'algorithm' : FGP_dTV,\
+ 'input' : noisyVol,\
'refdata' : noisyRef,\
'regularisation_parameter':0.04, \
'number_of_iterations' :300 ,\
@@ -358,4 +360,5 @@ a.text(0.15, 0.25, txtstr, transform=a.transAxes, fontsize=14,
verticalalignment='top', bbox=props)
imgplot = plt.imshow(fgp_dTV_cpu3D[10,:,:], cmap="gray")
plt.title('{}'.format('Recovered volume on the CPU using FGP-dTV'))
+"""
#%%
diff --git a/Wrappers/Python/demos/demo_cpu_vs_gpu_regularisers.py b/Wrappers/Python/demos/demo_cpu_vs_gpu_regularisers.py
index aa1f865..310cf75 100644
--- a/Wrappers/Python/demos/demo_cpu_vs_gpu_regularisers.py
+++ b/Wrappers/Python/demos/demo_cpu_vs_gpu_regularisers.py
@@ -22,6 +22,8 @@ def printParametersToString(pars):
txt += "{0} = {1}".format(key, value.__name__)
elif key == 'input':
txt += "{0} = {1}".format(key, np.shape(value))
+ elif key == 'refdata':
+ txt += "{0} = {1}".format(key, np.shape(value))
else:
txt += "{0} = {1}".format(key, value)
txt += '\n'
diff --git a/Wrappers/Python/demos/demo_gpu_regularisers.py b/Wrappers/Python/demos/demo_gpu_regularisers.py
index 4759cc3..24a3c88 100644
--- a/Wrappers/Python/demos/demo_gpu_regularisers.py
+++ b/Wrappers/Python/demos/demo_gpu_regularisers.py
@@ -22,6 +22,8 @@ def printParametersToString(pars):
txt += "{0} = {1}".format(key, value.__name__)
elif key == 'input':
txt += "{0} = {1}".format(key, np.shape(value))
+ elif key == 'refdata':
+ txt += "{0} = {1}".format(key, np.shape(value))
else:
txt += "{0} = {1}".format(key, value)
txt += '\n'
@@ -192,7 +194,7 @@ plt.title('{}'.format('GPU results'))
# Uncomment to test 3D regularisation performance
#%%
-
+"""
N = 512
slices = 20
@@ -314,7 +316,7 @@ imgplot = plt.imshow(noisyVol[10,:,:],cmap="gray")
# set parameters
pars = {'algorithm' : FGP_dTV, \
- 'input' : noisyVol,\
+ 'input' : noisyVol,\
'refdata' : noisyRef,\
'regularisation_parameter':0.04, \
'number_of_iterations' :300 ,\
@@ -352,5 +354,5 @@ a.text(0.15, 0.25, txtstr, transform=a.transAxes, fontsize=14,
verticalalignment='top', bbox=props)
imgplot = plt.imshow(fgp_dTV_gpu3D[10,:,:], cmap="gray")
plt.title('{}'.format('Recovered volume on the GPU using FGP-dTV'))
-
+"""
#%%
diff --git a/Wrappers/Python/src/cpu_regularisers.pyx b/Wrappers/Python/src/cpu_regularisers.pyx
index 8f9185a..1661375 100644
--- a/Wrappers/Python/src/cpu_regularisers.pyx
+++ b/Wrappers/Python/src/cpu_regularisers.pyx
@@ -156,8 +156,8 @@ def dTV_FGP_2D(np.ndarray[np.float32_t, ndim=2, mode="c"] inputData,
dTV_FGP_CPU_main(&inputData[0,0], &refdata[0,0], &outputData[0,0], regularisation_parameter,
iterationsNumb,
tolerance_param,
- methodTV,
eta_const,
+ methodTV,
nonneg,
printM,
dims[0], dims[1], 1)
diff --git a/Wrappers/Python/src/gpu_regularisers.pyx b/Wrappers/Python/src/gpu_regularisers.pyx
index 4a14f69..18efdcd 100644
--- a/Wrappers/Python/src/gpu_regularisers.pyx
+++ b/Wrappers/Python/src/gpu_regularisers.pyx
@@ -20,7 +20,7 @@ cimport numpy as np
cdef extern void TV_ROF_GPU_main(float* Input, float* Output, float lambdaPar, int iter, float tau, int N, int M, int Z);
cdef extern void TV_FGP_GPU_main(float *Input, float *Output, float lambdaPar, int iter, float epsil, int methodTV, int nonneg, int printM, int N, int M, int Z);
-cdef extern void dTV_FGP_CPU_main(float *Input, float *InputRef, float *Output, float lambdaPar, int iterationsNumb, float epsil, float eta, int methodTV, int nonneg, int printM, int N, int M, int Z);
+cdef extern void dTV_FGP_GPU_main(float *Input, float *InputRef, float *Output, float lambdaPar, int iterationsNumb, float epsil, float eta, int methodTV, int nonneg, int printM, int N, int M, int Z);
# Total-variation Rudin-Osher-Fatemi (ROF)
def TV_ROF_GPU(inputData,
@@ -187,8 +187,7 @@ def FGPTV3D(np.ndarray[np.float32_t, ndim=3, mode="c"] inputData,
np.zeros([dims[0],dims[1],dims[2]], dtype='float32')
# Running CUDA code here
- TV_FGP_GPU_main(
- &inputData[0,0,0], &outputData[0,0,0],
+ TV_FGP_GPU_main(&inputData[0,0,0], &outputData[0,0,0],
regularisation_parameter ,
iterations,
tolerance_param,
@@ -204,7 +203,7 @@ def FGPTV3D(np.ndarray[np.float32_t, ndim=3, mode="c"] inputData,
#****************************************************************#
#******** Directional TV Fast-Gradient-Projection (FGP)*********#
def FGPdTV2D(np.ndarray[np.float32_t, ndim=2, mode="c"] inputData,
- np.ndarray[np.float32_t, ndim=3, mode="c"] refdata,
+ np.ndarray[np.float32_t, ndim=2, mode="c"] refdata,
float regularisation_parameter,
int iterations,
float tolerance_param,