summaryrefslogtreecommitdiffstats
path: root/Wrappers
diff options
context:
space:
mode:
Diffstat (limited to 'Wrappers')
-rw-r--r--Wrappers/Python/demos/demo_cpu_regularisers.py23
-rw-r--r--Wrappers/Python/demos/demo_gpu_regularisers.py42
-rw-r--r--Wrappers/Python/demos/qualitymetrics.py6
-rw-r--r--Wrappers/Python/src/cpu_regularisers.pyx6
-rw-r--r--Wrappers/Python/src/gpu_regularisers.pyx4
5 files changed, 41 insertions, 40 deletions
diff --git a/Wrappers/Python/demos/demo_cpu_regularisers.py b/Wrappers/Python/demos/demo_cpu_regularisers.py
index 84d86c0..487bac7 100644
--- a/Wrappers/Python/demos/demo_cpu_regularisers.py
+++ b/Wrappers/Python/demos/demo_cpu_regularisers.py
@@ -27,7 +27,7 @@ def printParametersToString(pars):
txt += '\n'
return txt
###############################################################################
-
+#%%
filename = os.path.join(".." , ".." , ".." , "data" ,"lena_gray_512.tif")
# read image
@@ -135,22 +135,24 @@ imgplot = plt.imshow(fgp_cpu, cmap="gray")
plt.title('{}'.format('CPU results'))
# Uncomment to test 3D regularisation performance
+#%%
"""
N = 512
slices = 20
+filename = os.path.join(".." , ".." , ".." , "data" ,"lena_gray_512.tif")
Im = plt.imread(filename)
Im = np.asarray(Im, dtype='float32')
Im = Im/255
perc = 0.05
-noisyVol = np.zeros((N,N,slices),dtype='float32')
-idealVol = np.zeros((N,N,slices),dtype='float32')
+noisyVol = np.zeros((slices,N,N),dtype='float32')
+idealVol = np.zeros((slices,N,N),dtype='float32')
for i in range (slices):
- noisyVol[:,:,i] = Im + np.random.normal(loc = 0 , scale = perc * Im , size = np.shape(Im))
- idealVol[:,:,i] = Im
+ noisyVol[i,:,:] = Im + np.random.normal(loc = 0 , scale = perc * Im , size = np.shape(Im))
+ idealVol[i,:,:] = Im
print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
print ("_______________ROF-TV (3D)_________________")
@@ -161,7 +163,7 @@ fig = plt.figure(3)
plt.suptitle('Performance of ROF-TV regulariser using the CPU')
a=fig.add_subplot(1,2,1)
a.set_title('Noisy 15th slice of a volume')
-imgplot = plt.imshow(noisyVol[:,:,10],cmap="gray")
+imgplot = plt.imshow(noisyVol[10,:,:],cmap="gray")
# set parameters
pars = {'algorithm': ROF_TV, \
@@ -189,7 +191,7 @@ props = dict(boxstyle='round', facecolor='wheat', alpha=0.75)
# place a text box in upper left in axes coords
a.text(0.15, 0.25, txtstr, transform=a.transAxes, fontsize=14,
verticalalignment='top', bbox=props)
-imgplot = plt.imshow(rof_cpu3D[:,:,10], cmap="gray")
+imgplot = plt.imshow(rof_cpu3D[10,:,:], cmap="gray")
plt.title('{}'.format('Recovered volume on the CPU using ROF-TV'))
print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
@@ -201,7 +203,7 @@ fig = plt.figure(4)
plt.suptitle('Performance of FGP-TV regulariser using the CPU')
a=fig.add_subplot(1,2,1)
a.set_title('Noisy Image')
-imgplot = plt.imshow(noisyVol[:,:,10],cmap="gray")
+imgplot = plt.imshow(noisyVol[10,:,:],cmap="gray")
# set parameters
pars = {'algorithm' : FGP_TV, \
@@ -238,6 +240,7 @@ props = dict(boxstyle='round', facecolor='wheat', alpha=0.75)
# place a text box in upper left in axes coords
a.text(0.15, 0.25, txtstr, transform=a.transAxes, fontsize=14,
verticalalignment='top', bbox=props)
-imgplot = plt.imshow(fgp_cpu3D[:,:,10], cmap="gray")
+imgplot = plt.imshow(fgp_cpu3D[10,:,:], cmap="gray")
plt.title('{}'.format('Recovered volume on the CPU using FGP-TV'))
-""" \ No newline at end of file
+"""
+#%% \ No newline at end of file
diff --git a/Wrappers/Python/demos/demo_gpu_regularisers.py b/Wrappers/Python/demos/demo_gpu_regularisers.py
index fd7b32c..5eb7876 100644
--- a/Wrappers/Python/demos/demo_gpu_regularisers.py
+++ b/Wrappers/Python/demos/demo_gpu_regularisers.py
@@ -27,7 +27,7 @@ def printParametersToString(pars):
txt += '\n'
return txt
###############################################################################
-
+#%%
filename = os.path.join(".." , ".." , ".." , "data" ,"lena_gray_512.tif")
# read image
@@ -51,7 +51,7 @@ print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
## plot
fig = plt.figure(1)
plt.suptitle('Performance of the ROF-TV regulariser using the GPU')
-a=fig.add_subplot(1,4,1)
+a=fig.add_subplot(1,2,1)
a.set_title('Noisy Image')
imgplot = plt.imshow(u0,cmap="gray")
@@ -75,7 +75,7 @@ pars['algorithm'] = ROF_TV
txtstr = printParametersToString(pars)
txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time)
print (txtstr)
-a=fig.add_subplot(1,4,3)
+a=fig.add_subplot(1,2,2)
# these are matplotlib.patch.Patch properties
props = dict(boxstyle='round', facecolor='wheat', alpha=0.75)
@@ -93,7 +93,7 @@ print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
## plot
fig = plt.figure(2)
plt.suptitle('Performance of the FGP-TV regulariser using the GPU')
-a=fig.add_subplot(1,4,1)
+a=fig.add_subplot(1,2,1)
a.set_title('Noisy Image')
imgplot = plt.imshow(u0,cmap="gray")
@@ -124,7 +124,7 @@ pars['algorithm'] = FGP_TV
txtstr = printParametersToString(pars)
txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time)
print (txtstr)
-a=fig.add_subplot(1,4,3)
+a=fig.add_subplot(1,2,2)
# these are matplotlib.patch.Patch properties
props = dict(boxstyle='round', facecolor='wheat', alpha=0.75)
@@ -136,22 +136,24 @@ plt.title('{}'.format('GPU results'))
# Uncomment to test 3D regularisation performance
+#%%
"""
N = 512
slices = 20
+filename = os.path.join(".." , ".." , ".." , "data" ,"lena_gray_512.tif")
Im = plt.imread(filename)
Im = np.asarray(Im, dtype='float32')
Im = Im/255
perc = 0.05
-noisyVol = np.zeros((N,N,slices),dtype='float32')
-idealVol = np.zeros((N,N,slices),dtype='float32')
+noisyVol = np.zeros((slices,N,N),dtype='float32')
+idealVol = np.zeros((slices,N,N),dtype='float32')
for i in range (slices):
- noisyVol[:,:,i] = Im + np.random.normal(loc = 0 , scale = perc * Im , size = np.shape(Im))
- idealVol[:,:,i] = Im
+ noisyVol[i,:,:] = Im + np.random.normal(loc = 0 , scale = perc * Im , size = np.shape(Im))
+ idealVol[i,:,:] = Im
print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
print ("_______________ROF-TV (3D)_________________")
@@ -162,7 +164,7 @@ fig = plt.figure(3)
plt.suptitle('Performance of ROF-TV regulariser using the GPU')
a=fig.add_subplot(1,2,1)
a.set_title('Noisy 15th slice of a volume')
-imgplot = plt.imshow(noisyVol[:,:,10],cmap="gray")
+imgplot = plt.imshow(noisyVol[10,:,:],cmap="gray")
# set parameters
pars = {'algorithm': ROF_TV, \
@@ -171,7 +173,7 @@ pars = {'algorithm': ROF_TV, \
'number_of_iterations': 500,\
'time_marching_parameter': 0.0025
}
-print ("#############ROF TV CPU####################")
+print ("#############ROF TV GPU####################")
start_time = timeit.default_timer()
rof_gpu3D = ROF_TV(pars['input'],
pars['regularisation_parameter'],
@@ -190,7 +192,7 @@ props = dict(boxstyle='round', facecolor='wheat', alpha=0.75)
# place a text box in upper left in axes coords
a.text(0.15, 0.25, txtstr, transform=a.transAxes, fontsize=14,
verticalalignment='top', bbox=props)
-imgplot = plt.imshow(rof_gpu3D[:,:,10], cmap="gray")
+imgplot = plt.imshow(rof_gpu3D[10,:,:], cmap="gray")
plt.title('{}'.format('Recovered volume on the GPU using ROF-TV'))
print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
@@ -202,7 +204,7 @@ fig = plt.figure(4)
plt.suptitle('Performance of FGP-TV regulariser using the GPU')
a=fig.add_subplot(1,2,1)
a.set_title('Noisy Image')
-imgplot = plt.imshow(noisyVol[:,:,10],cmap="gray")
+imgplot = plt.imshow(noisyVol[10,:,:],cmap="gray")
# set parameters
pars = {'algorithm' : FGP_TV, \
@@ -214,8 +216,8 @@ pars = {'algorithm' : FGP_TV, \
'nonneg': 0 ,\
'printingOut': 0
}
-
-print ("#############FGP TV CPU####################")
+
+print ("#############FGP TV GPU####################")
start_time = timeit.default_timer()
fgp_gpu3D = FGP_TV(pars['input'],
pars['regularisation_parameter'],
@@ -223,9 +225,8 @@ fgp_gpu3D = FGP_TV(pars['input'],
pars['tolerance_constant'],
pars['methodTV'],
pars['nonneg'],
- pars['printingOut'],'gpu')
-
-
+ pars['printingOut'],'gpu')
+
rms = rmse(idealVol, fgp_gpu3D)
pars['rmse'] = rms
@@ -239,9 +240,8 @@ props = dict(boxstyle='round', facecolor='wheat', alpha=0.75)
# place a text box in upper left in axes coords
a.text(0.15, 0.25, txtstr, transform=a.transAxes, fontsize=14,
verticalalignment='top', bbox=props)
-imgplot = plt.imshow(fgp_gpu3D[:,:,10], cmap="gray")
+imgplot = plt.imshow(fgp_gpu3D[10,:,:], cmap="gray")
plt.title('{}'.format('Recovered volume on the GPU using FGP-TV'))
-
+#%%
"""
-
diff --git a/Wrappers/Python/demos/qualitymetrics.py b/Wrappers/Python/demos/qualitymetrics.py
index 32fa479..850829e 100644
--- a/Wrappers/Python/demos/qualitymetrics.py
+++ b/Wrappers/Python/demos/qualitymetrics.py
@@ -8,13 +8,11 @@ Created on Wed Feb 21 13:34:32 2018
import numpy as np
def nrmse(im1, im2):
- a, b = im1.shape
- rmse = np.sqrt(np.sum((im2 - im1) ** 2) / float(a * b))
+ 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):
- a, b = im1.shape
- rmse = np.sqrt(np.sum((im1 - im2) ** 2) / float(a * b))
+ rmse = np.sqrt(np.sum((im1 - im2) ** 2) / float(im1.size))
return rmse
diff --git a/Wrappers/Python/src/cpu_regularisers.pyx b/Wrappers/Python/src/cpu_regularisers.pyx
index 248bad1..0f08f7f 100644
--- a/Wrappers/Python/src/cpu_regularisers.pyx
+++ b/Wrappers/Python/src/cpu_regularisers.pyx
@@ -48,8 +48,8 @@ def TV_ROF_2D(np.ndarray[np.float32_t, ndim=2, mode="c"] inputData,
return outputData
def TV_ROF_3D(np.ndarray[np.float32_t, ndim=3, mode="c"] inputData,
- int iterationsNumb,
float regularisation_parameter,
+ int iterationsNumb,
float marching_step_parameter):
cdef long dims[3]
dims[0] = inputData.shape[0]
@@ -60,7 +60,7 @@ def TV_ROF_3D(np.ndarray[np.float32_t, ndim=3, mode="c"] inputData,
np.zeros([dims[0],dims[1],dims[2]], dtype='float32')
# Run ROF iterations for 3D data
- TV_ROF_CPU_main(&inputData[0,0,0], &outputData[0,0,0], regularisation_parameter, iterationsNumb, marching_step_parameter, dims[0], dims[1], dims[2])
+ TV_ROF_CPU_main(&inputData[0,0,0], &outputData[0,0,0], regularisation_parameter, iterationsNumb, marching_step_parameter, dims[2], dims[1], dims[0])
return outputData
@@ -122,5 +122,5 @@ def TV_FGP_3D(np.ndarray[np.float32_t, ndim=3, mode="c"] inputData,
methodTV,
nonneg,
printM,
- dims[0], dims[1], dims[2])
+ dims[2], dims[1], dims[0])
return outputData
diff --git a/Wrappers/Python/src/gpu_regularisers.pyx b/Wrappers/Python/src/gpu_regularisers.pyx
index 7ebd011..ea746d3 100644
--- a/Wrappers/Python/src/gpu_regularisers.pyx
+++ b/Wrappers/Python/src/gpu_regularisers.pyx
@@ -106,7 +106,7 @@ def ROFTV3D(np.ndarray[np.float32_t, ndim=3, mode="c"] inputData,
regularisation_parameter,
iterations ,
time_marching_parameter,
- dims[0], dims[1], dims[2]);
+ dims[2], dims[1], dims[0]);
return outputData
#****************************************************************#
@@ -165,6 +165,6 @@ def FGPTV3D(np.ndarray[np.float32_t, ndim=3, mode="c"] inputData,
methodTV,
nonneg,
printM,
- dims[0], dims[1], dims[2]);
+ dims[2], dims[1], dims[0]);
return outputData