summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Readme.md2
-rwxr-xr-xbuild/build-install.sh4
-rw-r--r--demos/data/SinoInpaint.mat (renamed from docs/data/SinoInpaint.mat)bin3335061 -> 3335061 bytes
-rw-r--r--demos/data/lena_gray_512.tif (renamed from docs/data/lena_gray_512.tif)bin262598 -> 262598 bytes
-rw-r--r--demos/demoMatlab_3Ddenoise.m (renamed from docs/demos/demoMatlab_3Ddenoise.m)6
-rw-r--r--demos/demoMatlab_denoise.m (renamed from docs/demos/demoMatlab_denoise.m)6
-rw-r--r--demos/demoMatlab_inpaint.m (renamed from docs/demos/demoMatlab_inpaint.m)4
-rw-r--r--demos/demo_cpu_inpainters.py (renamed from docs/demos/demo_cpu_inpainters.py)2
-rw-r--r--demos/demo_cpu_regularisers.py (renamed from docs/demos/demo_cpu_regularisers.py)2
-rw-r--r--demos/demo_cpu_regularisers3D.py (renamed from docs/demos/demo_cpu_regularisers3D.py)2
-rw-r--r--demos/demo_cpu_vs_gpu_regularisers.py (renamed from docs/demos/demo_cpu_vs_gpu_regularisers.py)2
-rw-r--r--demos/demo_gpu_regularisers.py (renamed from docs/demos/demo_gpu_regularisers.py)2
-rw-r--r--demos/demo_gpu_regularisers3D.py (renamed from docs/demos/demo_gpu_regularisers3D.py)4
-rw-r--r--demos/images/TV_vs_NLTV.jpg (renamed from docs/images/TV_vs_NLTV.jpg)bin111273 -> 111273 bytes
-rw-r--r--demos/images/probl.pdf (renamed from docs/images/probl.pdf)bin62326 -> 62326 bytes
-rw-r--r--demos/images/probl.png (renamed from docs/images/probl.png)bin38161 -> 38161 bytes
-rw-r--r--demos/images/reg_penalties.jpg (renamed from docs/images/reg_penalties.jpg)bin237455 -> 237455 bytes
-rw-r--r--demos/qualitymetrics.py (renamed from docs/demos/qualitymetrics.py)0
-rw-r--r--docs/installation.txt11
-rw-r--r--test/test_CPU_regularisers.py91
-rw-r--r--test/test_FGP_TV.py152
-rw-r--r--test/test_ROF_TV.py3
22 files changed, 263 insertions, 30 deletions
diff --git a/Readme.md b/Readme.md
index fe8fce8..112d606 100644
--- a/Readme.md
+++ b/Readme.md
@@ -65,7 +65,7 @@ cd CCPi-Regularisation-Toolkit
export CCPI_BUILD_ARGS="--numpy 1.12 --python 3.6"
build/jenkins-build.sh
```
-this will install `conda build` environment and compiles C/C++ and Python wrappers and performs basic tests.
+this will install `conda build` environment and compiles C/C++ and Python wrappers and performs basic tests for environment with python 3.6 and numpy 1.12.
### CMake
If you want to build directly using cmake, install CMake (v.>=3) to configure it. Additionally you will need a C compiler, `make` (on linux) and CUDA SDK where available. The toolkit may be used directly from C/C++ as it is compiled as a shared library (check-out the include files in `Core` for this)
diff --git a/build/build-install.sh b/build/build-install.sh
new file mode 100755
index 0000000..def66a4
--- /dev/null
+++ b/build/build-install.sh
@@ -0,0 +1,4 @@
+#!/usr/bin/env bash
+export CCPI_BUILD_ARGS="--numpy 1.12 --python 3.6"
+bash <(curl -L https://raw.githubusercontent.com/vais-ral/CCPi-VirtualMachine/master/scripts/jenkins-build.sh)
+conda install -y ccpi-regulariser --use-local --force \ No newline at end of file
diff --git a/docs/data/SinoInpaint.mat b/demos/data/SinoInpaint.mat
index d748fb4..d748fb4 100644
--- a/docs/data/SinoInpaint.mat
+++ b/demos/data/SinoInpaint.mat
Binary files differ
diff --git a/docs/data/lena_gray_512.tif b/demos/data/lena_gray_512.tif
index f80cafc..f80cafc 100644
--- a/docs/data/lena_gray_512.tif
+++ b/demos/data/lena_gray_512.tif
Binary files differ
diff --git a/docs/demos/demoMatlab_3Ddenoise.m b/demos/demoMatlab_3Ddenoise.m
index 0c331a4..cdd3117 100644
--- a/docs/demos/demoMatlab_3Ddenoise.m
+++ b/demos/demoMatlab_3Ddenoise.m
@@ -1,8 +1,8 @@
% Volume (3D) denoising demo using CCPi-RGL
clear; close all
-Path1 = sprintf(['..' filesep 'mex_compile' filesep 'installed'], 1i);
-Path2 = sprintf(['..' filesep '..' filesep '..' filesep 'data' filesep], 1i);
-Path3 = sprintf(['..' filesep 'supp'], 1i);
+Path1 = sprintf(['..' filesep 'src' filesep 'Matlab' filesep 'mex_compile' filesep 'installed'], 1i);
+Path2 = sprintf(['data' filesep], 1i);
+Path3 = sprintf(['..' filesep 'src' filesep 'Matlab' filesep 'supp'], 1i);
addpath(Path1);
addpath(Path2);
addpath(Path3);
diff --git a/docs/demos/demoMatlab_denoise.m b/demos/demoMatlab_denoise.m
index 14d3096..2031853 100644
--- a/docs/demos/demoMatlab_denoise.m
+++ b/demos/demoMatlab_denoise.m
@@ -2,9 +2,9 @@
clear; close all
fsep = '/';
-Path1 = sprintf(['..' fsep 'mex_compile' fsep 'installed'], 1i);
-Path2 = sprintf(['..' fsep '..' fsep '..' fsep 'data' fsep], 1i);
-Path3 = sprintf(['..' fsep 'supp'], 1i);
+Path1 = sprintf(['..' fsep 'src' fsep 'Matlab' fsep 'mex_compile' fsep 'installed'], 1i);
+Path2 = sprintf([ data' fsep], 1i);
+Path3 = sprintf(['..' filesep 'src' filesep 'Matlab' filesep 'supp'], 1i);
addpath(Path1); addpath(Path2); addpath(Path3);
Im = double(imread('lena_gray_512.tif'))/255; % loading image
diff --git a/docs/demos/demoMatlab_inpaint.m b/demos/demoMatlab_inpaint.m
index 66f9c15..a85f2b9 100644
--- a/docs/demos/demoMatlab_inpaint.m
+++ b/demos/demoMatlab_inpaint.m
@@ -1,7 +1,7 @@
% Image (2D) inpainting demo using CCPi-RGL
clear; close all
-Path1 = sprintf(['..' filesep 'mex_compile' filesep 'installed'], 1i);
-Path2 = sprintf(['..' filesep '..' filesep '..' filesep 'data' filesep], 1i);
+Path1 = sprintf(['..' filesep 'src' filesep 'Matlab' filesep 'mex_compile' filesep 'installed'], 1i);
+Path2 = sprintf(['data' filesep], 1i);
addpath(Path1);
addpath(Path2);
diff --git a/docs/demos/demo_cpu_inpainters.py b/demos/demo_cpu_inpainters.py
index 3b4191b..d07e74a 100644
--- a/docs/demos/demo_cpu_inpainters.py
+++ b/demos/demo_cpu_inpainters.py
@@ -29,7 +29,7 @@ def printParametersToString(pars):
###############################################################################
# read sinogram and the mask
-filename = os.path.join(".." , ".." , ".." , "data" ,"SinoInpaint.mat")
+filename = os.path.join("data" ,"SinoInpaint.mat")
sino = io.loadmat(filename)
sino_full = sino.get('Sinogram')
Mask = sino.get('Mask')
diff --git a/docs/demos/demo_cpu_regularisers.py b/demos/demo_cpu_regularisers.py
index e6befa9..373502b 100644
--- a/docs/demos/demo_cpu_regularisers.py
+++ b/demos/demo_cpu_regularisers.py
@@ -31,7 +31,7 @@ def printParametersToString(pars):
return txt
###############################################################################
#%%
-filename = os.path.join(".." , ".." , ".." , "data" ,"lena_gray_512.tif")
+filename = os.path.join( "data" ,"lena_gray_512.tif")
# read image
Im = plt.imread(filename)
diff --git a/docs/demos/demo_cpu_regularisers3D.py b/demos/demo_cpu_regularisers3D.py
index 2d2fc22..56baf13 100644
--- a/docs/demos/demo_cpu_regularisers3D.py
+++ b/demos/demo_cpu_regularisers3D.py
@@ -30,7 +30,7 @@ def printParametersToString(pars):
return txt
###############################################################################
#%%
-filename = os.path.join(".." , ".." , ".." , "data" ,"lena_gray_512.tif")
+filename = os.path.join( "data" ,"lena_gray_512.tif")
# read image
Im = plt.imread(filename)
diff --git a/docs/demos/demo_cpu_vs_gpu_regularisers.py b/demos/demo_cpu_vs_gpu_regularisers.py
index 230a761..5ce8da4 100644
--- a/docs/demos/demo_cpu_vs_gpu_regularisers.py
+++ b/demos/demo_cpu_vs_gpu_regularisers.py
@@ -31,7 +31,7 @@ def printParametersToString(pars):
return txt
###############################################################################
-filename = os.path.join(".." , ".." , ".." , "data" ,"lena_gray_512.tif")
+filename = os.path.join("data" ,"lena_gray_512.tif")
# read image
Im = plt.imread(filename)
diff --git a/docs/demos/demo_gpu_regularisers.py b/demos/demo_gpu_regularisers.py
index e1c6575..bc9baf2 100644
--- a/docs/demos/demo_gpu_regularisers.py
+++ b/demos/demo_gpu_regularisers.py
@@ -31,7 +31,7 @@ def printParametersToString(pars):
return txt
###############################################################################
#%%
-filename = os.path.join(".." , ".." , ".." , "data" ,"lena_gray_512.tif")
+filename = os.path.join( "data" ,"lena_gray_512.tif")
# read image
Im = plt.imread(filename)
diff --git a/docs/demos/demo_gpu_regularisers3D.py b/demos/demo_gpu_regularisers3D.py
index b6058d2..2f49cb9 100644
--- a/docs/demos/demo_gpu_regularisers3D.py
+++ b/demos/demo_gpu_regularisers3D.py
@@ -30,7 +30,7 @@ def printParametersToString(pars):
return txt
###############################################################################
#%%
-filename = os.path.join(".." , ".." , ".." , "data" ,"lena_gray_512.tif")
+filename = os.path.join( "data" ,"lena_gray_512.tif")
# read image
Im = plt.imread(filename)
@@ -70,7 +70,7 @@ del Im2
slices = 20
-filename = os.path.join(".." , ".." , ".." , "data" ,"lena_gray_512.tif")
+filename = os.path.join( "data" ,"lena_gray_512.tif")
Im = plt.imread(filename)
Im = np.asarray(Im, dtype='float32')
diff --git a/docs/images/TV_vs_NLTV.jpg b/demos/images/TV_vs_NLTV.jpg
index e976512..e976512 100644
--- a/docs/images/TV_vs_NLTV.jpg
+++ b/demos/images/TV_vs_NLTV.jpg
Binary files differ
diff --git a/docs/images/probl.pdf b/demos/images/probl.pdf
index 6a06021..6a06021 100644
--- a/docs/images/probl.pdf
+++ b/demos/images/probl.pdf
Binary files differ
diff --git a/docs/images/probl.png b/demos/images/probl.png
index af0e852..af0e852 100644
--- a/docs/images/probl.png
+++ b/demos/images/probl.png
Binary files differ
diff --git a/docs/images/reg_penalties.jpg b/demos/images/reg_penalties.jpg
index 923d5c4..923d5c4 100644
--- a/docs/images/reg_penalties.jpg
+++ b/demos/images/reg_penalties.jpg
Binary files differ
diff --git a/docs/demos/qualitymetrics.py b/demos/qualitymetrics.py
index 850829e..850829e 100644
--- a/docs/demos/qualitymetrics.py
+++ b/demos/qualitymetrics.py
diff --git a/docs/installation.txt b/docs/installation.txt
deleted file mode 100644
index f6db38c..0000000
--- a/docs/installation.txt
+++ /dev/null
@@ -1,11 +0,0 @@
-One can install CCPi-RGL toolkit using cmake:
-
-
-cmake ../CCPi-Regularisation-Toolkit/ -DBUILD_MATLAB_WRAPPERS=ON -DBUILD_PYTHON_WRAPPERS=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=install -DMatlab_ROOT_DIR=<Matlab directory> -DBUILD_CUDA=OFF
-
-make
-
-make install
-
-Running Matlab from Linux do:
-PATH="/path/to/mex/:$PATH" LD_LIBRARY_PATH="/path/to/library:$LD_LIBRARY_PATH" ./matlab -nosplash &
diff --git a/test/test_CPU_regularisers.py b/test/test_CPU_regularisers.py
new file mode 100644
index 0000000..42e4735
--- /dev/null
+++ b/test/test_CPU_regularisers.py
@@ -0,0 +1,91 @@
+import unittest
+import math
+import os
+import timeit
+from ccpi.filters.regularisers import FGP_TV, SB_TV, TGV, LLT_ROF, FGP_dTV, NDF, Diff4th, ROF_TV
+from testroutines import *
+
+###############################################################################
+
+class TestRegularisers(unittest.TestCase):
+
+ def getPars(self,alg,noi=1200):
+ filename = os.path.join("lena_gray_512.tif")
+ plt = TiffReader()
+ # read image
+ Im = plt.imread(filename)
+ Im = np.asarray(Im, dtype='float32')
+ Im = Im / 255
+ perc = 0.05
+ u0 = Im + np.random.normal(loc=0,
+ scale=perc * Im,
+ size=np.shape(Im))
+ u_ref = Im + np.random.normal(loc=0,
+ scale=0.01 * Im,
+ size=np.shape(Im))
+ # map the u0 u0->u0>0
+ # f = np.frompyfunc(lambda x: 0 if x < 0 else x, 1,1)
+ u0 = u0.astype('float32')
+ u_ref = u_ref.astype('float32')
+ # set parameters
+ pars = {'algorithm': alg, \
+ 'input': u0, \
+ 'regularisation_parameter': 0.04, \
+ 'number_of_iterations': noi, \
+ 'tolerance_constant': 0.00001, \
+ 'methodTV': 0, \
+ 'nonneg': 0, \
+ 'printingOut': 0, \
+ 'time_marching_parameter': 0.00002
+ }
+ return Im, pars
+
+
+ def test_FGP_TV_CPU(self):
+ Im, pars = self.getPars(FGP_TV)
+
+ fgp_cpu = FGP_TV(pars['input'],
+ pars['regularisation_parameter'],
+ pars['number_of_iterations'],
+ pars['tolerance_constant'],
+ pars['methodTV'],
+ pars['nonneg'],
+ pars['printingOut'], 'cpu')
+
+ rms = rmse(Im, fgp_cpu)
+ pars['rmse'] = rms
+ self.assertAlmostEqual(rms,0.02,delta=0.01)
+
+ def test_TV_ROF_CPU(self):
+ # set parameters
+ Im, pars = self.getPars(ROF_TV)
+ # call routine
+ fgp_cpu = ROF_TV(pars['input'],
+ pars['regularisation_parameter'],
+ pars['number_of_iterations'],
+ pars['time_marching_parameter'], 'cpu')
+
+ rms = rmse(Im, fgp_cpu)
+ pars['rmse'] = rms
+
+ #txtstr = printParametersToString(pars)
+ #print(txtstr)
+ # now test that it generates some expected output
+ self.assertAlmostEqual(rms,0.02,delta=0.01)
+
+ def test_SB_TV_CPU(self):
+ # set parameters
+ Im, pars = self.getPars(SB_TV)
+ # call routine
+ fgp_cpu = SB_TV(pars['input'],
+ pars['regularisation_parameter'],
+ pars['number_of_iterations'],
+ pars['time_marching_parameter'], 'cpu')
+
+ rms = rmse(Im, fgp_cpu)
+ pars['rmse'] = rms
+
+ #txtstr = printParametersToString(pars)
+ #print(txtstr)
+ # now test that it generates some expected output
+ self.assertAlmostEqual(rms,0.02,delta=0.01)
diff --git a/test/test_FGP_TV.py b/test/test_FGP_TV.py
new file mode 100644
index 0000000..f0dc540
--- /dev/null
+++ b/test/test_FGP_TV.py
@@ -0,0 +1,152 @@
+import unittest
+import math
+import os
+import timeit
+from ccpi.filters.regularisers import FGP_TV
+#, FGP_TV, SB_TV, TGV, LLT_ROF, FGP_dTV, NDF, Diff4th
+from testroutines import *
+
+###############################################################################
+
+class TestRegularisers(unittest.TestCase):
+
+ def test_FGP_TV_CPU(self):
+ print(__name__)
+ filename = os.path.join("lena_gray_512.tif")
+ plt = TiffReader()
+ # read image
+ Im = plt.imread(filename)
+ Im = np.asarray(Im, dtype='float32')
+
+ Im = Im / 255
+ perc = 0.05
+ u0 = Im + np.random.normal(loc=0,
+ scale=perc * Im,
+ size=np.shape(Im))
+ u_ref = Im + np.random.normal(loc=0,
+ scale=0.01 * Im,
+ size=np.shape(Im))
+
+ # map the u0 u0->u0>0
+ # f = np.frompyfunc(lambda x: 0 if x < 0 else x, 1,1)
+ u0 = u0.astype('float32')
+ u_ref = u_ref.astype('float32')
+
+ print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
+ print("____________FGP-TV bench___________________")
+ print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
+
+ # set parameters
+ pars = {'algorithm': FGP_TV, \
+ 'input': u0, \
+ 'regularisation_parameter': 0.04, \
+ 'number_of_iterations': 1200, \
+ 'tolerance_constant': 0.00001, \
+ 'methodTV': 0, \
+ 'nonneg': 0, \
+ 'printingOut': 0
+ }
+
+ print("#############FGP TV CPU####################")
+ start_time = timeit.default_timer()
+ fgp_cpu = FGP_TV(pars['input'],
+ pars['regularisation_parameter'],
+ pars['number_of_iterations'],
+ pars['tolerance_constant'],
+ pars['methodTV'],
+ pars['nonneg'],
+ pars['printingOut'], 'cpu')
+
+ rms = rmse(Im, fgp_cpu)
+ pars['rmse'] = rms
+
+ txtstr = printParametersToString(pars)
+ txtstr += "%s = %.3fs" % ('elapsed time', timeit.default_timer() - start_time)
+ print(txtstr)
+ self.assertTrue(math.isclose(rms,0.02,rel_tol=1e-1))
+
+ def test_FGP_TV_CPU_vs_GPU(self):
+ print(__name__)
+ filename = os.path.join("lena_gray_512.tif")
+ plt = TiffReader()
+ # read image
+ Im = plt.imread(filename)
+ Im = np.asarray(Im, dtype='float32')
+
+ Im = Im / 255
+ perc = 0.05
+ u0 = Im + np.random.normal(loc=0,
+ scale=perc * Im,
+ size=np.shape(Im))
+ u_ref = Im + np.random.normal(loc=0,
+ scale=0.01 * Im,
+ size=np.shape(Im))
+
+ # map the u0 u0->u0>0
+ # f = np.frompyfunc(lambda x: 0 if x < 0 else x, 1,1)
+ u0 = u0.astype('float32')
+ u_ref = u_ref.astype('float32')
+
+ print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
+ print("____________FGP-TV bench___________________")
+ print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
+
+ # set parameters
+ pars = {'algorithm': FGP_TV, \
+ 'input': u0, \
+ 'regularisation_parameter': 0.04, \
+ 'number_of_iterations': 1200, \
+ 'tolerance_constant': 0.00001, \
+ 'methodTV': 0, \
+ 'nonneg': 0, \
+ 'printingOut': 0
+ }
+
+ print("#############FGP TV CPU####################")
+ start_time = timeit.default_timer()
+ fgp_cpu = FGP_TV(pars['input'],
+ pars['regularisation_parameter'],
+ pars['number_of_iterations'],
+ pars['tolerance_constant'],
+ pars['methodTV'],
+ pars['nonneg'],
+ pars['printingOut'], 'cpu')
+
+ rms = rmse(Im, fgp_cpu)
+ pars['rmse'] = rms
+
+ txtstr = printParametersToString(pars)
+ txtstr += "%s = %.3fs" % ('elapsed time', timeit.default_timer() - start_time)
+ print(txtstr)
+
+ print("##############FGP TV GPU##################")
+ start_time = timeit.default_timer()
+ try:
+ fgp_gpu = FGP_TV(pars['input'],
+ pars['regularisation_parameter'],
+ pars['number_of_iterations'],
+ pars['tolerance_constant'],
+ pars['methodTV'],
+ pars['nonneg'],
+ pars['printingOut'], 'gpu')
+
+ except ValueError as ve:
+ self.skipTest("Results not comparable. GPU computing error.")
+
+ rms = rmse(Im, fgp_gpu)
+ pars['rmse'] = rms
+ pars['algorithm'] = FGP_TV
+ txtstr = printParametersToString(pars)
+ txtstr += "%s = %.3fs" % ('elapsed time', timeit.default_timer() - start_time)
+ print(txtstr)
+
+ print("--------Compare the results--------")
+ tolerance = 1e-05
+ diff_im = np.zeros(np.shape(fgp_cpu))
+ diff_im = abs(fgp_cpu - fgp_gpu)
+ diff_im[diff_im > tolerance] = 1
+
+ self.assertLessEqual(diff_im.sum(), 1)
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/test/test_ROF_TV.py b/test/test_ROF_TV.py
index dda38b7..fa35680 100644
--- a/test/test_ROF_TV.py
+++ b/test/test_ROF_TV.py
@@ -53,9 +53,6 @@ class TestRegularisers(unittest.TestCase):
def test_ROF_TV_CPU_vs_GPU(self):
- # print ("tomas debug test function")
- print(__name__)
- self.fail("testfail2")
filename = os.path.join("lena_gray_512.tif")
plt = TiffReader()
# read image