summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/test_CPU_regularisers.py113
-rw-r--r--test/test_FGP_TV.py152
-rw-r--r--test/test_ROF_TV.py124
3 files changed, 75 insertions, 314 deletions
diff --git a/test/test_CPU_regularisers.py b/test/test_CPU_regularisers.py
index 42e4735..8940926 100644
--- a/test/test_CPU_regularisers.py
+++ b/test/test_CPU_regularisers.py
@@ -9,7 +9,7 @@ from testroutines import *
class TestRegularisers(unittest.TestCase):
- def getPars(self,alg,noi=1200):
+ def getPars(self):
filename = os.path.join("lena_gray_512.tif")
plt = TiffReader()
# read image
@@ -28,64 +28,101 @@ class TestRegularisers(unittest.TestCase):
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
+ #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,u0,u_ref
def test_FGP_TV_CPU(self):
- Im, pars = self.getPars(FGP_TV)
+ Im,input,ref = self.getPars()
- fgp_cpu = FGP_TV(pars['input'],
- pars['regularisation_parameter'],
- pars['number_of_iterations'],
- pars['tolerance_constant'],
- pars['methodTV'],
- pars['nonneg'],
- pars['printingOut'], 'cpu')
+ fgp_cpu = FGP_TV(input,0.04,1200,1e-5,0,0,0,'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)
+ Im, input,ref = self.getPars()
# call routine
- fgp_cpu = ROF_TV(pars['input'],
- pars['regularisation_parameter'],
- pars['number_of_iterations'],
- pars['time_marching_parameter'], 'cpu')
+ fgp_cpu = ROF_TV(input,0.04,1200,2e-5, '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)
+ Im, input,ref = self.getPars()
# call routine
- fgp_cpu = SB_TV(pars['input'],
- pars['regularisation_parameter'],
- pars['number_of_iterations'],
- pars['time_marching_parameter'], 'cpu')
+ sb_cpu = SB_TV(input,0.04,150,1e-5,0,0,'cpu')
- rms = rmse(Im, fgp_cpu)
- pars['rmse'] = rms
+ rms = rmse(Im, sb_cpu)
+
+ # now test that it generates some expected output
+ self.assertAlmostEqual(rms,0.02,delta=0.01)
+
+ def test_TGV_CPU(self):
+ # set parameters
+ Im, input,ref = self.getPars()
+ # call routine
+ sb_cpu = TGV(input,0.04,1.0,2.0,250,12,'cpu')
+
+ rms = rmse(Im, sb_cpu)
- #txtstr = printParametersToString(pars)
- #print(txtstr)
# now test that it generates some expected output
self.assertAlmostEqual(rms,0.02,delta=0.01)
+
+ def test_LLT_ROF_CPU(self):
+ # set parameters
+ Im, input,ref = self.getPars()
+ # call routine
+ sb_cpu = LLT_ROF(input,0.04,0.01,1000,1e-4,'cpu')
+
+ rms = rmse(Im, sb_cpu)
+
+ # now test that it generates some expected output
+ self.assertAlmostEqual(rms,0.02,delta=0.01)
+
+ def test_NDF_CPU(self):
+ # set parameters
+ Im, input,ref = self.getPars()
+ # call routine
+ sb_cpu = NDF(input, 0.06, 0.04,1000,0.025,1, 'cpu')
+
+ rms = rmse(Im, sb_cpu)
+
+ # now test that it generates some expected output
+ self.assertAlmostEqual(rms, 0.02, delta=0.01)
+
+ def test_Diff4th_CPU(self):
+ # set parameters
+ Im, input,ref = self.getPars()
+ # call routine
+ sb_cpu = Diff4th(input, 3.5,0.02,500,0.001, 'cpu')
+
+ rms = rmse(Im, sb_cpu)
+
+ # now test that it generates some expected output
+ self.assertAlmostEqual(rms, 0.02, delta=0.01)
+
+ def test_FGP_dTV_CPU(self):
+ # set parameters
+ Im, input,ref = self.getPars()
+ # call routine
+ sb_cpu = FGP_dTV(input,ref,0.04,1000,1e-7,0.2,0,0,0, 'cpu')
+
+ rms = rmse(Im, sb_cpu)
+
+ # 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
deleted file mode 100644
index f0dc540..0000000
--- a/test/test_FGP_TV.py
+++ /dev/null
@@ -1,152 +0,0 @@
-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
deleted file mode 100644
index fa35680..0000000
--- a/test/test_ROF_TV.py
+++ /dev/null
@@ -1,124 +0,0 @@
-import unittest
-import math
-import os
-import timeit
-from ccpi.filters.regularisers import ROF_TV
-#, FGP_TV, SB_TV, TGV, LLT_ROF, FGP_dTV, NDF, Diff4th
-from testroutines import *
-
-class TestRegularisers(unittest.TestCase):
-
- def test_ROF_TV_CPU(self):
- 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': ROF_TV, \
- 'input': u0, \
- 'regularisation_parameter': 0.04, \
- 'number_of_iterations': 2500, \
- 'time_marching_parameter': 0.00002
- }
- print("#############ROF TV CPU####################")
- start_time = timeit.default_timer()
- rof_cpu = ROF_TV(pars['input'],
- pars['regularisation_parameter'],
- pars['number_of_iterations'],
- pars['time_marching_parameter'], 'cpu')
- rms = rmse(Im, rof_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.02067839,rel_tol=1e-2))
-
-
- def test_ROF_TV_CPU_vs_GPU(self):
- 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("____________ROF-TV bench___________________")
- print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
-
- # set parameters
- pars = {'algorithm': ROF_TV, \
- 'input': u0, \
- 'regularisation_parameter': 0.04, \
- 'number_of_iterations': 2500, \
- 'time_marching_parameter': 0.00002
- }
- print("##############ROF TV GPU##################")
- start_time = timeit.default_timer()
- try:
- rof_gpu = ROF_TV(pars['input'],
- pars['regularisation_parameter'],
- pars['number_of_iterations'],
- pars['time_marching_parameter'], 'gpu')
- except ValueError as ve:
- self.skipTest("Results not comparable. GPU computing error.")
-
- rms = rmse(Im, rof_gpu)
- pars['rmse'] = rms
- pars['algorithm'] = ROF_TV
- txtstr = printParametersToString(pars)
- txtstr += "%s = %.3fs" % ('elapsed time', timeit.default_timer() - start_time)
- print(txtstr)
-
- print("#############ROF TV CPU####################")
- start_time = timeit.default_timer()
- rof_cpu = ROF_TV(pars['input'],
- pars['regularisation_parameter'],
- pars['number_of_iterations'],
- pars['time_marching_parameter'], 'cpu')
- rms = rmse(Im, rof_cpu)
- pars['rmse'] = rms
-
- txtstr = printParametersToString(pars)
- txtstr += "%s = %.3fs" % ('elapsed time', timeit.default_timer() - start_time)
- print(txtstr)
- print("--------Compare the results--------")
- tolerance = 1e-04
- diff_im = np.zeros(np.shape(rof_cpu))
- diff_im = abs(rof_cpu - rof_gpu)
- diff_im[diff_im > tolerance] = 1
- self.assertLessEqual(diff_im.sum(), 1)
-
-if __name__ == '__main__':
- unittest.main()