summaryrefslogtreecommitdiffstats
path: root/test/testroutines.py
diff options
context:
space:
mode:
authorTomas Kulhanek <tomas.kulhanek@stfc.ac.uk>2019-02-28 16:24:01 +0000
committerGitHub <noreply@github.com>2019-02-28 16:24:01 +0000
commit879c87c5709ee194a8c7a2207f5a21d4a757f723 (patch)
treeeddf7bc14a998ffabc7e9e01f0cca2ac44b1d88a /test/testroutines.py
parent4c728cf72345f7ab7967380cb536529fd9b1403d (diff)
parent68e6f3397e8a450854f39a5d514e1f747b9031a4 (diff)
downloadregularization-879c87c5709ee194a8c7a2207f5a21d4a757f723.tar.gz
regularization-879c87c5709ee194a8c7a2207f5a21d4a757f723.tar.bz2
regularization-879c87c5709ee194a8c7a2207f5a21d4a757f723.tar.xz
regularization-879c87c5709ee194a8c7a2207f5a21d4a757f723.zip
Merge pull request #104 from vais-ral/newdirstructure
New directory structure, Merged other changes. The build script checks old and new structure.
Diffstat (limited to 'test/testroutines.py')
-rw-r--r--test/testroutines.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/test/testroutines.py b/test/testroutines.py
new file mode 100644
index 0000000..8da5c5e
--- /dev/null
+++ b/test/testroutines.py
@@ -0,0 +1,37 @@
+import numpy as np
+from PIL import Image
+
+class TiffReader(object):
+ def imread(self, filename):
+ return np.asarray(Image.open(filename))
+
+
+###############################################################################
+def printParametersToString(pars):
+ txt = r''
+ for key, value in pars.items():
+ if key == 'algorithm':
+ 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'
+ return txt
+
+
+def nrmse(im1, im2):
+ rmse = np.sqrt(np.sum((im2 - im1) ** 2) / float(im1.size))
+ max_val = max(np.max(im1), np.max(im2))
+ min_val = min(np.min(im1), np.min(im2))
+ return 1 - (rmse / (max_val - min_val))
+
+
+def rmse(im1, im2):
+ rmse = np.sqrt(np.sum((im1 - im2) ** 2) / float(im1.size))
+ return rmse
+
+
+###############################################################################