diff options
author | Daniil Kazantsev <dkazanc3@googlemail.com> | 2019-03-17 11:12:23 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-17 11:12:23 +0000 |
commit | ce6ec432cca73780e6f30e7075c0eb1b661a13be (patch) | |
tree | b8654877391908a82e2284f2b00d57a3bac67920 /demos | |
parent | 514ba391805517a999db7ef42808b9ae9662b67b (diff) | |
parent | 527e8b28aad16d09b37fa8c9d8790a89276d68b1 (diff) | |
download | regularization-ce6ec432cca73780e6f30e7075c0eb1b661a13be.tar.gz regularization-ce6ec432cca73780e6f30e7075c0eb1b661a13be.tar.bz2 regularization-ce6ec432cca73780e6f30e7075c0eb1b661a13be.tar.xz regularization-ce6ec432cca73780e6f30e7075c0eb1b661a13be.zip |
Merge pull request #110 from vais-ral/tol
Tolerance-based stopping criterion, fixes for a new structure, new demos
Diffstat (limited to 'demos')
-rw-r--r-- | demos/SoftwareX_supp/Demo_RealData_Recon_SX.py | 22 | ||||
-rw-r--r-- | demos/SoftwareX_supp/Demo_SimulData_ParOptimis_SX.py | 2 | ||||
-rw-r--r-- | demos/SoftwareX_supp/Demo_SimulData_Recon_SX.py | 3 | ||||
-rw-r--r-- | demos/SoftwareX_supp/Demo_VolumeDenoise.py | 503 | ||||
-rw-r--r-- | demos/demoMatlab_3Ddenoise.m | 52 | ||||
-rw-r--r-- | demos/demoMatlab_denoise.m | 119 | ||||
-rw-r--r-- | demos/demo_cpu_regularisers.py | 158 | ||||
-rw-r--r-- | demos/demo_cpu_regularisers3D.py | 129 | ||||
-rw-r--r-- | demos/demo_cpu_vs_gpu_regularisers.py | 250 | ||||
-rw-r--r-- | demos/demo_gpu_regularisers.py | 158 | ||||
-rw-r--r-- | demos/demo_gpu_regularisers3D.py | 119 |
11 files changed, 995 insertions, 520 deletions
diff --git a/demos/SoftwareX_supp/Demo_RealData_Recon_SX.py b/demos/SoftwareX_supp/Demo_RealData_Recon_SX.py index 01491d9..5991989 100644 --- a/demos/SoftwareX_supp/Demo_RealData_Recon_SX.py +++ b/demos/SoftwareX_supp/Demo_RealData_Recon_SX.py @@ -1,15 +1,15 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ -This demo scripts support the following publication: -"CCPi-Regularisation Toolkit for computed tomographic image reconstruction with +This demo scripts support the following publication: +"CCPi-Regularisation Toolkit for computed tomographic image reconstruction with proximal splitting algorithms" by Daniil Kazantsev, Edoardo Pasca, Martin J. Turner, Philip J. Withers; Software X, 2019 ____________________________________________________________________________ * Reads real tomographic data (stored at Zenodo) --- https://doi.org/10.5281/zenodo.2578893 * Reconstructs using TomoRec software -* Saves reconstructed images +* Saves reconstructed images ____________________________________________________________________________ >>>>> Dependencies: <<<<< 1. ASTRA toolbox: conda install -c astra-toolbox astra-toolbox @@ -40,7 +40,7 @@ data_norm = normaliser(dataRaw, flats, darks, log='log') del dataRaw, darks, flats intens_max = 2.3 -plt.figure() +plt.figure() plt.subplot(131) plt.imshow(data_norm[:,150,:],vmin=0, vmax=intens_max) plt.title('2D Projection (analytical)') @@ -72,7 +72,7 @@ FBPrec = RectoolsDIR.FBP(data_norm[0:100,:,det_y_crop]) sliceSel = 50 max_val = 0.003 -plt.figure() +plt.figure() plt.subplot(131) plt.imshow(FBPrec[sliceSel,:,:],vmin=0, vmax=max_val, cmap="gray") plt.title('FBP Reconstruction, axial view') @@ -108,10 +108,10 @@ RectoolsIR = RecToolsIR(DetectorsDimH = np.size(det_y_crop), # DetectorsDimH # DetectorsDimV = 100, # DetectorsDimV # detector dimension (vertical) for 3D case only AnglesVec = angles_rad, # array of angles in radians ObjSize = N_size, # a scalar to define reconstructed object dimensions - datafidelity='LS',# data fidelity, choose LS, PWLS (wip), GH (wip), Student (wip) + datafidelity='LS',# data fidelity, choose LS, PWLS, GH (wip), Students t (wip) nonnegativity='ENABLE', # enable nonnegativity constraint (set to 'ENABLE') OS_number = None, # the number of subsets, NONE/(or > 1) ~ classical / ordered subsets - tolerance = 1e-08, # tolerance to stop outer iterations earlier + tolerance = 0.0, # tolerance to stop inner (regularisation) iterations earlier device='gpu') #%% print ("Reconstructing with ADMM method using SB-TV penalty") @@ -124,7 +124,7 @@ RecADMM_reg_sbtv = RectoolsIR.ADMM(data_norm[0:100,:,det_y_crop], sliceSel = 50 max_val = 0.003 -plt.figure() +plt.figure() plt.subplot(131) plt.imshow(RecADMM_reg_sbtv[sliceSel,:,:],vmin=0, vmax=max_val, cmap="gray") plt.title('3D ADMM-SB-TV Reconstruction, axial view') @@ -164,7 +164,7 @@ RecADMM_reg_rofllt = RectoolsIR.ADMM(data_norm[0:100,:,det_y_crop], sliceSel = 50 max_val = 0.003 -plt.figure() +plt.figure() plt.subplot(131) plt.imshow(RecADMM_reg_rofllt[sliceSel,:,:],vmin=0, vmax=max_val) plt.title('3D ADMM-ROFLLT Reconstruction, axial view') @@ -202,7 +202,7 @@ RecADMM_reg_tgv = RectoolsIR.ADMM(data_norm[0:100,:,det_y_crop], sliceSel = 50 max_val = 0.003 -plt.figure() +plt.figure() plt.subplot(131) plt.imshow(RecADMM_reg_tgv[sliceSel,:,:],vmin=0, vmax=max_val) plt.title('3D ADMM-TGV Reconstruction, axial view') @@ -228,4 +228,4 @@ for i in range(0,np.size(RecADMM_reg_tgv,0)): # Saving recpnstructed data with a unique time label np.save('Dendr_ADMM_TGV'+str(time_label)+'.npy', RecADMM_reg_tgv) del RecADMM_reg_tgv -#%%
\ No newline at end of file +#%% diff --git a/demos/SoftwareX_supp/Demo_SimulData_ParOptimis_SX.py b/demos/SoftwareX_supp/Demo_SimulData_ParOptimis_SX.py index 59ffc0e..be99afe 100644 --- a/demos/SoftwareX_supp/Demo_SimulData_ParOptimis_SX.py +++ b/demos/SoftwareX_supp/Demo_SimulData_ParOptimis_SX.py @@ -77,7 +77,7 @@ RectoolsIR = RecToolsIR(DetectorsDimH = Horiz_det, # DetectorsDimH # detector d datafidelity='LS',# data fidelity, choose LS, PWLS (wip), GH (wip), Student (wip) nonnegativity='ENABLE', # enable nonnegativity constraint (set to 'ENABLE') OS_number = None, # the number of subsets, NONE/(or > 1) ~ classical / ordered subsets - tolerance = 1e-08, # tolerance to stop outer iterations earlier + tolerance = 0.0, # tolerance to stop inner (regularisation) iterations earlier device='gpu') #%% param_space = 30 diff --git a/demos/SoftwareX_supp/Demo_SimulData_Recon_SX.py b/demos/SoftwareX_supp/Demo_SimulData_Recon_SX.py index 93b0cef..ae2bfba 100644 --- a/demos/SoftwareX_supp/Demo_SimulData_Recon_SX.py +++ b/demos/SoftwareX_supp/Demo_SimulData_Recon_SX.py @@ -78,7 +78,6 @@ plt.title('3D Phantom, coronal (Y-Z) view') plt.subplot(133) plt.imshow(phantom[:,:,sliceSel],vmin=0, vmax=1, cmap="PuOr") plt.title('3D Phantom, sagittal view') - """ plt.show() #%% @@ -164,7 +163,7 @@ RectoolsIR = RecToolsIR(DetectorsDimH = Horiz_det, # DetectorsDimH # detector d datafidelity='LS',# data fidelity, choose LS, PWLS (wip), GH (wip), Student (wip) nonnegativity='ENABLE', # enable nonnegativity constraint (set to 'ENABLE') OS_number = None, # the number of subsets, NONE/(or > 1) ~ classical / ordered subsets - tolerance = 1e-08, # tolerance to stop outer iterations earlier + tolerance = 0.0, # tolerance to stop inner (regularisation) iterations earlier device='gpu') #%% print ("Reconstructing with ADMM method using SB-TV penalty") diff --git a/demos/SoftwareX_supp/Demo_VolumeDenoise.py b/demos/SoftwareX_supp/Demo_VolumeDenoise.py new file mode 100644 index 0000000..e128127 --- /dev/null +++ b/demos/SoftwareX_supp/Demo_VolumeDenoise.py @@ -0,0 +1,503 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +This demo scripts support the following publication: +"CCPi-Regularisation Toolkit for computed tomographic image reconstruction with +proximal splitting algorithms" by Daniil Kazantsev, Edoardo Pasca, Martin J. Turner, + Philip J. Withers; Software X, 2019 +____________________________________________________________________________ +* Generates phantom using TomoPhantom software +* Denoise using closely to optimal parameters +____________________________________________________________________________ +>>>>> Dependencies: <<<<< +1. TomoPhantom software for phantom and data generation + +@author: Daniil Kazantsev, e:mail daniil.kazantsev@diamond.ac.uk +Apache 2.0. +""" +import timeit +import matplotlib.pyplot as plt +# import matplotlib.gridspec as gridspec +import numpy as np +import os +import tomophantom +from tomophantom import TomoP3D +from tomophantom.supp.artifacts import ArtifactsClass +from ccpi.supp.qualitymetrics import QualityTools +from scipy.signal import gaussian +from ccpi.filters.regularisers import ROF_TV, FGP_TV, SB_TV, LLT_ROF, TGV, NDF, Diff4th +#%% +print ("Building 3D phantom using TomoPhantom software") +tic=timeit.default_timer() +model = 16 # select a model number from the library +N_size = 128 # Define phantom dimensions using a scalar value (cubic phantom) +path = os.path.dirname(tomophantom.__file__) +path_library3D = os.path.join(path, "Phantom3DLibrary.dat") +#This will generate a N_size x N_size x N_size phantom (3D) +phantom_tm = TomoP3D.Model(model, N_size, path_library3D) +toc=timeit.default_timer() +Run_time = toc - tic +print("Phantom has been built in {} seconds".format(Run_time)) + +# adding normally distributed noise +artifacts_add = ArtifactsClass(phantom_tm) +phantom_noise = artifacts_add.noise(sigma=0.1,noisetype='Gaussian') + +sliceSel = int(0.5*N_size) +#plt.gray() +plt.figure() +plt.subplot(131) +plt.imshow(phantom_noise[sliceSel,:,:],vmin=0, vmax=1.4) +plt.title('3D Phantom, axial view') + +plt.subplot(132) +plt.imshow(phantom_noise[:,sliceSel,:],vmin=0, vmax=1.4) +plt.title('3D Phantom, coronal view') + +plt.subplot(133) +plt.imshow(phantom_noise[:,:,sliceSel],vmin=0, vmax=1.4) +plt.title('3D Phantom, sagittal view') +plt.show() +#%% +print ("____________________Applying regularisers_______________________") +print ("________________________________________________________________") + +print ("#############ROF TV CPU####################") +# set parameters +pars = {'algorithm': ROF_TV, \ + 'input' : phantom_noise,\ + 'regularisation_parameter':0.06,\ + 'number_of_iterations': 1000,\ + 'time_marching_parameter': 0.00025,\ + 'tolerance_constant':0.0} + +tic=timeit.default_timer() +(rof_cpu3D, infcpu) = ROF_TV(pars['input'], + pars['regularisation_parameter'], + pars['number_of_iterations'], + pars['time_marching_parameter'], + pars['tolerance_constant'],'cpu') + +toc=timeit.default_timer() + +Run_time_rof = toc - tic +Qtools = QualityTools(phantom_tm, rof_cpu3D) +RMSE_rof = Qtools.rmse() + +# SSIM measure +Qtools = QualityTools(phantom_tm[sliceSel,:,:]*255, rof_cpu3D[sliceSel,:,:]*235) +win = np.array([gaussian(11, 1.5)]) +win2d = win * (win.T) +ssim_rof = Qtools.ssim(win2d) + +print("ROF-TV (cpu) ____ RMSE: {}, MMSIM: {}, run time: {} sec".format(RMSE_rof,ssim_rof[0],Run_time_rof)) +#%% +print ("#############ROF TV GPU####################") +# set parameters +pars = {'algorithm': ROF_TV, \ + 'input' : phantom_noise,\ + 'regularisation_parameter':0.06,\ + 'number_of_iterations': 8330,\ + 'time_marching_parameter': 0.00025,\ + 'tolerance_constant':0.0} + +tic=timeit.default_timer() +(rof_gpu3D, infogpu) = ROF_TV(pars['input'], + pars['regularisation_parameter'], + pars['number_of_iterations'], + pars['time_marching_parameter'], + pars['tolerance_constant'],'gpu') + +toc=timeit.default_timer() + +Run_time_rof = toc - tic +Qtools = QualityTools(phantom_tm, rof_gpu3D) +RMSE_rof = Qtools.rmse() + +# SSIM measure +Qtools = QualityTools(phantom_tm[sliceSel,:,:]*255, rof_gpu3D[sliceSel,:,:]*235) +win = np.array([gaussian(11, 1.5)]) +win2d = win * (win.T) +ssim_rof = Qtools.ssim(win2d) + +print("ROF-TV (gpu) ____ RMSE: {}, MMSIM: {}, run time: {} sec".format(RMSE_rof,ssim_rof[0],Run_time_rof)) +#%% +print ("#############FGP TV CPU####################") +# set parameters +pars = {'algorithm' : FGP_TV, \ + 'input' : phantom_noise,\ + 'regularisation_parameter':0.06, \ + 'number_of_iterations' : 930 ,\ + 'tolerance_constant':0.0,\ + 'methodTV': 0 ,\ + 'nonneg': 0} + +tic=timeit.default_timer() +(fgp_cpu3D, infoFGP) = FGP_TV(pars['input'], + pars['regularisation_parameter'], + pars['number_of_iterations'], + pars['tolerance_constant'], + pars['methodTV'], + pars['nonneg'],'cpu') +toc=timeit.default_timer() + +Run_time_fgp = toc - tic +Qtools = QualityTools(phantom_tm, fgp_cpu3D) +RMSE_rof = Qtools.rmse() + +# SSIM measure +Qtools = QualityTools(phantom_tm[sliceSel,:,:]*255, fgp_cpu3D[sliceSel,:,:]*235) +win = np.array([gaussian(11, 1.5)]) +win2d = win * (win.T) +ssim_fgp = Qtools.ssim(win2d) + +print("FGP-TV (cpu) ____ RMSE: {}, MMSIM: {}, run time: {} sec".format(RMSE_rof,ssim_fgp[0],Run_time_fgp)) +#%% +print ("#############FGP TV GPU####################") +# set parameters +pars = {'algorithm' : FGP_TV, \ + 'input' : phantom_noise,\ + 'regularisation_parameter':0.06, \ + 'number_of_iterations' :930 ,\ + 'tolerance_constant':0.0,\ + 'methodTV': 0 ,\ + 'nonneg': 0} + +tic=timeit.default_timer() +(fgp_gpu3D,infogpu) = FGP_TV(pars['input'], + pars['regularisation_parameter'], + pars['number_of_iterations'], + pars['tolerance_constant'], + pars['methodTV'], + pars['nonneg'],'gpu') +toc=timeit.default_timer() + +Run_time_fgp = toc - tic +Qtools = QualityTools(phantom_tm, fgp_gpu3D) +RMSE_rof = Qtools.rmse() + +# SSIM measure +Qtools = QualityTools(phantom_tm[sliceSel,:,:]*255, fgp_gpu3D[sliceSel,:,:]*235) +win = np.array([gaussian(11, 1.5)]) +win2d = win * (win.T) +ssim_fgp = Qtools.ssim(win2d) + +print("FGP-TV (gpu) ____ RMSE: {}, MMSIM: {}, run time: {} sec".format(RMSE_rof,ssim_fgp[0],Run_time_fgp)) +#%% +print ("#############SB TV CPU####################") +# set parameters +pars = {'algorithm' : SB_TV, \ + 'input' : phantom_noise,\ + 'regularisation_parameter':0.06, \ + 'number_of_iterations' :225 ,\ + 'tolerance_constant':0.0,\ + 'methodTV': 0} + +tic=timeit.default_timer() +(sb_cpu3D, info_vec_cpu) = SB_TV(pars['input'], + pars['regularisation_parameter'], + pars['number_of_iterations'], + pars['tolerance_constant'], + pars['methodTV'], 'cpu') +toc=timeit.default_timer() + +Run_time = toc - tic +Qtools = QualityTools(phantom_tm, sb_cpu3D) +RMSE = Qtools.rmse() + +# SSIM measure +Qtools = QualityTools(phantom_tm[sliceSel,:,:]*255, sb_cpu3D[sliceSel,:,:]*235) +win = np.array([gaussian(11, 1.5)]) +win2d = win * (win.T) +ssim = Qtools.ssim(win2d) + +print("SB-TV (cpu) ____ RMSE: {}, MMSIM: {}, run time: {} sec".format(RMSE,ssim[0],Run_time)) +#%% +print ("#############SB TV GPU####################") +# set parameters +pars = {'algorithm' : SB_TV, \ + 'input' : phantom_noise,\ + 'regularisation_parameter':0.06, \ + 'number_of_iterations' :225 ,\ + 'tolerance_constant':0.0,\ + 'methodTV': 0} + +tic=timeit.default_timer() +(sb_gpu3D,info_vec_gpu) = SB_TV(pars['input'], + pars['regularisation_parameter'], + pars['number_of_iterations'], + pars['tolerance_constant'], + pars['methodTV'], 'gpu') + +toc=timeit.default_timer() + +Run_time = toc - tic +Qtools = QualityTools(phantom_tm, sb_gpu3D) +RMSE = Qtools.rmse() + +# SSIM measure +Qtools = QualityTools(phantom_tm[sliceSel,:,:]*255, sb_gpu3D[sliceSel,:,:]*235) +win = np.array([gaussian(11, 1.5)]) +win2d = win * (win.T) +ssim = Qtools.ssim(win2d) + +print("SB-TV (gpu) ____ RMSE: {}, MMSIM: {}, run time: {} sec".format(RMSE,ssim[0],Run_time)) +#%% +print ("#############NDF CPU####################") +# set parameters +pars = {'algorithm' : NDF, \ + 'input' : phantom_noise,\ + 'regularisation_parameter':0.06, \ + 'edge_parameter':0.017,\ + 'number_of_iterations' :530 ,\ + 'time_marching_parameter':0.01,\ + 'penalty_type':1,\ + 'tolerance_constant':0.0} + +tic=timeit.default_timer() +(ndf_cpu3D, info_vec_cpu) = NDF(pars['input'], + pars['regularisation_parameter'], + pars['edge_parameter'], + pars['number_of_iterations'], + pars['time_marching_parameter'], + pars['penalty_type'], + pars['tolerance_constant'],'cpu') +toc=timeit.default_timer() + +Run_time = toc - tic +Qtools = QualityTools(phantom_tm, ndf_cpu3D) +RMSE = Qtools.rmse() + +# SSIM measure +Qtools = QualityTools(phantom_tm[sliceSel,:,:]*255, ndf_cpu3D[sliceSel,:,:]*235) +win = np.array([gaussian(11, 1.5)]) +win2d = win * (win.T) +ssim = Qtools.ssim(win2d) + +print("NDF (cpu) ____ RMSE: {}, MMSIM: {}, run time: {} sec".format(RMSE,ssim[0],Run_time)) +#%% +print ("#############NDF GPU####################") +# set parameters +pars = {'algorithm' : NDF, \ + 'input' : phantom_noise,\ + 'regularisation_parameter':0.06, \ + 'edge_parameter':0.017,\ + 'number_of_iterations' :530 ,\ + 'time_marching_parameter':0.01,\ + 'penalty_type':1,\ + 'tolerance_constant':0.0} + +tic=timeit.default_timer() +(ndf_gpu3D,info_vec_gpu) = NDF(pars['input'], + pars['regularisation_parameter'], + pars['edge_parameter'], + pars['number_of_iterations'], + pars['time_marching_parameter'], + pars['penalty_type'], + pars['tolerance_constant'],'gpu') + +toc=timeit.default_timer() + +Run_time = toc - tic +Qtools = QualityTools(phantom_tm, ndf_gpu3D) +RMSE = Qtools.rmse() + +# SSIM measure +Qtools = QualityTools(phantom_tm[sliceSel,:,:]*255, ndf_gpu3D[sliceSel,:,:]*235) +win = np.array([gaussian(11, 1.5)]) +win2d = win * (win.T) +ssim = Qtools.ssim(win2d) + +print("NDF (gpu) ____ RMSE: {}, MMSIM: {}, run time: {} sec".format(RMSE,ssim[0],Run_time)) +#%% +print ("#############Diff4th CPU####################") +# set parameters +pars = {'algorithm' : Diff4th, \ + 'input' : phantom_noise,\ + 'regularisation_parameter':4.5, \ + 'edge_parameter':0.035,\ + 'number_of_iterations' :2425 ,\ + 'time_marching_parameter':0.001,\ + 'tolerance_constant':0.0} + +tic=timeit.default_timer() +(diff4th_cpu3D, info_vec_cpu) = Diff4th(pars['input'], + pars['regularisation_parameter'], + pars['edge_parameter'], + pars['number_of_iterations'], + pars['time_marching_parameter'], + pars['tolerance_constant'],'cpu') +toc=timeit.default_timer() + +Run_time = toc - tic +Qtools = QualityTools(phantom_tm, diff4th_cpu3D) +RMSE = Qtools.rmse() + +# SSIM measure +Qtools = QualityTools(phantom_tm[sliceSel,:,:]*255, diff4th_cpu3D[sliceSel,:,:]*235) +win = np.array([gaussian(11, 1.5)]) +win2d = win * (win.T) +ssim = Qtools.ssim(win2d) + +print("Diff4th (cpu) ____ RMSE: {}, MMSIM: {}, run time: {} sec".format(RMSE,ssim[0],Run_time)) +#%% +print ("#############Diff4th GPU####################") +# set parameters +pars = {'algorithm' : Diff4th, \ + 'input' : phantom_noise,\ + 'regularisation_parameter':4.5, \ + 'edge_parameter':0.035,\ + 'number_of_iterations' :2425 ,\ + 'time_marching_parameter':0.001,\ + 'tolerance_constant':0.0} + +tic=timeit.default_timer() +(diff4th_gpu3D,info_vec_gpu) = Diff4th(pars['input'], + pars['regularisation_parameter'], + pars['edge_parameter'], + pars['number_of_iterations'], + pars['time_marching_parameter'], + pars['tolerance_constant'],'gpu') + +toc=timeit.default_timer() + +Run_time = toc - tic +Qtools = QualityTools(phantom_tm, diff4th_gpu3D) +RMSE = Qtools.rmse() + +# SSIM measure +Qtools = QualityTools(phantom_tm[sliceSel,:,:]*255, diff4th_gpu3D[sliceSel,:,:]*235) +win = np.array([gaussian(11, 1.5)]) +win2d = win * (win.T) +ssim = Qtools.ssim(win2d) + +print("Diff4th (gpu) ____ RMSE: {}, MMSIM: {}, run time: {} sec".format(RMSE,ssim[0],Run_time)) +#%% +print ("#############TGV CPU####################") +# set parameters +pars = {'algorithm' : TGV, \ + 'input' : phantom_noise,\ + 'regularisation_parameter':0.06,\ + 'alpha1':1.0,\ + 'alpha0':2.0,\ + 'number_of_iterations' :1000,\ + 'LipshitzConstant' :12,\ + 'tolerance_constant':0.0} + +tic=timeit.default_timer() +(tgv_cpu3D, info_vec_cpu) = TGV(pars['input'], + pars['regularisation_parameter'], + pars['alpha1'], + pars['alpha0'], + pars['number_of_iterations'], + pars['LipshitzConstant'], + pars['tolerance_constant'],'cpu') +toc=timeit.default_timer() + +Run_time = toc - tic +Qtools = QualityTools(phantom_tm, tgv_cpu3D) +RMSE = Qtools.rmse() + +# SSIM measure +Qtools = QualityTools(phantom_tm[sliceSel,:,:]*255, tgv_cpu3D[sliceSel,:,:]*235) +win = np.array([gaussian(11, 1.5)]) +win2d = win * (win.T) +ssim = Qtools.ssim(win2d) + +print("TGV (cpu) ____ RMSE: {}, MMSIM: {}, run time: {} sec".format(RMSE,ssim[0],Run_time)) +#%% +print ("#############TGV GPU####################") +# set parameters +pars = {'algorithm' : TGV, \ + 'input' : phantom_noise,\ + 'regularisation_parameter':0.06,\ + 'alpha1':1.0,\ + 'alpha0':2.0,\ + 'number_of_iterations' :7845,\ + 'LipshitzConstant' :12,\ + 'tolerance_constant':0.0} + +tic=timeit.default_timer() +(tgv_gpu3D,info_vec_gpu) = TGV(pars['input'], + pars['regularisation_parameter'], + pars['alpha1'], + pars['alpha0'], + pars['number_of_iterations'], + pars['LipshitzConstant'], + pars['tolerance_constant'],'gpu') + +toc=timeit.default_timer() + +Run_time = toc - tic +Qtools = QualityTools(phantom_tm, tgv_gpu3D) +RMSE = Qtools.rmse() + +# SSIM measure +Qtools = QualityTools(phantom_tm[sliceSel,:,:]*255, tgv_gpu3D[sliceSel,:,:]*235) +win = np.array([gaussian(11, 1.5)]) +win2d = win * (win.T) +ssim = Qtools.ssim(win2d) + +print("TGV (gpu) ____ RMSE: {}, MMSIM: {}, run time: {} sec".format(RMSE,ssim[0],Run_time)) +#%% +print ("#############ROF-LLT CPU####################") +# set parameters +pars = {'algorithm' : LLT_ROF, \ + 'input' : phantom_noise,\ + 'regularisation_parameterROF':0.03, \ + 'regularisation_parameterLLT':0.015, \ + 'number_of_iterations' : 1000 ,\ + 'time_marching_parameter' :0.00025 ,\ + 'tolerance_constant':0.0} + +tic=timeit.default_timer() +(rofllt_cpu3D, info_vec_cpu) = LLT_ROF(pars['input'], + pars['regularisation_parameterROF'], + pars['regularisation_parameterLLT'], + pars['number_of_iterations'], + pars['time_marching_parameter'], + pars['tolerance_constant'], 'cpu') +toc=timeit.default_timer() + +Run_time = toc - tic +Qtools = QualityTools(phantom_tm, rofllt_cpu3D) +RMSE = Qtools.rmse() + +# SSIM measure +Qtools = QualityTools(phantom_tm[sliceSel,:,:]*255, rofllt_cpu3D[sliceSel,:,:]*235) +win = np.array([gaussian(11, 1.5)]) +win2d = win * (win.T) +ssim = Qtools.ssim(win2d) + +print("ROF-LLT (cpu) ____ RMSE: {}, MMSIM: {}, run time: {} sec".format(RMSE,ssim[0],Run_time)) +#%% +print ("#############ROF-LLT GPU####################") +# set parameters +pars = {'algorithm' : LLT_ROF, \ + 'input' : phantom_noise,\ + 'regularisation_parameterROF':0.03, \ + 'regularisation_parameterLLT':0.015, \ + 'number_of_iterations' : 8000 ,\ + 'time_marching_parameter' :0.00025 ,\ + 'tolerance_constant':0.0} + +tic=timeit.default_timer() +(rofllt_gpu3D,info_vec_gpu) = LLT_ROF(pars['input'], + pars['regularisation_parameterROF'], + pars['regularisation_parameterLLT'], + pars['number_of_iterations'], + pars['time_marching_parameter'], + pars['tolerance_constant'], 'gpu') +toc=timeit.default_timer() + +Run_time = toc - tic +Qtools = QualityTools(phantom_tm, rofllt_gpu3D) +RMSE = Qtools.rmse() + +# SSIM measure +Qtools = QualityTools(phantom_tm[sliceSel,:,:]*255, rofllt_gpu3D[sliceSel,:,:]*235) +win = np.array([gaussian(11, 1.5)]) +win2d = win * (win.T) +ssim = Qtools.ssim(win2d) + +print("ROF-LLT (gpu) ____ RMSE: {}, MMSIM: {}, run time: {} sec".format(RMSE,ssim[0],Run_time)) diff --git a/demos/demoMatlab_3Ddenoise.m b/demos/demoMatlab_3Ddenoise.m index cf2c88a..3942eea 100644 --- a/demos/demoMatlab_3Ddenoise.m +++ b/demos/demoMatlab_3Ddenoise.m @@ -18,37 +18,43 @@ Ideal3D(:,:,i) = Im; end vol3D(vol3D < 0) = 0; figure; imshow(vol3D(:,:,7), [0 1]); title('Noisy image'); -lambda_reg = 0.03; % regularsation parameter for all methods + %% fprintf('Denoise a volume using the ROF-TV model (CPU) \n'); +lambda_reg = 0.03; % regularsation parameter for all methods tau_rof = 0.0025; % time-marching constant iter_rof = 300; % number of ROF iterations -tic; u_rof = ROF_TV(single(vol3D), lambda_reg, iter_rof, tau_rof); toc; +epsil_tol = 0.0; % tolerance +tic; [u_rof,infovec] = ROF_TV(single(vol3D), lambda_reg, iter_rof, tau_rof, epsil_tol); toc; energyfunc_val_rof = TV_energy(single(u_rof),single(vol3D),lambda_reg, 1); % get energy function value rmse_rof = (RMSE(Ideal3D(:),u_rof(:))); fprintf('%s %f \n', 'RMSE error for ROF is:', rmse_rof); figure; imshow(u_rof(:,:,7), [0 1]); title('ROF-TV denoised volume (CPU)'); %% % fprintf('Denoise a volume using the ROF-TV model (GPU) \n'); +% lambda_reg = 0.03; % regularsation parameter for all methods % tau_rof = 0.0025; % time-marching constant % iter_rof = 300; % number of ROF iterations -% tic; u_rofG = ROF_TV_GPU(single(vol3D), lambda_reg, iter_rof, tau_rof); toc; +% epsil_tol = 0.0; % tolerance +% tic; u_rofG = ROF_TV_GPU(single(vol3D), lambda_reg, iter_rof, tau_rof, epsil_tol); toc; % rmse_rofG = (RMSE(Ideal3D(:),u_rofG(:))); % fprintf('%s %f \n', 'RMSE error for ROF is:', rmse_rofG); % figure; imshow(u_rofG(:,:,7), [0 1]); title('ROF-TV denoised volume (GPU)'); %% fprintf('Denoise a volume using the FGP-TV model (CPU) \n'); +lambda_reg = 0.03; % regularsation parameter for all methods iter_fgp = 300; % number of FGP iterations -epsil_tol = 1.0e-05; % tolerance -tic; u_fgp = FGP_TV(single(vol3D), lambda_reg, iter_fgp, epsil_tol); toc; +epsil_tol = 0.0; % tolerance +tic; [u_fgp,infovec] = FGP_TV(single(vol3D), lambda_reg, iter_fgp, epsil_tol); toc; energyfunc_val_fgp = TV_energy(single(u_fgp),single(vol3D),lambda_reg, 1); % get energy function value rmse_fgp = (RMSE(Ideal3D(:),u_fgp(:))); fprintf('%s %f \n', 'RMSE error for FGP-TV is:', rmse_fgp); figure; imshow(u_fgp(:,:,7), [0 1]); title('FGP-TV denoised volume (CPU)'); %% -% fprintf('Denoise a volume using the FGP-TV model (GPU) \n'); +fprintf('Denoise a volume using the FGP-TV model (GPU) \n'); +% lambda_reg = 0.03; % regularsation parameter for all methods % iter_fgp = 300; % number of FGP iterations -% epsil_tol = 1.0e-05; % tolerance +% epsil_tol = 0.0; % tolerance % tic; u_fgpG = FGP_TV_GPU(single(vol3D), lambda_reg, iter_fgp, epsil_tol); toc; % rmse_fgpG = (RMSE(Ideal3D(:),u_fgpG(:))); % fprintf('%s %f \n', 'RMSE error for FGP-TV is:', rmse_fgpG); @@ -56,8 +62,8 @@ figure; imshow(u_fgp(:,:,7), [0 1]); title('FGP-TV denoised volume (CPU)'); %% fprintf('Denoise a volume using the SB-TV model (CPU) \n'); iter_sb = 150; % number of SB iterations -epsil_tol = 1.0e-05; % tolerance -tic; u_sb = SB_TV(single(vol3D), lambda_reg, iter_sb, epsil_tol); toc; +epsil_tol = 0.0; % tolerance +tic; [u_sb,infovec] = SB_TV(single(vol3D), lambda_reg, iter_sb, epsil_tol); toc; energyfunc_val_sb = TV_energy(single(u_sb),single(vol3D),lambda_reg, 1); % get energy function value rmse_sb = (RMSE(Ideal3D(:),u_sb(:))); fprintf('%s %f \n', 'RMSE error for SB-TV is:', rmse_sb); @@ -65,7 +71,7 @@ figure; imshow(u_sb(:,:,7), [0 1]); title('SB-TV denoised volume (CPU)'); %% % fprintf('Denoise a volume using the SB-TV model (GPU) \n'); % iter_sb = 150; % number of SB iterations -% epsil_tol = 1.0e-05; % tolerance +% epsil_tol = 0.0; % tolerance % tic; u_sbG = SB_TV_GPU(single(vol3D), lambda_reg, iter_sb, epsil_tol); toc; % rmse_sbG = (RMSE(Ideal3D(:),u_sbG(:))); % fprintf('%s %f \n', 'RMSE error for SB-TV is:', rmse_sbG); @@ -76,7 +82,8 @@ lambda_ROF = lambda_reg; % ROF regularisation parameter lambda_LLT = lambda_reg*0.35; % LLT regularisation parameter iter_LLT = 300; % iterations tau_rof_llt = 0.0025; % time-marching constant -tic; u_rof_llt = LLT_ROF(single(vol3D), lambda_ROF, lambda_LLT, iter_LLT, tau_rof_llt); toc; +epsil_tol = 0.0; % tolerance +tic; [u_rof_llt, infovec] = LLT_ROF(single(vol3D), lambda_ROF, lambda_LLT, iter_LLT, tau_rof_llt, epsil_tol); toc; rmse_rof_llt = (RMSE(Ideal3D(:),u_rof_llt(:))); fprintf('%s %f \n', 'RMSE error for ROF-LLT is:', rmse_rof_llt); figure; imshow(u_rof_llt(:,:,7), [0 1]); title('ROF-LLT denoised volume (CPU)'); @@ -86,7 +93,8 @@ figure; imshow(u_rof_llt(:,:,7), [0 1]); title('ROF-LLT denoised volume (CPU)'); % lambda_LLT = lambda_reg*0.35; % LLT regularisation parameter % iter_LLT = 300; % iterations % tau_rof_llt = 0.0025; % time-marching constant -% tic; u_rof_llt_g = LLT_ROF_GPU(single(vol3D), lambda_ROF, lambda_LLT, iter_LLT, tau_rof_llt); toc; +% epsil_tol = 0.0; % tolerance +% tic; u_rof_llt_g = LLT_ROF_GPU(single(vol3D), lambda_ROF, lambda_LLT, iter_LLT, tau_rof_llt, epsil_tol); toc; % rmse_rof_llt = (RMSE(Ideal3D(:),u_rof_llt_g(:))); % fprintf('%s %f \n', 'RMSE error for ROF-LLT is:', rmse_rof_llt); % figure; imshow(u_rof_llt_g(:,:,7), [0 1]); title('ROF-LLT denoised volume (GPU)'); @@ -96,7 +104,8 @@ iter_diff = 300; % number of diffusion iterations lambda_regDiff = 0.025; % regularisation for the diffusivity sigmaPar = 0.015; % edge-preserving parameter tau_param = 0.025; % time-marching constant -tic; u_diff = NonlDiff(single(vol3D), lambda_regDiff, sigmaPar, iter_diff, tau_param, 'Huber'); toc; +epsil_tol = 0.0; % tolerance +tic; [u_diff, infovec] = NonlDiff(single(vol3D), lambda_regDiff, sigmaPar, iter_diff, tau_param, 'Huber', epsil_tol); toc; rmse_diff = (RMSE(Ideal3D(:),u_diff(:))); fprintf('%s %f \n', 'RMSE error for Diffusion is:', rmse_diff); figure; imshow(u_diff(:,:,7), [0 1]); title('Diffusion denoised volume (CPU)'); @@ -106,7 +115,7 @@ figure; imshow(u_diff(:,:,7), [0 1]); title('Diffusion denoised volume (CPU)'); % lambda_regDiff = 0.025; % regularisation for the diffusivity % sigmaPar = 0.015; % edge-preserving parameter % tau_param = 0.025; % time-marching constant -% tic; u_diff_g = NonlDiff_GPU(single(vol3D), lambda_regDiff, sigmaPar, iter_diff, tau_param, 'Huber'); toc; +% tic; u_diff_g = NonlDiff_GPU(single(vol3D), lambda_regDiff, sigmaPar, iter_diff, tau_param, 'Huber', epsil_tol); toc; % rmse_diff = (RMSE(Ideal3D(:),u_diff_g(:))); % fprintf('%s %f \n', 'RMSE error for Diffusion is:', rmse_diff); % figure; imshow(u_diff_g(:,:,7), [0 1]); title('Diffusion denoised volume (GPU)'); @@ -116,7 +125,8 @@ iter_diff = 300; % number of diffusion iterations lambda_regDiff = 3.5; % regularisation for the diffusivity sigmaPar = 0.02; % edge-preserving parameter tau_param = 0.0015; % time-marching constant -tic; u_diff4 = Diffusion_4thO(single(vol3D), lambda_regDiff, sigmaPar, iter_diff, tau_param); toc; +epsil_tol = 0.0; % tolerance +tic; u_diff4 = Diffusion_4thO(single(vol3D), lambda_regDiff, sigmaPar, iter_diff, tau_param, epsil_tol); toc; rmse_diff4 = (RMSE(Ideal3D(:),u_diff4(:))); fprintf('%s %f \n', 'RMSE error for Anis.Diff of 4th order is:', rmse_diff4); figure; imshow(u_diff4(:,:,7), [0 1]); title('Diffusion 4thO denoised volume (CPU)'); @@ -126,7 +136,7 @@ figure; imshow(u_diff4(:,:,7), [0 1]); title('Diffusion 4thO denoised volume (CP % lambda_regDiff = 3.5; % regularisation for the diffusivity % sigmaPar = 0.02; % edge-preserving parameter % tau_param = 0.0015; % time-marching constant -% tic; u_diff4_g = Diffusion_4thO_GPU(single(vol3D), lambda_regDiff, sigmaPar, iter_diff, tau_param); toc; +% tic; u_diff4_g = Diffusion_4thO_GPU(single(vol3D), lambda_regDiff, sigmaPar, iter_diff, tau_param, epsil_tol); toc; % rmse_diff4 = (RMSE(Ideal3D(:),u_diff4_g(:))); % fprintf('%s %f \n', 'RMSE error for Anis.Diff of 4th order is:', rmse_diff4); % figure; imshow(u_diff4_g(:,:,7), [0 1]); title('Diffusion 4thO denoised volume (GPU)'); @@ -135,8 +145,10 @@ fprintf('Denoise using the TGV model (CPU) \n'); lambda_TGV = 0.03; % regularisation parameter alpha1 = 1.0; % parameter to control the first-order term alpha0 = 2.0; % parameter to control the second-order term +L2 = 12.0; % convergence parameter iter_TGV = 500; % number of Primal-Dual iterations for TGV -tic; u_tgv = TGV(single(vol3D), lambda_TGV, alpha1, alpha0, iter_TGV); toc; +epsil_tol = 0.0; % tolerance +tic; u_tgv = TGV(single(vol3D), lambda_TGV, alpha1, alpha0, iter_TGV, L2, epsil_tol); toc; rmseTGV = RMSE(Ideal3D(:),u_tgv(:)); fprintf('%s %f \n', 'RMSE error for TGV is:', rmseTGV); figure; imshow(u_tgv(:,:,3), [0 1]); title('TGV denoised volume (CPU)'); @@ -146,7 +158,7 @@ figure; imshow(u_tgv(:,:,3), [0 1]); title('TGV denoised volume (CPU)'); % alpha1 = 1.0; % parameter to control the first-order term % alpha0 = 2.0; % parameter to control the second-order term % iter_TGV = 500; % number of Primal-Dual iterations for TGV -% tic; u_tgv_gpu = TGV_GPU(single(vol3D), lambda_TGV, alpha1, alpha0, iter_TGV); toc; +% tic; u_tgv_gpu = TGV_GPU(single(vol3D), lambda_TGV, alpha1, alpha0, iter_TGV, L2, epsil_tol); toc; % rmseTGV = RMSE(Ideal3D(:),u_tgv_gpu(:)); % fprintf('%s %f \n', 'RMSE error for TGV is:', rmseTGV); % figure; imshow(u_tgv_gpu(:,:,3), [0 1]); title('TGV denoised volume (GPU)'); @@ -163,7 +175,7 @@ vol3D_ref(vol3D_ref < 0) = 0; % vol3D_ref = zeros(size(Im),'single'); % pass zero reference (dTV -> TV) iter_fgp = 300; % number of FGP iterations -epsil_tol = 1.0e-05; % tolerance +epsil_tol = 0.0; % tolerance eta = 0.2; % Reference image gradient smoothing constant tic; u_fgp_dtv = FGP_dTV(single(vol3D), single(vol3D_ref), lambda_reg, iter_fgp, epsil_tol, eta); toc; figure; imshow(u_fgp_dtv(:,:,7), [0 1]); title('FGP-dTV denoised volume (CPU)'); @@ -179,7 +191,7 @@ vol3D_ref(vol3D_ref < 0) = 0; % vol3D_ref = zeros(size(Im),'single'); % pass zero reference (dTV -> TV) iter_fgp = 300; % number of FGP iterations -epsil_tol = 1.0e-05; % tolerance +epsil_tol = 0.0; % tolerance eta = 0.2; % Reference image gradient smoothing constant tic; u_fgp_dtv_g = FGP_dTV_GPU(single(vol3D), single(vol3D_ref), lambda_reg, iter_fgp, epsil_tol, eta); toc; figure; imshow(u_fgp_dtv_g(:,:,7), [0 1]); title('FGP-dTV denoised volume (GPU)'); diff --git a/demos/demoMatlab_denoise.m b/demos/demoMatlab_denoise.m index 5e92ee1..9d89138 100644 --- a/demos/demoMatlab_denoise.m +++ b/demos/demoMatlab_denoise.m @@ -3,8 +3,8 @@ clear; close all fsep = '/'; 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); +Path2 = sprintf(['data' fsep], 1i); +Path3 = sprintf(['..' fsep 'src' fsep 'Matlab' fsep 'supp'], 1i); addpath(Path1); addpath(Path2); addpath(Path3); @@ -12,13 +12,13 @@ addpath(Path3); Im = double(imread('lena_gray_512.tif'))/255; % loading image u0 = Im + .05*randn(size(Im)); u0(u0 < 0) = 0; figure; imshow(u0, [0 1]); title('Noisy image'); - %% fprintf('Denoise using the ROF-TV model (CPU) \n'); -lambda_reg = 0.017; % regularsation parameter for all methods -tau_rof = 0.0025; % time-marching constant -iter_rof = 1200; % number of ROF iterations -tic; u_rof = ROF_TV(single(u0), lambda_reg, iter_rof, tau_rof); toc; +lambda_reg = 0.03; % regularsation parameter for all methods +iter_rof = 2000; % number of ROF iterations +tau_rof = 0.01; % time-marching constant +epsil_tol = 0.0; % tolerance / 1.0e-06 +tic; [u_rof,infovec] = ROF_TV(single(u0), lambda_reg, iter_rof, tau_rof, epsil_tol); toc; energyfunc_val_rof = TV_energy(single(u_rof),single(u0),lambda_reg, 1); % get energy function value rmseROF = (RMSE(u_rof(:),Im(:))); fprintf('%s %f \n', 'RMSE error for ROF-TV is:', rmseROF); @@ -26,17 +26,15 @@ fprintf('%s %f \n', 'RMSE error for ROF-TV is:', rmseROF); fprintf('%s %f \n', 'MSSIM error for ROF-TV is:', ssimval); figure; imshow(u_rof, [0 1]); title('ROF-TV denoised image (CPU)'); %% -% fprintf('Denoise using the ROF-TV model (GPU) \n'); -% tau_rof = 0.0025; % time-marching constant -% iter_rof = 1200; % number of ROF iterations -% tic; u_rofG = ROF_TV_GPU(single(u0), lambda_reg, iter_rof, tau_rof); toc; -% figure; imshow(u_rofG, [0 1]); title('ROF-TV denoised image (GPU)'); +%fprintf('Denoise using the ROF-TV model (GPU) \n'); +%tic; [u_rofG,infovec] = ROF_TV_GPU(single(u0), lambda_reg, iter_rof, tau_rof, epsil_tol); toc; +%figure; imshow(u_rofG, [0 1]); title('ROF-TV denoised image (GPU)'); %% fprintf('Denoise using the FGP-TV model (CPU) \n'); -lambda_reg = 0.033; -iter_fgp = 300; % number of FGP iterations -epsil_tol = 1.0e-09; % tolerance -tic; u_fgp = FGP_TV(single(u0), lambda_reg, iter_fgp, epsil_tol); toc; +lambda_reg = 0.03; +iter_fgp = 500; % number of FGP iterations +epsil_tol = 0.0; % tolerance +tic; [u_fgp,infovec] = FGP_TV(single(u0), lambda_reg, iter_fgp, epsil_tol); toc; energyfunc_val_fgp = TV_energy(single(u_fgp),single(u0),lambda_reg, 1); % get energy function value rmseFGP = (RMSE(u_fgp(:),Im(:))); fprintf('%s %f \n', 'RMSE error for FGP-TV is:', rmseFGP); @@ -45,15 +43,14 @@ fprintf('%s %f \n', 'MSSIM error for FGP-TV is:', ssimval); figure; imshow(u_fgp, [0 1]); title('FGP-TV denoised image (CPU)'); %% % fprintf('Denoise using the FGP-TV model (GPU) \n'); -% iter_fgp = 300; % number of FGP iterations -% epsil_tol = 1.0e-09; % tolerance % tic; u_fgpG = FGP_TV_GPU(single(u0), lambda_reg, iter_fgp, epsil_tol); toc; % figure; imshow(u_fgpG, [0 1]); title('FGP-TV denoised image (GPU)'); %% fprintf('Denoise using the SB-TV model (CPU) \n'); -iter_sb = 80; % number of SB iterations -epsil_tol = 1.0e-08; % tolerance -tic; u_sb = SB_TV(single(u0), lambda_reg, iter_sb, epsil_tol); toc; +lambda_reg = 0.03; +iter_sb = 200; % number of SB iterations +epsil_tol = 0.0; % tolerance +tic; [u_sb,infovec] = SB_TV(single(u0), lambda_reg, iter_sb, epsil_tol); toc; energyfunc_val_sb = TV_energy(single(u_sb),single(u0),lambda_reg, 1); % get energy function value rmseSB = (RMSE(u_sb(:),Im(:))); fprintf('%s %f \n', 'RMSE error for SB-TV is:', rmseSB); @@ -62,8 +59,6 @@ fprintf('%s %f \n', 'MSSIM error for SB-TV is:', ssimval); figure; imshow(u_sb, [0 1]); title('SB-TV denoised image (CPU)'); %% % fprintf('Denoise using the SB-TV model (GPU) \n'); -% iter_sb = 80; % number of SB iterations -% epsil_tol = 1.0e-06; % tolerance % tic; u_sbG = SB_TV_GPU(single(u0), lambda_reg, iter_sb, epsil_tol); toc; % figure; imshow(u_sbG, [0 1]); title('SB-TV denoised image (GPU)'); %% @@ -72,51 +67,43 @@ iter_diff = 450; % number of diffusion iterations lambda_regDiff = 0.025; % regularisation for the diffusivity sigmaPar = 0.015; % edge-preserving parameter tau_param = 0.02; % time-marching constant -tic; u_diff = NonlDiff(single(u0), lambda_regDiff, sigmaPar, iter_diff, tau_param, 'Huber'); toc; +epsil_tol = 0.0; % tolerance +tic; [u_diff,infovec] = NonlDiff(single(u0), lambda_regDiff, sigmaPar, iter_diff, tau_param, 'Huber', epsil_tol); toc; rmseDiffus = (RMSE(u_diff(:),Im(:))); fprintf('%s %f \n', 'RMSE error for Nonlinear Diffusion is:', rmseDiffus); [ssimval] = ssim(u_diff*255,single(Im)*255); fprintf('%s %f \n', 'MSSIM error for NDF is:', ssimval); figure; imshow(u_diff, [0 1]); title('Diffusion denoised image (CPU)'); %% -% fprintf('Denoise using Nonlinear-Diffusion model (GPU) \n'); -% iter_diff = 450; % number of diffusion iterations -% lambda_regDiff = 0.025; % regularisation for the diffusivity -% sigmaPar = 0.015; % edge-preserving parameter -% tau_param = 0.025; % time-marching constant -% tic; u_diff_g = NonlDiff_GPU(single(u0), lambda_regDiff, sigmaPar, iter_diff, tau_param, 'Huber'); toc; -% figure; imshow(u_diff_g, [0 1]); title('Diffusion denoised image (GPU)'); +%fprintf('Denoise using Nonlinear-Diffusion model (GPU) \n'); +%tic; u_diff_g = NonlDiff_GPU(single(u0), lambda_regDiff, sigmaPar, iter_diff, tau_param, 'Huber', epsil_tol); toc; +%figure; imshow(u_diff_g, [0 1]); title('Diffusion denoised image (GPU)'); %% fprintf('Denoise using the TGV model (CPU) \n'); -lambda_TGV = 0.034; % regularisation parameter +lambda_TGV = 0.035; % regularisation parameter alpha1 = 1.0; % parameter to control the first-order term -alpha0 = 1.0; % parameter to control the second-order term -iter_TGV = 500; % number of Primal-Dual iterations for TGV -tic; u_tgv = TGV(single(u0), lambda_TGV, alpha1, alpha0, iter_TGV); toc; +alpha0 = 2.0; % parameter to control the second-order term +L2 = 12.0; % convergence parameter +iter_TGV = 1200; % number of Primal-Dual iterations for TGV +epsil_tol = 0.0; % tolerance +tic; [u_tgv,infovec] = TGV(single(u0), lambda_TGV, alpha1, alpha0, iter_TGV, L2, epsil_tol); toc; +figure; imshow(u_tgv, [0 1]); title('TGV denoised image (CPU)'); rmseTGV = (RMSE(u_tgv(:),Im(:))); fprintf('%s %f \n', 'RMSE error for TGV is:', rmseTGV); [ssimval] = ssim(u_tgv*255,single(Im)*255); fprintf('%s %f \n', 'MSSIM error for TGV is:', ssimval); -figure; imshow(u_tgv, [0 1]); title('TGV denoised image (CPU)'); %% % fprintf('Denoise using the TGV model (GPU) \n'); -% lambda_TGV = 0.034; % regularisation parameter -% alpha1 = 1.0; % parameter to control the first-order term -% alpha0 = 1.0; % parameter to control the second-order term -% iter_TGV = 500; % number of Primal-Dual iterations for TGV -% tic; u_tgv_gpu = TGV_GPU(single(u0), lambda_TGV, alpha1, alpha0, iter_TGV); toc; -% rmseTGV_gpu = (RMSE(u_tgv_gpu(:),Im(:))); -% fprintf('%s %f \n', 'RMSE error for TGV is:', rmseTGV_gpu); -% [ssimval] = ssim(u_tgv_gpu*255,single(Im)*255); -% fprintf('%s %f \n', 'MSSIM error for TGV is:', ssimval); +% tic; u_tgv_gpu = TGV_GPU(single(u0), lambda_TGV, alpha1, alpha0, iter_TGV, L2, epsil_tol); toc; % figure; imshow(u_tgv_gpu, [0 1]); title('TGV denoised image (GPU)'); %% fprintf('Denoise using the ROF-LLT model (CPU) \n'); -lambda_ROF = 0.016; % ROF regularisation parameter -lambda_LLT = lambda_reg*0.25; % LLT regularisation parameter -iter_LLT = 500; % iterations -tau_rof_llt = 0.0025; % time-marching constant -tic; u_rof_llt = LLT_ROF(single(u0), lambda_ROF, lambda_LLT, iter_LLT, tau_rof_llt); toc; +lambda_ROF = 0.02; % ROF regularisation parameter +lambda_LLT = 0.015; % LLT regularisation parameter +iter_LLT = 2000; % iterations +tau_rof_llt = 0.01; % time-marching constant +epsil_tol = 0.0; % tolerance +tic; [u_rof_llt,infovec] = LLT_ROF(single(u0), lambda_ROF, lambda_LLT, iter_LLT, tau_rof_llt,epsil_tol); toc; rmseROFLLT = (RMSE(u_rof_llt(:),Im(:))); fprintf('%s %f \n', 'RMSE error for TGV is:', rmseROFLLT); [ssimval] = ssim(u_rof_llt*255,single(Im)*255); @@ -124,34 +111,25 @@ fprintf('%s %f \n', 'MSSIM error for ROFLLT is:', ssimval); figure; imshow(u_rof_llt, [0 1]); title('ROF-LLT denoised image (CPU)'); %% % fprintf('Denoise using the ROF-LLT model (GPU) \n'); -% lambda_ROF = 0.016; % ROF regularisation parameter -% lambda_LLT = lambda_reg*0.25; % LLT regularisation parameter -% iter_LLT = 500; % iterations -% tau_rof_llt = 0.0025; % time-marching constant -% tic; u_rof_llt_g = LLT_ROF_GPU(single(u0), lambda_ROF, lambda_LLT, iter_LLT, tau_rof_llt); toc; -% rmseROFLLT_g = (RMSE(u_rof_llt_g(:),Im(:))); -% fprintf('%s %f \n', 'RMSE error for TGV is:', rmseROFLLT_g); +% tic; u_rof_llt_g = LLT_ROF_GPU(single(u0), lambda_ROF, lambda_LLT, iter_LLT, tau_rof_llt, epsil_tol); toc; % figure; imshow(u_rof_llt_g, [0 1]); title('ROF-LLT denoised image (GPU)'); %% fprintf('Denoise using Fourth-order anisotropic diffusion model (CPU) \n'); iter_diff = 800; % number of diffusion iterations -lambda_regDiff = 3.5; % regularisation for the diffusivity -sigmaPar = 0.021; % edge-preserving parameter -tau_param = 0.0015; % time-marching constant -tic; u_diff4 = Diffusion_4thO(single(u0), lambda_regDiff, sigmaPar, iter_diff, tau_param); toc; +lambda_regDiff = 3; % regularisation for the diffusivity +sigmaPar = 0.03; % edge-preserving parameter +tau_param = 0.0025; % time-marching constant +epsil_tol = 0.0; % tolerance +tic; [u_diff4,infovec] = Diffusion_4thO(single(u0), lambda_regDiff, sigmaPar, iter_diff, tau_param, epsil_tol); toc; rmseDiffHO = (RMSE(u_diff4(:),Im(:))); fprintf('%s %f \n', 'RMSE error for Fourth-order anisotropic diffusion is:', rmseDiffHO); [ssimval] = ssim(u_diff4*255,single(Im)*255); fprintf('%s %f \n', 'MSSIM error for DIFF4th is:', ssimval); figure; imshow(u_diff4, [0 1]); title('Diffusion 4thO denoised image (CPU)'); %% -% fprintf('Denoise using Fourth-order anisotropic diffusion model (GPU) \n'); -% iter_diff = 800; % number of diffusion iterations -% lambda_regDiff = 3.5; % regularisation for the diffusivity -% sigmaPar = 0.02; % edge-preserving parameter -% tau_param = 0.0015; % time-marching constant -% tic; u_diff4_g = Diffusion_4thO_GPU(single(u0), lambda_regDiff, sigmaPar, iter_diff, tau_param); toc; -% figure; imshow(u_diff4_g, [0 1]); title('Diffusion 4thO denoised image (GPU)'); +%fprintf('Denoise using Fourth-order anisotropic diffusion model (GPU) \n'); +%tic; u_diff4_g = Diffusion_4thO_GPU(single(u0), lambda_regDiff, sigmaPar, iter_diff, tau_param); toc; +%figure; imshow(u_diff4_g, [0 1]); title('Diffusion 4thO denoised image (GPU)'); %% fprintf('Weights pre-calculation for Non-local TV (takes time on CPU) \n'); SearchingWindow = 7; @@ -177,10 +155,11 @@ fprintf('Denoise using the FGP-dTV model (CPU) \n'); u_ref = Im + .01*randn(size(Im)); u_ref(u_ref < 0) = 0; % u_ref = zeros(size(Im),'single'); % pass zero reference (dTV -> TV) +lambda_reg = 0.04; iter_fgp = 1000; % number of FGP iterations -epsil_tol = 1.0e-06; % tolerance +epsil_tol = 0.0; % tolerance eta = 0.2; % Reference image gradient smoothing constant -tic; u_fgp_dtv = FGP_dTV(single(u0), single(u_ref), lambda_reg, iter_fgp, epsil_tol, eta); toc; +tic; [u_fgp_dtv,infovec] = FGP_dTV(single(u0), single(u_ref), lambda_reg, iter_fgp, epsil_tol, eta); toc; rmse_dTV= (RMSE(u_fgp_dtv(:),Im(:))); fprintf('%s %f \n', 'RMSE error for Directional Total Variation (dTV) is:', rmse_dTV); figure; imshow(u_fgp_dtv, [0 1]); title('FGP-dTV denoised image (CPU)'); diff --git a/demos/demo_cpu_regularisers.py b/demos/demo_cpu_regularisers.py index d34607a..8655623 100644 --- a/demos/demo_cpu_regularisers.py +++ b/demos/demo_cpu_regularisers.py @@ -30,7 +30,7 @@ def printParametersToString(pars): txt += '\n' return txt ############################################################################### -#%% + filename = os.path.join( "data" ,"lena_gray_512.tif") # read image @@ -85,15 +85,17 @@ imgplot = plt.imshow(u0,cmap="gray") pars = {'algorithm': ROF_TV, \ 'input' : u0,\ 'regularisation_parameter':0.02,\ - 'number_of_iterations': 2000,\ - 'time_marching_parameter': 0.0025 - } + 'number_of_iterations': 4000,\ + 'time_marching_parameter': 0.001,\ + 'tolerance_constant':1e-06} + print ("#############ROF TV CPU####################") start_time = timeit.default_timer() -rof_cpu = ROF_TV(pars['input'], +(rof_cpu,info_vec_cpu) = ROF_TV(pars['input'], pars['regularisation_parameter'], pars['number_of_iterations'], - pars['time_marching_parameter'],'cpu') + pars['time_marching_parameter'], + pars['tolerance_constant'], 'cpu') Qtools = QualityTools(Im, rof_cpu) pars['rmse'] = Qtools.rmse() @@ -126,24 +128,20 @@ imgplot = plt.imshow(u0,cmap="gray") # set parameters pars = {'algorithm' : FGP_TV, \ 'input' : u0,\ - 'regularisation_parameter':0.04, \ - 'number_of_iterations' :2000 ,\ + 'regularisation_parameter':0.02, \ + 'number_of_iterations' :400 ,\ 'tolerance_constant':1e-06,\ 'methodTV': 0 ,\ - 'nonneg': 0 ,\ - 'printingOut': 0 - } + 'nonneg': 0} print ("#############FGP TV CPU####################") start_time = timeit.default_timer() -fgp_cpu = FGP_TV(pars['input'], +(fgp_cpu,info_vec_cpu) = FGP_TV(pars['input'], pars['regularisation_parameter'], pars['number_of_iterations'], pars['tolerance_constant'], pars['methodTV'], - pars['nonneg'], - pars['printingOut'],'cpu') - + pars['nonneg'],'cpu') Qtools = QualityTools(Im, fgp_cpu) pars['rmse'] = Qtools.rmse() @@ -176,21 +174,18 @@ imgplot = plt.imshow(u0,cmap="gray") # set parameters pars = {'algorithm' : SB_TV, \ 'input' : u0,\ - 'regularisation_parameter':0.04, \ - 'number_of_iterations' :150 ,\ + 'regularisation_parameter':0.02, \ + 'number_of_iterations' :250 ,\ 'tolerance_constant':1e-06,\ - 'methodTV': 0 ,\ - 'printingOut': 0 - } + 'methodTV': 0} print ("#############SB TV CPU####################") start_time = timeit.default_timer() -sb_cpu = SB_TV(pars['input'], +(sb_cpu,info_vec_cpu) = SB_TV(pars['input'], pars['regularisation_parameter'], pars['number_of_iterations'], pars['tolerance_constant'], - pars['methodTV'], - pars['printingOut'],'cpu') + pars['methodTV'],'cpu') Qtools = QualityTools(Im, sb_cpu) pars['rmse'] = Qtools.rmse() @@ -210,37 +205,35 @@ plt.title('{}'.format('CPU results')) #%% print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") -print ("_____Total Generalised Variation (2D)______") +print ("______________LLT- ROF (2D)________________") print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") ## plot fig = plt.figure() -plt.suptitle('Performance of TGV regulariser using the CPU') +plt.suptitle('Performance of LLT-ROF regulariser using the CPU') a=fig.add_subplot(1,2,1) a.set_title('Noisy Image') imgplot = plt.imshow(u0,cmap="gray") # set parameters -pars = {'algorithm' : TGV, \ +pars = {'algorithm' : LLT_ROF, \ 'input' : u0,\ - 'regularisation_parameter':0.04, \ - 'alpha1':1.0,\ - 'alpha0':2.0,\ - 'number_of_iterations' :1350 ,\ - 'LipshitzConstant' :12 ,\ - } + 'regularisation_parameterROF':0.01, \ + 'regularisation_parameterLLT':0.0085, \ + 'number_of_iterations' :6000 ,\ + 'time_marching_parameter' :0.001 ,\ + 'tolerance_constant':1e-06} -print ("#############TGV CPU####################") +print ("#############LLT- ROF CPU####################") start_time = timeit.default_timer() -tgv_cpu = TGV(pars['input'], - pars['regularisation_parameter'], - pars['alpha1'], - pars['alpha0'], +(lltrof_cpu,info_vec_cpu) = LLT_ROF(pars['input'], + pars['regularisation_parameterROF'], + pars['regularisation_parameterLLT'], pars['number_of_iterations'], - pars['LipshitzConstant'],'cpu') - - -Qtools = QualityTools(Im, tgv_cpu) + pars['time_marching_parameter'], + pars['tolerance_constant'], 'cpu') + +Qtools = QualityTools(Im, lltrof_cpu) pars['rmse'] = Qtools.rmse() txtstr = printParametersToString(pars) @@ -253,40 +246,42 @@ 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(tgv_cpu, cmap="gray") +imgplot = plt.imshow(lltrof_cpu, cmap="gray") plt.title('{}'.format('CPU results')) #%% - print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") -print ("______________LLT- ROF (2D)________________") +print ("_____Total Generalised Variation (2D)______") print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") ## plot fig = plt.figure() -plt.suptitle('Performance of LLT-ROF regulariser using the CPU') +plt.suptitle('Performance of TGV regulariser using the CPU') a=fig.add_subplot(1,2,1) a.set_title('Noisy Image') imgplot = plt.imshow(u0,cmap="gray") # set parameters -pars = {'algorithm' : LLT_ROF, \ +pars = {'algorithm' : TGV, \ 'input' : u0,\ - 'regularisation_parameterROF':0.04, \ - 'regularisation_parameterLLT':0.01, \ - 'number_of_iterations' :500 ,\ - 'time_marching_parameter' :0.0025 ,\ - } - -print ("#############LLT- ROF CPU####################") + 'regularisation_parameter':0.02, \ + 'alpha1':1.0,\ + 'alpha0':2.0,\ + 'number_of_iterations' :1000 ,\ + 'LipshitzConstant' :12 ,\ + 'tolerance_constant':1e-06} + +print ("#############TGV CPU####################") start_time = timeit.default_timer() -lltrof_cpu = LLT_ROF(pars['input'], - pars['regularisation_parameterROF'], - pars['regularisation_parameterLLT'], +(tgv_cpu,info_vec_cpu) = TGV(pars['input'], + pars['regularisation_parameter'], + pars['alpha1'], + pars['alpha0'], pars['number_of_iterations'], - pars['time_marching_parameter'],'cpu') + pars['LipshitzConstant'], + pars['tolerance_constant'], 'cpu') -Qtools = QualityTools(Im, lltrof_cpu) +Qtools = QualityTools(Im, tgv_cpu) pars['rmse'] = Qtools.rmse() txtstr = printParametersToString(pars) @@ -299,12 +294,10 @@ 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(lltrof_cpu, cmap="gray") +imgplot = plt.imshow(tgv_cpu, cmap="gray") plt.title('{}'.format('CPU results')) #%% - - print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") print ("________________NDF (2D)___________________") print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") @@ -319,21 +312,22 @@ imgplot = plt.imshow(u0,cmap="gray") # set parameters pars = {'algorithm' : NDF, \ 'input' : u0,\ - 'regularisation_parameter':0.025, \ - 'edge_parameter':0.015,\ - 'number_of_iterations' :500 ,\ - 'time_marching_parameter':0.025,\ - 'penalty_type':1 - } + 'regularisation_parameter':0.02, \ + 'edge_parameter':0.017,\ + 'number_of_iterations' :1500 ,\ + 'time_marching_parameter':0.01,\ + 'penalty_type':1,\ + 'tolerance_constant':1e-06} print ("#############NDF CPU################") start_time = timeit.default_timer() -ndf_cpu = NDF(pars['input'], +(ndf_cpu,info_vec_cpu) = NDF(pars['input'], pars['regularisation_parameter'], pars['edge_parameter'], pars['number_of_iterations'], pars['time_marching_parameter'], - pars['penalty_type'],'cpu') + pars['penalty_type'], + pars['tolerance_constant'],'cpu') Qtools = QualityTools(Im, ndf_cpu) pars['rmse'] = Qtools.rmse() @@ -366,19 +360,20 @@ imgplot = plt.imshow(u0,cmap="gray") # set parameters pars = {'algorithm' : Diff4th, \ 'input' : u0,\ - 'regularisation_parameter':3.5, \ + 'regularisation_parameter':0.8, \ 'edge_parameter':0.02,\ - 'number_of_iterations' :500 ,\ - 'time_marching_parameter':0.0015 - } + 'number_of_iterations' :5500 ,\ + 'time_marching_parameter':0.001,\ + 'tolerance_constant':1e-06} print ("#############Diff4th CPU################") start_time = timeit.default_timer() -diff4_cpu = Diff4th(pars['input'], +(diff4_cpu,info_vec_cpu) = Diff4th(pars['input'], pars['regularisation_parameter'], pars['edge_parameter'], pars['number_of_iterations'], - pars['time_marching_parameter'],'cpu') + pars['time_marching_parameter'], + pars['tolerance_constant'],'cpu') Qtools = QualityTools(Im, diff4_cpu) pars['rmse'] = Qtools.rmse() @@ -484,26 +479,23 @@ imgplot = plt.imshow(u0,cmap="gray") pars = {'algorithm' : FGP_dTV, \ 'input' : u0,\ 'refdata' : u_ref,\ - 'regularisation_parameter':0.04, \ - 'number_of_iterations' :2000 ,\ + 'regularisation_parameter':0.02, \ + 'number_of_iterations' :500 ,\ 'tolerance_constant':1e-06,\ 'eta_const':0.2,\ 'methodTV': 0 ,\ - 'nonneg': 0 ,\ - 'printingOut': 0 - } + 'nonneg': 0} print ("#############FGP dTV CPU####################") start_time = timeit.default_timer() -fgp_dtv_cpu = FGP_dTV(pars['input'], +(fgp_dtv_cpu,info_vec_cpu) = FGP_dTV(pars['input'], pars['refdata'], pars['regularisation_parameter'], pars['number_of_iterations'], pars['tolerance_constant'], pars['eta_const'], pars['methodTV'], - pars['nonneg'], - pars['printingOut'],'cpu') + pars['nonneg'],'cpu') Qtools = QualityTools(Im, fgp_dtv_cpu) pars['rmse'] = Qtools.rmse() diff --git a/demos/demo_cpu_regularisers3D.py b/demos/demo_cpu_regularisers3D.py index fd6c545..fc1e8e6 100644 --- a/demos/demo_cpu_regularisers3D.py +++ b/demos/demo_cpu_regularisers3D.py @@ -29,8 +29,9 @@ def printParametersToString(pars): txt += '\n' return txt ############################################################################### -#%% -filename = os.path.join( "data" ,"lena_gray_512.tif") + +# filename = os.path.join( "data" ,"lena_gray_512.tif") +filename = "/home/algol/Documents/DEV/CCPi-Regularisation-Toolkit/test/lena_gray_512.tif" # read image Im = plt.imread(filename) @@ -94,16 +95,18 @@ imgplot = plt.imshow(noisyVol[10,:,:],cmap="gray") # set parameters pars = {'algorithm': ROF_TV, \ 'input' : noisyVol,\ - 'regularisation_parameter':0.04,\ - 'number_of_iterations': 500,\ - 'time_marching_parameter': 0.0025 - } + 'regularisation_parameter':0.02,\ + 'number_of_iterations': 7000,\ + 'time_marching_parameter': 0.0007,\ + 'tolerance_constant':1e-06} + print ("#############ROF TV CPU####################") start_time = timeit.default_timer() -rof_cpu3D = ROF_TV(pars['input'], +(rof_cpu3D, info_vec_cpu) = ROF_TV(pars['input'], pars['regularisation_parameter'], pars['number_of_iterations'], - pars['time_marching_parameter'],'cpu') + pars['time_marching_parameter'], + pars['tolerance_constant'], 'cpu') Qtools = QualityTools(idealVol, rof_cpu3D) pars['rmse'] = Qtools.rmse() @@ -136,23 +139,20 @@ imgplot = plt.imshow(noisyVol[10,:,:],cmap="gray") # set parameters pars = {'algorithm' : FGP_TV, \ 'input' : noisyVol,\ - 'regularisation_parameter':0.04, \ - 'number_of_iterations' :300 ,\ - 'tolerance_constant':0.00001,\ + 'regularisation_parameter':0.02, \ + 'number_of_iterations' :1000 ,\ + 'tolerance_constant':1e-06,\ 'methodTV': 0 ,\ - 'nonneg': 0 ,\ - 'printingOut': 0 - } - -print ("#############FGP TV CPU####################") + 'nonneg': 0} + +print ("#############FGP TV GPU####################") start_time = timeit.default_timer() -fgp_cpu3D = FGP_TV(pars['input'], +(fgp_cpu3D, info_vec_cpu) = FGP_TV(pars['input'], pars['regularisation_parameter'], pars['number_of_iterations'], pars['tolerance_constant'], pars['methodTV'], - pars['nonneg'], - pars['printingOut'],'cpu') + pars['nonneg'], 'cpu') Qtools = QualityTools(idealVol, fgp_cpu3D) pars['rmse'] = Qtools.rmse() @@ -185,22 +185,18 @@ imgplot = plt.imshow(noisyVol[10,:,:],cmap="gray") # set parameters pars = {'algorithm' : SB_TV, \ 'input' : noisyVol,\ - 'regularisation_parameter':0.04, \ - 'number_of_iterations' :150 ,\ - 'tolerance_constant':0.00001,\ - 'methodTV': 0 ,\ - 'printingOut': 0 - } + 'regularisation_parameter':0.02, \ + 'number_of_iterations' :250 ,\ + 'tolerance_constant':1e-06,\ + 'methodTV': 0} print ("#############SB TV CPU####################") start_time = timeit.default_timer() -sb_cpu3D = SB_TV(pars['input'], +(sb_cpu3D, info_vec_cpu) = SB_TV(pars['input'], pars['regularisation_parameter'], pars['number_of_iterations'], pars['tolerance_constant'], - pars['methodTV'], - pars['printingOut'],'cpu') - + pars['methodTV'],'cpu') Qtools = QualityTools(idealVol, sb_cpu3D) pars['rmse'] = Qtools.rmse() @@ -234,19 +230,20 @@ imgplot = plt.imshow(noisyVol[10,:,:],cmap="gray") # set parameters pars = {'algorithm' : LLT_ROF, \ 'input' : noisyVol,\ - 'regularisation_parameterROF':0.04, \ - 'regularisation_parameterLLT':0.015, \ - 'number_of_iterations' :300 ,\ - 'time_marching_parameter' :0.0025 ,\ - } + 'regularisation_parameterROF':0.01, \ + 'regularisation_parameterLLT':0.008, \ + 'number_of_iterations' :500 ,\ + 'time_marching_parameter' :0.001 ,\ + 'tolerance_constant':1e-06} print ("#############LLT ROF CPU####################") start_time = timeit.default_timer() -lltrof_cpu3D = LLT_ROF(pars['input'], +(lltrof_cpu3D,info_vec_cpu) = LLT_ROF(pars['input'], pars['regularisation_parameterROF'], pars['regularisation_parameterLLT'], pars['number_of_iterations'], - pars['time_marching_parameter'],'cpu') + pars['time_marching_parameter'], + pars['tolerance_constant'], 'cpu') Qtools = QualityTools(idealVol, lltrof_cpu3D) @@ -280,22 +277,23 @@ imgplot = plt.imshow(noisyVol[10,:,:],cmap="gray") # set parameters pars = {'algorithm' : TGV, \ 'input' : noisyVol,\ - 'regularisation_parameter':0.04, \ + 'regularisation_parameter':0.02, \ 'alpha1':1.0,\ 'alpha0':2.0,\ - 'number_of_iterations' :250 ,\ + 'number_of_iterations' :500 ,\ 'LipshitzConstant' :12 ,\ - } + 'tolerance_constant':1e-06} print ("#############TGV CPU####################") start_time = timeit.default_timer() -tgv_cpu3D = TGV(pars['input'], +(tgv_cpu3D,info_vec_cpu) = TGV(pars['input'], pars['regularisation_parameter'], pars['alpha1'], pars['alpha0'], pars['number_of_iterations'], - pars['LipshitzConstant'],'cpu') - + pars['LipshitzConstant'], + pars['tolerance_constant'],'cpu') + Qtools = QualityTools(idealVol, tgv_cpu3D) pars['rmse'] = Qtools.rmse() @@ -328,21 +326,22 @@ imgplot = plt.imshow(noisyVol[10,:,:],cmap="gray") # set parameters pars = {'algorithm' : NDF, \ 'input' : noisyVol,\ - 'regularisation_parameter':0.025, \ + 'regularisation_parameter':0.02, \ 'edge_parameter':0.015,\ - 'number_of_iterations' :500 ,\ - 'time_marching_parameter':0.025,\ - 'penalty_type': 1 - } - + 'number_of_iterations' :700 ,\ + 'time_marching_parameter':0.01,\ + 'penalty_type': 1,\ + 'tolerance_constant':1e-06} + print ("#############NDF CPU################") start_time = timeit.default_timer() -ndf_cpu3D = NDF(pars['input'], +(ndf_cpu3D,info_vec_cpu) = NDF(pars['input'], pars['regularisation_parameter'], pars['edge_parameter'], pars['number_of_iterations'], pars['time_marching_parameter'], - pars['penalty_type']) + pars['penalty_type'], + pars['tolerance_constant'], 'cpu') Qtools = QualityTools(idealVol, ndf_cpu3D) @@ -376,19 +375,20 @@ imgplot = plt.imshow(noisyVol[10,:,:],cmap="gray") # set parameters pars = {'algorithm' : Diff4th, \ 'input' : noisyVol,\ - 'regularisation_parameter':3.5, \ + 'regularisation_parameter':0.8, \ 'edge_parameter':0.02,\ - 'number_of_iterations' :300 ,\ - 'time_marching_parameter':0.0015 - } - + 'number_of_iterations' :500 ,\ + 'time_marching_parameter':0.001,\ + 'tolerance_constant':1e-06} + print ("#############Diff4th CPU################") start_time = timeit.default_timer() -diff4th_cpu3D = Diff4th(pars['input'], +(diff4th_cpu3D,info_vec_cpu) = Diff4th(pars['input'], pars['regularisation_parameter'], pars['edge_parameter'], pars['number_of_iterations'], - pars['time_marching_parameter']) + pars['time_marching_parameter'], + pars['tolerance_constant'],'cpu') Qtools = QualityTools(idealVol, diff4th_cpu3D) @@ -423,26 +423,23 @@ imgplot = plt.imshow(noisyVol[10,:,:],cmap="gray") pars = {'algorithm' : FGP_dTV,\ 'input' : noisyVol,\ 'refdata' : noisyRef,\ - 'regularisation_parameter':0.04, \ - 'number_of_iterations' :300 ,\ - 'tolerance_constant':0.00001,\ + 'regularisation_parameter':0.02, \ + 'number_of_iterations' :500 ,\ + 'tolerance_constant':1e-06,\ 'eta_const':0.2,\ 'methodTV': 0 ,\ - 'nonneg': 0 ,\ - 'printingOut': 0 - } + 'nonneg': 0} print ("#############FGP dTV CPU####################") start_time = timeit.default_timer() -fgp_dTV_cpu3D = FGP_dTV(pars['input'], +(fgp_dTV_cpu3D,info_vec_cpu) = FGP_dTV(pars['input'], pars['refdata'], pars['regularisation_parameter'], pars['number_of_iterations'], pars['tolerance_constant'], pars['eta_const'], pars['methodTV'], - pars['nonneg'], - pars['printingOut'],'cpu') + pars['nonneg'],'cpu') Qtools = QualityTools(idealVol, fgp_dTV_cpu3D) diff --git a/demos/demo_cpu_vs_gpu_regularisers.py b/demos/demo_cpu_vs_gpu_regularisers.py index e1eb91f..21e3899 100644 --- a/demos/demo_cpu_vs_gpu_regularisers.py +++ b/demos/demo_cpu_vs_gpu_regularisers.py @@ -66,16 +66,18 @@ imgplot = plt.imshow(u0,cmap="gray") # set parameters pars = {'algorithm': ROF_TV, \ 'input' : u0,\ - 'regularisation_parameter':0.04,\ - 'number_of_iterations': 4500,\ - 'time_marching_parameter': 0.00002 - } + 'regularisation_parameter':0.02,\ + 'number_of_iterations': 1000,\ + 'time_marching_parameter': 0.001,\ + 'tolerance_constant':0.0} + print ("#############ROF TV CPU####################") start_time = timeit.default_timer() -rof_cpu = ROF_TV(pars['input'], +(rof_cpu, infocpu) = ROF_TV(pars['input'], pars['regularisation_parameter'], pars['number_of_iterations'], - pars['time_marching_parameter'],'cpu') + pars['time_marching_parameter'], + pars['tolerance_constant'],'cpu') Qtools = QualityTools(Im, rof_cpu) pars['rmse'] = Qtools.rmse() @@ -95,10 +97,11 @@ plt.title('{}'.format('CPU results')) print ("##############ROF TV GPU##################") start_time = timeit.default_timer() -rof_gpu = ROF_TV(pars['input'], - pars['regularisation_parameter'], - pars['number_of_iterations'], - pars['time_marching_parameter'],'gpu') +(rof_gpu, infgpu) = ROF_TV(pars['input'], + pars['regularisation_parameter'], + pars['number_of_iterations'], + pars['time_marching_parameter'], + pars['tolerance_constant'],'gpu') Qtools = QualityTools(Im, rof_gpu) pars['rmse'] = Qtools.rmse() @@ -130,7 +133,6 @@ if (diff_im.sum() > 1): print ("Arrays do not match!") else: print ("Arrays match") - #%% print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") print ("____________FGP-TV bench___________________") @@ -146,24 +148,20 @@ imgplot = plt.imshow(u0,cmap="gray") # set parameters pars = {'algorithm' : FGP_TV, \ 'input' : u0,\ - 'regularisation_parameter':0.04, \ - 'number_of_iterations' :1200 ,\ - 'tolerance_constant':0.00001,\ + 'regularisation_parameter':0.02, \ + 'number_of_iterations' :400 ,\ + 'tolerance_constant':0.0,\ 'methodTV': 0 ,\ - 'nonneg': 0 ,\ - 'printingOut': 0 - } + 'nonneg': 0} print ("#############FGP TV CPU####################") start_time = timeit.default_timer() -fgp_cpu = FGP_TV(pars['input'], +(fgp_cpu,infocpu) = FGP_TV(pars['input'], pars['regularisation_parameter'], pars['number_of_iterations'], pars['tolerance_constant'], pars['methodTV'], - pars['nonneg'], - pars['printingOut'],'cpu') - + pars['nonneg'],'cpu') Qtools = QualityTools(Im, fgp_cpu) pars['rmse'] = Qtools.rmse() @@ -184,13 +182,12 @@ plt.title('{}'.format('CPU results')) print ("##############FGP TV GPU##################") start_time = timeit.default_timer() -fgp_gpu = FGP_TV(pars['input'], +(fgp_gpu,infogpu) = FGP_TV(pars['input'], pars['regularisation_parameter'], pars['number_of_iterations'], pars['tolerance_constant'], pars['methodTV'], - pars['nonneg'], - pars['printingOut'],'gpu') + pars['nonneg'],'gpu') Qtools = QualityTools(Im, fgp_gpu) pars['rmse'] = Qtools.rmse() @@ -238,21 +235,18 @@ imgplot = plt.imshow(u0,cmap="gray") # set parameters pars = {'algorithm' : SB_TV, \ 'input' : u0,\ - 'regularisation_parameter':0.04, \ - 'number_of_iterations' :150 ,\ - 'tolerance_constant':1e-05,\ - 'methodTV': 0 ,\ - 'printingOut': 0 - } + 'regularisation_parameter':0.02, \ + 'number_of_iterations' :250 ,\ + 'tolerance_constant':0.0,\ + 'methodTV': 0} print ("#############SB-TV CPU####################") start_time = timeit.default_timer() -sb_cpu = SB_TV(pars['input'], +(sb_cpu, info_vec_cpu) = SB_TV(pars['input'], pars['regularisation_parameter'], pars['number_of_iterations'], pars['tolerance_constant'], - pars['methodTV'], - pars['printingOut'],'cpu') + pars['methodTV'], 'cpu') Qtools = QualityTools(Im, sb_cpu) @@ -274,12 +268,11 @@ plt.title('{}'.format('CPU results')) print ("##############SB TV GPU##################") start_time = timeit.default_timer() -sb_gpu = SB_TV(pars['input'], +(sb_gpu, info_vec_gpu) = SB_TV(pars['input'], pars['regularisation_parameter'], pars['number_of_iterations'], pars['tolerance_constant'], - pars['methodTV'], - pars['printingOut'],'gpu') + pars['methodTV'], 'gpu') Qtools = QualityTools(Im, sb_gpu) pars['rmse'] = Qtools.rmse() @@ -311,36 +304,36 @@ else: print ("Arrays match") #%% print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") -print ("____________TGV bench___________________") +print ("____________LLT-ROF bench___________________") print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") ## plot fig = plt.figure() -plt.suptitle('Comparison of TGV regulariser using CPU and GPU implementations') +plt.suptitle('Comparison of LLT-ROF regulariser using CPU and GPU implementations') a=fig.add_subplot(1,4,1) a.set_title('Noisy Image') imgplot = plt.imshow(u0,cmap="gray") # set parameters -pars = {'algorithm' : TGV, \ +pars = {'algorithm' : LLT_ROF, \ 'input' : u0,\ - 'regularisation_parameter':0.04, \ - 'alpha1':1.0,\ - 'alpha0':2.0,\ - 'number_of_iterations' :400 ,\ - 'LipshitzConstant' :12 ,\ - } - -print ("#############TGV CPU####################") + 'regularisation_parameterROF':0.01, \ + 'regularisation_parameterLLT':0.0085, \ + 'number_of_iterations' : 1000 ,\ + 'time_marching_parameter' :0.0001 ,\ + 'tolerance_constant':0.0} + + +print ("#############LLT- ROF CPU####################") start_time = timeit.default_timer() -tgv_cpu = TGV(pars['input'], - pars['regularisation_parameter'], - pars['alpha1'], - pars['alpha0'], +(lltrof_cpu, info_vec_cpu) = LLT_ROF(pars['input'], + pars['regularisation_parameterROF'], + pars['regularisation_parameterLLT'], pars['number_of_iterations'], - pars['LipshitzConstant'],'cpu') - -Qtools = QualityTools(Im, tgv_cpu) + pars['time_marching_parameter'], + pars['tolerance_constant'], 'cpu') + +Qtools = QualityTools(Im, lltrof_cpu) pars['rmse'] = Qtools.rmse() txtstr = printParametersToString(pars) @@ -353,21 +346,22 @@ 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(tgv_cpu, cmap="gray") +imgplot = plt.imshow(lltrof_cpu, cmap="gray") plt.title('{}'.format('CPU results')) -print ("##############TGV GPU##################") +print ("#############LLT- ROF GPU####################") start_time = timeit.default_timer() -tgv_gpu = TGV(pars['input'], - pars['regularisation_parameter'], - pars['alpha1'], - pars['alpha0'], +(lltrof_gpu, info_vec_gpu) = LLT_ROF(pars['input'], + pars['regularisation_parameterROF'], + pars['regularisation_parameterLLT'], pars['number_of_iterations'], - pars['LipshitzConstant'],'gpu') - -Qtools = QualityTools(Im, tgv_gpu) + pars['time_marching_parameter'], + pars['tolerance_constant'], 'gpu') + +Qtools = QualityTools(Im, lltrof_gpu) pars['rmse'] = Qtools.rmse() -pars['algorithm'] = TGV + +pars['algorithm'] = LLT_ROF txtstr = printParametersToString(pars) txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time) print (txtstr) @@ -378,13 +372,13 @@ 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(tgv_gpu, cmap="gray") +imgplot = plt.imshow(lltrof_gpu, cmap="gray") plt.title('{}'.format('GPU results')) print ("--------Compare the results--------") tolerance = 1e-05 -diff_im = np.zeros(np.shape(tgv_gpu)) -diff_im = abs(tgv_cpu - tgv_gpu) +diff_im = np.zeros(np.shape(lltrof_gpu)) +diff_im = abs(lltrof_cpu - lltrof_gpu) diff_im[diff_im > tolerance] = 1 a=fig.add_subplot(1,4,4) imgplot = plt.imshow(diff_im, vmin=0, vmax=1, cmap="gray") @@ -395,34 +389,37 @@ else: print ("Arrays match") #%% print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") -print ("____________LLT-ROF bench___________________") +print ("____________TGV bench___________________") print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") ## plot fig = plt.figure() -plt.suptitle('Comparison of LLT-ROF regulariser using CPU and GPU implementations') +plt.suptitle('Comparison of TGV regulariser using CPU and GPU implementations') a=fig.add_subplot(1,4,1) a.set_title('Noisy Image') imgplot = plt.imshow(u0,cmap="gray") # set parameters -pars = {'algorithm' : LLT_ROF, \ +pars = {'algorithm' : TGV, \ 'input' : u0,\ - 'regularisation_parameterROF':0.04, \ - 'regularisation_parameterLLT':0.01, \ - 'number_of_iterations' :4500 ,\ - 'time_marching_parameter' :0.00002 ,\ - } + 'regularisation_parameter':0.02, \ + 'alpha1':1.0,\ + 'alpha0':2.0,\ + 'number_of_iterations' :1000 ,\ + 'LipshitzConstant' :12 ,\ + 'tolerance_constant':0.0} -print ("#############LLT- ROF CPU####################") +print ("#############TGV CPU####################") start_time = timeit.default_timer() -lltrof_cpu = LLT_ROF(pars['input'], - pars['regularisation_parameterROF'], - pars['regularisation_parameterLLT'], +(tgv_cpu, info_vec_cpu) = TGV(pars['input'], + pars['regularisation_parameter'], + pars['alpha1'], + pars['alpha0'], pars['number_of_iterations'], - pars['time_marching_parameter'],'cpu') - -Qtools = QualityTools(Im, lltrof_cpu) + pars['LipshitzConstant'], + pars['tolerance_constant'],'cpu') + +Qtools = QualityTools(Im, tgv_cpu) pars['rmse'] = Qtools.rmse() txtstr = printParametersToString(pars) @@ -435,21 +432,22 @@ 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(lltrof_cpu, cmap="gray") +imgplot = plt.imshow(tgv_cpu, cmap="gray") plt.title('{}'.format('CPU results')) -print ("#############LLT- ROF GPU####################") +print ("##############TGV GPU##################") start_time = timeit.default_timer() -lltrof_gpu = LLT_ROF(pars['input'], - pars['regularisation_parameterROF'], - pars['regularisation_parameterLLT'], +(tgv_gpu, info_vec_gpu) = TGV(pars['input'], + pars['regularisation_parameter'], + pars['alpha1'], + pars['alpha0'], pars['number_of_iterations'], - pars['time_marching_parameter'],'gpu') - -Qtools = QualityTools(Im, lltrof_gpu) + pars['LipshitzConstant'], + pars['tolerance_constant'],'gpu') + +Qtools = QualityTools(Im, tgv_gpu) pars['rmse'] = Qtools.rmse() - -pars['algorithm'] = LLT_ROF +pars['algorithm'] = TGV txtstr = printParametersToString(pars) txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time) print (txtstr) @@ -460,13 +458,13 @@ 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(lltrof_gpu, cmap="gray") +imgplot = plt.imshow(tgv_gpu, cmap="gray") plt.title('{}'.format('GPU results')) print ("--------Compare the results--------") tolerance = 1e-05 -diff_im = np.zeros(np.shape(lltrof_gpu)) -diff_im = abs(lltrof_cpu - lltrof_gpu) +diff_im = np.zeros(np.shape(tgv_gpu)) +diff_im = abs(tgv_cpu - tgv_gpu) diff_im[diff_im > tolerance] = 1 a=fig.add_subplot(1,4,4) imgplot = plt.imshow(diff_im, vmin=0, vmax=1, cmap="gray") @@ -490,21 +488,22 @@ imgplot = plt.imshow(u0,cmap="gray") # set parameters pars = {'algorithm' : NDF, \ 'input' : u0,\ - 'regularisation_parameter':0.06, \ - 'edge_parameter':0.04,\ - 'number_of_iterations' :1000 ,\ - 'time_marching_parameter':0.025,\ - 'penalty_type': 1 - } - + 'regularisation_parameter':0.02, \ + 'edge_parameter':0.017,\ + 'number_of_iterations' :1500 ,\ + 'time_marching_parameter':0.01,\ + 'penalty_type':1,\ + 'tolerance_constant':0.0} + print ("#############NDF CPU####################") start_time = timeit.default_timer() -ndf_cpu = NDF(pars['input'], +(ndf_cpu,info_vec_cpu) = NDF(pars['input'], pars['regularisation_parameter'], pars['edge_parameter'], pars['number_of_iterations'], pars['time_marching_parameter'], - pars['penalty_type'],'cpu') + pars['penalty_type'], + pars['tolerance_constant'],'cpu') Qtools = QualityTools(Im, ndf_cpu) pars['rmse'] = Qtools.rmse() @@ -525,12 +524,13 @@ plt.title('{}'.format('CPU results')) print ("##############NDF GPU##################") start_time = timeit.default_timer() -ndf_gpu = NDF(pars['input'], +(ndf_gpu,info_vec_gpu) = NDF(pars['input'], pars['regularisation_parameter'], pars['edge_parameter'], pars['number_of_iterations'], pars['time_marching_parameter'], - pars['penalty_type'],'gpu') + pars['penalty_type'], + pars['tolerance_constant'],'gpu') Qtools = QualityTools(Im, ndf_gpu) pars['rmse'] = Qtools.rmse() @@ -576,19 +576,20 @@ imgplot = plt.imshow(u0,cmap="gray") # set parameters pars = {'algorithm' : Diff4th, \ 'input' : u0,\ - 'regularisation_parameter':3.5, \ + 'regularisation_parameter':0.8, \ 'edge_parameter':0.02,\ - 'number_of_iterations' :500 ,\ - 'time_marching_parameter':0.001 - } + 'number_of_iterations' :1500 ,\ + 'time_marching_parameter':0.001,\ + 'tolerance_constant':0.0} print ("#############Diff4th CPU####################") start_time = timeit.default_timer() -diff4th_cpu = Diff4th(pars['input'], +(diff4th_cpu,info_vec_cpu) = Diff4th(pars['input'], pars['regularisation_parameter'], pars['edge_parameter'], pars['number_of_iterations'], - pars['time_marching_parameter'],'cpu') + pars['time_marching_parameter'], + pars['tolerance_constant'],'cpu') Qtools = QualityTools(Im, diff4th_cpu) pars['rmse'] = Qtools.rmse() @@ -608,11 +609,12 @@ plt.title('{}'.format('CPU results')) print ("##############Diff4th GPU##################") start_time = timeit.default_timer() -diff4th_gpu = Diff4th(pars['input'], +(diff4th_gpu,info_vec_gpu) = Diff4th(pars['input'], pars['regularisation_parameter'], pars['edge_parameter'], pars['number_of_iterations'], - pars['time_marching_parameter'], 'gpu') + pars['time_marching_parameter'], + pars['tolerance_constant'],'gpu') Qtools = QualityTools(Im, diff4th_gpu) pars['rmse'] = Qtools.rmse() @@ -659,26 +661,23 @@ imgplot = plt.imshow(u0,cmap="gray") pars = {'algorithm' : FGP_dTV, \ 'input' : u0,\ 'refdata' : u_ref,\ - 'regularisation_parameter':0.04, \ - 'number_of_iterations' :1000 ,\ - 'tolerance_constant':1e-07,\ + 'regularisation_parameter':0.02, \ + 'number_of_iterations' :500 ,\ + 'tolerance_constant':0.0,\ 'eta_const':0.2,\ 'methodTV': 0 ,\ - 'nonneg': 0 ,\ - 'printingOut': 0 - } + 'nonneg': 0} print ("#############FGP dTV CPU####################") start_time = timeit.default_timer() -fgp_dtv_cpu = FGP_dTV(pars['input'], +(fgp_dtv_cpu,info_vec_cpu) = FGP_dTV(pars['input'], pars['refdata'], pars['regularisation_parameter'], pars['number_of_iterations'], pars['tolerance_constant'], pars['eta_const'], pars['methodTV'], - pars['nonneg'], - pars['printingOut'],'cpu') + pars['nonneg'],'cpu') Qtools = QualityTools(Im, fgp_dtv_cpu) pars['rmse'] = Qtools.rmse() @@ -699,15 +698,14 @@ plt.title('{}'.format('CPU results')) print ("##############FGP dTV GPU##################") start_time = timeit.default_timer() -fgp_dtv_gpu = FGP_dTV(pars['input'], +(fgp_dtv_gpu,info_vec_gpu) = FGP_dTV(pars['input'], pars['refdata'], pars['regularisation_parameter'], pars['number_of_iterations'], pars['tolerance_constant'], pars['eta_const'], pars['methodTV'], - pars['nonneg'], - pars['printingOut'],'gpu') + pars['nonneg'],'gpu') Qtools = QualityTools(Im, fgp_dtv_gpu) pars['rmse'] = Qtools.rmse() pars['algorithm'] = FGP_dTV diff --git a/demos/demo_gpu_regularisers.py b/demos/demo_gpu_regularisers.py index 89bb948..3efcfce 100644 --- a/demos/demo_gpu_regularisers.py +++ b/demos/demo_gpu_regularisers.py @@ -83,16 +83,18 @@ imgplot = plt.imshow(u0,cmap="gray") # set parameters pars = {'algorithm': ROF_TV, \ 'input' : u0,\ - 'regularisation_parameter':0.04,\ - 'number_of_iterations': 1200,\ - 'time_marching_parameter': 0.0025 - } + 'regularisation_parameter':0.02,\ + 'number_of_iterations': 4000,\ + 'time_marching_parameter': 0.001,\ + 'tolerance_constant':1e-06} + print ("##############ROF TV GPU##################") start_time = timeit.default_timer() -rof_gpu = ROF_TV(pars['input'], - pars['regularisation_parameter'], - pars['number_of_iterations'], - pars['time_marching_parameter'],'gpu') +(rof_gpu, info_vec_gpu) = ROF_TV(pars['input'], + pars['regularisation_parameter'], + pars['number_of_iterations'], + pars['time_marching_parameter'], + pars['tolerance_constant'], 'gpu') Qtools = QualityTools(Im, rof_gpu) pars['rmse'] = Qtools.rmse() @@ -125,23 +127,20 @@ imgplot = plt.imshow(u0,cmap="gray") # set parameters pars = {'algorithm' : FGP_TV, \ 'input' : u0,\ - 'regularisation_parameter':0.04, \ - 'number_of_iterations' :1200 ,\ + 'regularisation_parameter':0.02, \ + 'number_of_iterations' :400 ,\ 'tolerance_constant':1e-06,\ 'methodTV': 0 ,\ - 'nonneg': 0 ,\ - 'printingOut': 0 - } + 'nonneg': 0} print ("##############FGP TV GPU##################") start_time = timeit.default_timer() -fgp_gpu = FGP_TV(pars['input'], +(fgp_gpu, info_vec_gpu) = FGP_TV(pars['input'], pars['regularisation_parameter'], pars['number_of_iterations'], pars['tolerance_constant'], pars['methodTV'], - pars['nonneg'], - pars['printingOut'],'gpu') + pars['nonneg'],'gpu') Qtools = QualityTools(Im, fgp_gpu) pars['rmse'] = Qtools.rmse() pars['algorithm'] = FGP_TV @@ -157,7 +156,6 @@ a.text(0.15, 0.25, txtstr, transform=a.transAxes, fontsize=14, verticalalignment='top', bbox=props) imgplot = plt.imshow(fgp_gpu, cmap="gray") plt.title('{}'.format('GPU results')) - #%% print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") print ("____________SB-TV regulariser______________") @@ -173,21 +171,18 @@ imgplot = plt.imshow(u0,cmap="gray") # set parameters pars = {'algorithm' : SB_TV, \ 'input' : u0,\ - 'regularisation_parameter':0.04, \ - 'number_of_iterations' :150 ,\ + 'regularisation_parameter':0.02, \ + 'number_of_iterations' :250 ,\ 'tolerance_constant':1e-06,\ - 'methodTV': 0 ,\ - 'printingOut': 0 - } + 'methodTV': 0} print ("##############SB TV GPU##################") start_time = timeit.default_timer() -sb_gpu = SB_TV(pars['input'], +(sb_gpu, info_vec_gpu) = SB_TV(pars['input'], pars['regularisation_parameter'], pars['number_of_iterations'], pars['tolerance_constant'], - pars['methodTV'], - pars['printingOut'],'gpu') + pars['methodTV'], 'gpu') Qtools = QualityTools(Im, sb_gpu) pars['rmse'] = Qtools.rmse() @@ -207,36 +202,35 @@ plt.title('{}'.format('GPU results')) #%% print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") -print ("_____Total Generalised Variation (2D)______") +print ("______________LLT- ROF (2D)________________") print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") ## plot fig = plt.figure() -plt.suptitle('Performance of TGV regulariser using the GPU') +plt.suptitle('Performance of LLT-ROF regulariser using the GPU') a=fig.add_subplot(1,2,1) a.set_title('Noisy Image') imgplot = plt.imshow(u0,cmap="gray") # set parameters -pars = {'algorithm' : TGV, \ +pars = {'algorithm' : LLT_ROF, \ 'input' : u0,\ - 'regularisation_parameter':0.04, \ - 'alpha1':1.0,\ - 'alpha0':2.0,\ - 'number_of_iterations' :1250 ,\ - 'LipshitzConstant' :12 ,\ - } + 'regularisation_parameterROF':0.01, \ + 'regularisation_parameterLLT':0.0085, \ + 'number_of_iterations' : 6000 ,\ + 'time_marching_parameter' :0.001 ,\ + 'tolerance_constant':1e-06} -print ("#############TGV CPU####################") +print ("#############LLT- ROF GPU####################") start_time = timeit.default_timer() -tgv_gpu = TGV(pars['input'], - pars['regularisation_parameter'], - pars['alpha1'], - pars['alpha0'], +(lltrof_gpu, info_vec_gpu) = LLT_ROF(pars['input'], + pars['regularisation_parameterROF'], + pars['regularisation_parameterLLT'], pars['number_of_iterations'], - pars['LipshitzConstant'],'gpu') - -Qtools = QualityTools(Im, tgv_gpu) + pars['time_marching_parameter'], + pars['tolerance_constant'], 'gpu') + +Qtools = QualityTools(Im, lltrof_gpu) pars['rmse'] = Qtools.rmse() txtstr = printParametersToString(pars) txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time) @@ -248,40 +242,43 @@ 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(tgv_gpu, cmap="gray") +imgplot = plt.imshow(lltrof_gpu, cmap="gray") plt.title('{}'.format('GPU results')) #%% print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") -print ("______________LLT- ROF (2D)________________") +print ("_____Total Generalised Variation (2D)______") print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") ## plot fig = plt.figure() -plt.suptitle('Performance of LLT-ROF regulariser using the GPU') +plt.suptitle('Performance of TGV regulariser using the GPU') a=fig.add_subplot(1,2,1) a.set_title('Noisy Image') imgplot = plt.imshow(u0,cmap="gray") # set parameters -pars = {'algorithm' : LLT_ROF, \ +pars = {'algorithm' : TGV, \ 'input' : u0,\ - 'regularisation_parameterROF':0.04, \ - 'regularisation_parameterLLT':0.01, \ - 'number_of_iterations' :500 ,\ - 'time_marching_parameter' :0.0025 ,\ - } + 'regularisation_parameter':0.02, \ + 'alpha1':1.0,\ + 'alpha0':2.0,\ + 'number_of_iterations' :1000 ,\ + 'LipshitzConstant' :12 ,\ + 'tolerance_constant':1e-06} -print ("#############LLT- ROF GPU####################") +print ("#############TGV CPU####################") start_time = timeit.default_timer() -lltrof_gpu = LLT_ROF(pars['input'], - pars['regularisation_parameterROF'], - pars['regularisation_parameterLLT'], +(tgv_gpu, info_vec_gpu) = TGV(pars['input'], + pars['regularisation_parameter'], + pars['alpha1'], + pars['alpha0'], pars['number_of_iterations'], - pars['time_marching_parameter'],'gpu') - -Qtools = QualityTools(Im, lltrof_gpu) + pars['LipshitzConstant'], + pars['tolerance_constant'],'gpu') + +Qtools = QualityTools(Im, tgv_gpu) pars['rmse'] = Qtools.rmse() txtstr = printParametersToString(pars) txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time) @@ -293,7 +290,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(lltrof_gpu, cmap="gray") +imgplot = plt.imshow(tgv_gpu, cmap="gray") plt.title('{}'.format('GPU results')) #%% @@ -311,21 +308,22 @@ imgplot = plt.imshow(u0,cmap="gray") # set parameters pars = {'algorithm' : NDF, \ 'input' : u0,\ - 'regularisation_parameter':0.025, \ - 'edge_parameter':0.015,\ - 'number_of_iterations' :500 ,\ - 'time_marching_parameter':0.025,\ - 'penalty_type': 1 - } + 'regularisation_parameter':0.02, \ + 'edge_parameter':0.017,\ + 'number_of_iterations' :1500 ,\ + 'time_marching_parameter':0.01,\ + 'penalty_type':1,\ + 'tolerance_constant':1e-06} print ("##############NDF GPU##################") start_time = timeit.default_timer() -ndf_gpu = NDF(pars['input'], +(ndf_gpu,info_vec_gpu) = NDF(pars['input'], pars['regularisation_parameter'], pars['edge_parameter'], pars['number_of_iterations'], pars['time_marching_parameter'], - pars['penalty_type'],'gpu') + pars['penalty_type'], + pars['tolerance_constant'],'gpu') Qtools = QualityTools(Im, ndf_gpu) pars['rmse'] = Qtools.rmse() @@ -358,19 +356,20 @@ imgplot = plt.imshow(u0,cmap="gray") # set parameters pars = {'algorithm' : Diff4th, \ 'input' : u0,\ - 'regularisation_parameter':3.5, \ + 'regularisation_parameter':0.8, \ 'edge_parameter':0.02,\ - 'number_of_iterations' :500 ,\ - 'time_marching_parameter':0.0015 - } + 'number_of_iterations' :5500 ,\ + 'time_marching_parameter':0.001,\ + 'tolerance_constant':1e-06} print ("#############DIFF4th CPU################") start_time = timeit.default_timer() -diff4_gpu = Diff4th(pars['input'], +(diff4_gpu,info_vec_gpu) = Diff4th(pars['input'], pars['regularisation_parameter'], pars['edge_parameter'], pars['number_of_iterations'], - pars['time_marching_parameter'],'gpu') + pars['time_marching_parameter'], + pars['tolerance_constant'],'gpu') Qtools = QualityTools(Im, diff4_gpu) pars['algorithm'] = Diff4th @@ -474,26 +473,23 @@ imgplot = plt.imshow(u0,cmap="gray") pars = {'algorithm' : FGP_dTV, \ 'input' : u0,\ 'refdata' : u_ref,\ - 'regularisation_parameter':0.04, \ - 'number_of_iterations' :2000 ,\ + 'regularisation_parameter':0.02, \ + 'number_of_iterations' :500 ,\ 'tolerance_constant':1e-06,\ 'eta_const':0.2,\ 'methodTV': 0 ,\ - 'nonneg': 0 ,\ - 'printingOut': 0 - } + 'nonneg': 0} print ("##############FGP dTV GPU##################") start_time = timeit.default_timer() -fgp_dtv_gpu = FGP_dTV(pars['input'], +(fgp_dtv_gpu,info_vec_gpu) = FGP_dTV(pars['input'], pars['refdata'], pars['regularisation_parameter'], pars['number_of_iterations'], pars['tolerance_constant'], pars['eta_const'], pars['methodTV'], - pars['nonneg'], - pars['printingOut'],'gpu') + pars['nonneg'],'gpu') Qtools = QualityTools(Im, fgp_dtv_gpu) pars['rmse'] = Qtools.rmse() diff --git a/demos/demo_gpu_regularisers3D.py b/demos/demo_gpu_regularisers3D.py index be16921..ccf9694 100644 --- a/demos/demo_gpu_regularisers3D.py +++ b/demos/demo_gpu_regularisers3D.py @@ -101,16 +101,18 @@ imgplot = plt.imshow(noisyVol[10,:,:],cmap="gray") # set parameters pars = {'algorithm': ROF_TV, \ 'input' : noisyVol,\ - 'regularisation_parameter':0.04,\ - 'number_of_iterations': 500,\ - 'time_marching_parameter': 0.0025 - } -print ("#############ROF TV GPU####################") + 'regularisation_parameter':0.02,\ + 'number_of_iterations': 7000,\ + 'time_marching_parameter': 0.0007,\ + 'tolerance_constant':1e-06} + +print ("#############ROF TV CPU####################") start_time = timeit.default_timer() -rof_gpu3D = ROF_TV(pars['input'], +(rof_gpu3D, info_vec_gpu) = ROF_TV(pars['input'], pars['regularisation_parameter'], pars['number_of_iterations'], - pars['time_marching_parameter'],'gpu') + pars['time_marching_parameter'], + pars['tolerance_constant'], 'gpu') Qtools = QualityTools(idealVol, rof_gpu3D) pars['rmse'] = Qtools.rmse() @@ -141,23 +143,20 @@ imgplot = plt.imshow(noisyVol[10,:,:],cmap="gray") # set parameters pars = {'algorithm' : FGP_TV, \ 'input' : noisyVol,\ - 'regularisation_parameter':0.04, \ - 'number_of_iterations' :300 ,\ - 'tolerance_constant':0.00001,\ + 'regularisation_parameter':0.02, \ + 'number_of_iterations' :1000 ,\ + 'tolerance_constant':1e-06,\ 'methodTV': 0 ,\ - 'nonneg': 0 ,\ - 'printingOut': 0 - } + 'nonneg': 0} print ("#############FGP TV GPU####################") start_time = timeit.default_timer() -fgp_gpu3D = FGP_TV(pars['input'], +(fgp_gpu3D, info_vec_gpu) = FGP_TV(pars['input'], pars['regularisation_parameter'], pars['number_of_iterations'], pars['tolerance_constant'], pars['methodTV'], - pars['nonneg'], - pars['printingOut'],'gpu') + pars['nonneg'], 'gpu') Qtools = QualityTools(idealVol, fgp_gpu3D) pars['rmse'] = Qtools.rmse() @@ -189,21 +188,18 @@ imgplot = plt.imshow(noisyVol[10,:,:],cmap="gray") # set parameters pars = {'algorithm' : SB_TV, \ 'input' : noisyVol,\ - 'regularisation_parameter':0.04, \ - 'number_of_iterations' :100 ,\ - 'tolerance_constant':1e-05,\ - 'methodTV': 0 ,\ - 'printingOut': 0 - } + 'regularisation_parameter':0.02, \ + 'number_of_iterations' :300 ,\ + 'tolerance_constant':1e-06,\ + 'methodTV': 0 } print ("#############SB TV GPU####################") start_time = timeit.default_timer() -sb_gpu3D = SB_TV(pars['input'], +(sb_gpu3D, info_vec_gpu) = SB_TV(pars['input'], pars['regularisation_parameter'], pars['number_of_iterations'], pars['tolerance_constant'], - pars['methodTV'], - pars['printingOut'],'gpu') + pars['methodTV'],'gpu') Qtools = QualityTools(idealVol, sb_gpu3D) pars['rmse'] = Qtools.rmse() @@ -235,19 +231,20 @@ imgplot = plt.imshow(noisyVol[10,:,:],cmap="gray") # set parameters pars = {'algorithm' : LLT_ROF, \ 'input' : noisyVol,\ - 'regularisation_parameterROF':0.04, \ - 'regularisation_parameterLLT':0.015, \ - 'number_of_iterations' :300 ,\ - 'time_marching_parameter' :0.0025 ,\ - } + 'regularisation_parameterROF':0.01, \ + 'regularisation_parameterLLT':0.008, \ + 'number_of_iterations' : 500 ,\ + 'time_marching_parameter' :0.001 ,\ + 'tolerance_constant':1e-06} print ("#############LLT ROF CPU####################") start_time = timeit.default_timer() -lltrof_gpu3D = LLT_ROF(pars['input'], +(lltrof_gpu3D,info_vec_gpu) = LLT_ROF(pars['input'], pars['regularisation_parameterROF'], pars['regularisation_parameterLLT'], pars['number_of_iterations'], - pars['time_marching_parameter'],'gpu') + pars['time_marching_parameter'], + pars['tolerance_constant'], 'gpu') Qtools = QualityTools(idealVol, lltrof_gpu3D) pars['rmse'] = Qtools.rmse() @@ -280,21 +277,22 @@ imgplot = plt.imshow(noisyVol[10,:,:],cmap="gray") # set parameters pars = {'algorithm' : TGV, \ 'input' : noisyVol,\ - 'regularisation_parameter':0.04, \ + 'regularisation_parameter':0.02, \ 'alpha1':1.0,\ 'alpha0':2.0,\ - 'number_of_iterations' :600 ,\ + 'number_of_iterations' :500 ,\ 'LipshitzConstant' :12 ,\ - } + 'tolerance_constant':1e-06} print ("#############TGV GPU####################") start_time = timeit.default_timer() -tgv_gpu3D = TGV(pars['input'], +(tgv_gpu3D,info_vec_gpu) = TGV(pars['input'], pars['regularisation_parameter'], pars['alpha1'], pars['alpha0'], pars['number_of_iterations'], - pars['LipshitzConstant'],'gpu') + pars['LipshitzConstant'], + pars['tolerance_constant'],'gpu') Qtools = QualityTools(idealVol, tgv_gpu3D) pars['rmse'] = Qtools.rmse() @@ -325,21 +323,23 @@ imgplot = plt.imshow(noisyVol[10,:,:],cmap="gray") # set parameters pars = {'algorithm' : NDF, \ 'input' : noisyVol,\ - 'regularisation_parameter':0.025, \ + 'regularisation_parameter':0.02, \ 'edge_parameter':0.015,\ - 'number_of_iterations' :500 ,\ - 'time_marching_parameter':0.025,\ - 'penalty_type': 1 - } + 'number_of_iterations' :700 ,\ + 'time_marching_parameter':0.01,\ + 'penalty_type': 1,\ + 'tolerance_constant':1e-06} + print ("#############NDF GPU####################") start_time = timeit.default_timer() -ndf_gpu3D = NDF(pars['input'], +(ndf_gpu3D,info_vec_gpu) = NDF(pars['input'], pars['regularisation_parameter'], pars['edge_parameter'], pars['number_of_iterations'], pars['time_marching_parameter'], - pars['penalty_type'],'gpu') + pars['penalty_type'], + pars['tolerance_constant'], 'gpu') Qtools = QualityTools(idealVol, ndf_gpu3D) pars['rmse'] = Qtools.rmse() @@ -371,19 +371,20 @@ imgplot = plt.imshow(noisyVol[10,:,:],cmap="gray") # set parameters pars = {'algorithm' : Diff4th, \ 'input' : noisyVol,\ - 'regularisation_parameter':3.5, \ + 'regularisation_parameter':0.8, \ 'edge_parameter':0.02,\ - 'number_of_iterations' :300 ,\ - 'time_marching_parameter':0.0015 - } + 'number_of_iterations' :500 ,\ + 'time_marching_parameter':0.001,\ + 'tolerance_constant':1e-06} print ("#############DIFF4th CPU################") start_time = timeit.default_timer() -diff4_gpu3D = Diff4th(pars['input'], +(diff4_gpu3D,info_vec_gpu) = Diff4th(pars['input'], pars['regularisation_parameter'], pars['edge_parameter'], pars['number_of_iterations'], - pars['time_marching_parameter'],'gpu') + pars['time_marching_parameter'], + pars['tolerance_constant'],'gpu') Qtools = QualityTools(idealVol, diff4_gpu3D) pars['rmse'] = Qtools.rmse() @@ -413,29 +414,27 @@ a.set_title('Noisy Image') imgplot = plt.imshow(noisyVol[10,:,:],cmap="gray") # set parameters -pars = {'algorithm' : FGP_dTV, \ +pars = {'algorithm' : FGP_dTV,\ 'input' : noisyVol,\ 'refdata' : noisyRef,\ - 'regularisation_parameter':0.04, \ - 'number_of_iterations' :300 ,\ - 'tolerance_constant':0.00001,\ + 'regularisation_parameter':0.02, + 'number_of_iterations' :500 ,\ + 'tolerance_constant':1e-06,\ 'eta_const':0.2,\ 'methodTV': 0 ,\ - 'nonneg': 0 ,\ - 'printingOut': 0 - } + 'nonneg': 0} print ("#############FGP TV GPU####################") start_time = timeit.default_timer() -fgp_dTV_gpu3D = FGP_dTV(pars['input'], +(fgp_dTV_gpu3D,info_vec_gpu) = FGP_dTV(pars['input'], pars['refdata'], pars['regularisation_parameter'], pars['number_of_iterations'], pars['tolerance_constant'], pars['eta_const'], pars['methodTV'], - pars['nonneg'], - pars['printingOut'],'gpu') + pars['nonneg'],'gpu') + Qtools = QualityTools(idealVol, fgp_dTV_gpu3D) pars['rmse'] = Qtools.rmse() |