From 5a12eb57a4965dea7241093c1fe7bf50dfac9659 Mon Sep 17 00:00:00 2001 From: dkazanc Date: Tue, 5 Mar 2019 18:38:29 +0000 Subject: software X denoise demo --- demos/SoftwareX_supp/Demo_VolumeDenoise.py | 121 +++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 demos/SoftwareX_supp/Demo_VolumeDenoise.py (limited to 'demos') diff --git a/demos/SoftwareX_supp/Demo_VolumeDenoise.py b/demos/SoftwareX_supp/Demo_VolumeDenoise.py new file mode 100644 index 0000000..2387e94 --- /dev/null +++ b/demos/SoftwareX_supp/Demo_VolumeDenoise.py @@ -0,0 +1,121 @@ +#!/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, NDF, Diff4th +#%% +print ("Building 3D phantom using TomoPhantom software") +tic=timeit.default_timer() +model = 9 # select a model number from the library +N_size = 256 # 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 ("#############ROF TV CPU####################") +# set parameters +pars = {'algorithm': ROF_TV, \ + 'input' : phantom_noise,\ + 'regularisation_parameter':0.04,\ + 'number_of_iterations': 100,\ + 'time_marching_parameter': 0.0025 + } + +tic=timeit.default_timer() +rof_cpu3D = ROF_TV(pars['input'], + pars['regularisation_parameter'], + pars['number_of_iterations'], + pars['time_marching_parameter'],'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[128,:,:]*255, rof_cpu3D[128,:,:]*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.04,\ + 'number_of_iterations': 600,\ + 'time_marching_parameter': 0.0025 + } + +tic=timeit.default_timer() +rof_gpu3D = ROF_TV(pars['input'], + pars['regularisation_parameter'], + pars['number_of_iterations'], + pars['time_marching_parameter'],'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[128,:,:]*255, rof_gpu3D[128,:,:]*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)) + +#%% + -- cgit v1.2.3 From 39baef90c4b209090f006e5308653cb0a3348c4e Mon Sep 17 00:00:00 2001 From: dkazanc Date: Wed, 6 Mar 2019 15:13:58 +0000 Subject: tol work --- demos/SoftwareX_supp/Demo_VolumeDenoise.py | 62 +++++++++++++++++++++++++++++- demos/demoMatlab_denoise.m | 12 +++--- demos/demo_cpu_regularisers.py | 16 ++++---- 3 files changed, 75 insertions(+), 15 deletions(-) (limited to 'demos') diff --git a/demos/SoftwareX_supp/Demo_VolumeDenoise.py b/demos/SoftwareX_supp/Demo_VolumeDenoise.py index 2387e94..17cdf4d 100644 --- a/demos/SoftwareX_supp/Demo_VolumeDenoise.py +++ b/demos/SoftwareX_supp/Demo_VolumeDenoise.py @@ -60,13 +60,14 @@ 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.04,\ - 'number_of_iterations': 100,\ + 'number_of_iterations': 600,\ 'time_marching_parameter': 0.0025 } @@ -116,6 +117,65 @@ 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.04,\ + 'number_of_iterations': 300,\ + 'time_marching_parameter': 0.0025,\ + 'tolerance_constant':1e-05,\ + } + +tic=timeit.default_timer() +fgp_cpu3D = FGP_TV(pars['input'], + pars['regularisation_parameter'], + pars['number_of_iterations'], + pars['time_marching_parameter'],'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[128,:,:]*255, fgp_cpu3D[128,:,:]*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.04,\ + 'number_of_iterations': 300,\ + 'time_marching_parameter': 0.0025,\ + 'tolerance_constant':1e-05,\ + } +tic=timeit.default_timer() +fgp_gpu3D = FGP_TV(pars['input'], + pars['regularisation_parameter'], + pars['number_of_iterations'], + pars['time_marching_parameter'],'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[128,:,:]*255, fgp_gpu3D[128,:,:]*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)) #%% + + diff --git a/demos/demoMatlab_denoise.m b/demos/demoMatlab_denoise.m index 5e92ee1..fa81f6d 100644 --- a/demos/demoMatlab_denoise.m +++ b/demos/demoMatlab_denoise.m @@ -2,9 +2,11 @@ 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); +%Path1 = sprintf(['..' fsep 'src' fsep 'Matlab' fsep 'mex_compile' fsep 'installed'], 1i); +Path1 = ('/home/kjy41806/Documents/SOFT/CCPi-Regularisation-Toolkit/src/Matlab/mex_compile/installed'); +Path2 = sprintf(['data' fsep], 1i); +%Path3 = sprintf(['..' filesep 'src' filesep 'Matlab' filesep 'supp'], 1i); +Path3 = '/home/kjy41806/Documents/SOFT/CCPi-Regularisation-Toolkit/src/Matlab/supp'; addpath(Path1); addpath(Path2); addpath(Path3); @@ -34,8 +36,8 @@ figure; imshow(u_rof, [0 1]); title('ROF-TV denoised image (CPU)'); %% 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 +iter_fgp = 200; % number of FGP iterations +epsil_tol = 1.0e-05; % tolerance tic; u_fgp = 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(:))); diff --git a/demos/demo_cpu_regularisers.py b/demos/demo_cpu_regularisers.py index d34607a..e58ed2f 100644 --- a/demos/demo_cpu_regularisers.py +++ b/demos/demo_cpu_regularisers.py @@ -30,8 +30,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/kjy41806/Documents/SOFT/CCPi-Regularisation-Toolkit/test/lena_gray_512.tif" # read image Im = plt.imread(filename) @@ -127,23 +128,20 @@ imgplot = plt.imshow(u0,cmap="gray") pars = {'algorithm' : FGP_TV, \ 'input' : u0,\ 'regularisation_parameter':0.04, \ - 'number_of_iterations' :2000 ,\ + 'number_of_iterations' :200 ,\ '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 = 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() -- cgit v1.2.3 From 4b29a6adc924bf8a4b3e4f9835ded93a3a2f7b92 Mon Sep 17 00:00:00 2001 From: dkazanc Date: Wed, 6 Mar 2019 17:37:14 +0000 Subject: fixes 2n vector problem --- demos/demo_cpu_regularisers.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'demos') diff --git a/demos/demo_cpu_regularisers.py b/demos/demo_cpu_regularisers.py index e58ed2f..8fa7022 100644 --- a/demos/demo_cpu_regularisers.py +++ b/demos/demo_cpu_regularisers.py @@ -31,7 +31,7 @@ def printParametersToString(pars): return txt ############################################################################### -# filename = os.path.join( "data" ,"lena_gray_512.tif") +#filename = os.path.join( "data" ,"lena_gray_512.tif") filename = "/home/kjy41806/Documents/SOFT/CCPi-Regularisation-Toolkit/test/lena_gray_512.tif" # read image @@ -128,8 +128,8 @@ imgplot = plt.imshow(u0,cmap="gray") pars = {'algorithm' : FGP_TV, \ 'input' : u0,\ 'regularisation_parameter':0.04, \ - 'number_of_iterations' :200 ,\ - 'tolerance_constant':1e-06,\ + 'number_of_iterations' :800 ,\ + 'tolerance_constant':1e-07,\ 'methodTV': 0 ,\ 'nonneg': 0 } -- cgit v1.2.3 From cfcc4be4413f65a0b9c4ef197687e3a167eff0e8 Mon Sep 17 00:00:00 2001 From: Daniil Kazantsev Date: Wed, 6 Mar 2019 23:34:55 +0000 Subject: cont1 --- demos/SoftwareX_supp/Demo_VolumeDenoise.py | 44 ++++++++++++++++-------------- demos/demo_cpu_regularisers.py | 21 +++++++------- 2 files changed, 35 insertions(+), 30 deletions(-) (limited to 'demos') diff --git a/demos/SoftwareX_supp/Demo_VolumeDenoise.py b/demos/SoftwareX_supp/Demo_VolumeDenoise.py index 17cdf4d..6e7ea46 100644 --- a/demos/SoftwareX_supp/Demo_VolumeDenoise.py +++ b/demos/SoftwareX_supp/Demo_VolumeDenoise.py @@ -120,19 +120,21 @@ print("ROF-TV (gpu) ____ RMSE: {}, MMSIM: {}, run time: {} sec".format(RMSE_rof, #%% print ("#############FGP TV CPU####################") # set parameters -pars = {'algorithm':FGP_TV, \ +pars = {'algorithm' : FGP_TV, \ 'input' : phantom_noise,\ - 'regularisation_parameter':0.04,\ - 'number_of_iterations': 300,\ - 'time_marching_parameter': 0.0025,\ - 'tolerance_constant':1e-05,\ - } + 'regularisation_parameter':0.05, \ + 'number_of_iterations' :100 ,\ + 'tolerance_constant':1e-04,\ + 'methodTV': 0 ,\ + 'nonneg': 0} tic=timeit.default_timer() -fgp_cpu3D = FGP_TV(pars['input'], - pars['regularisation_parameter'], - pars['number_of_iterations'], - pars['time_marching_parameter'],'cpu') +(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 @@ -149,19 +151,21 @@ print("FGP-TV (cpu) ____ RMSE: {}, MMSIM: {}, run time: {} sec".format(RMSE_rof, #%% print ("#############FGP TV GPU####################") # set parameters -pars = {'algorithm':FGP_TV, \ +pars = {'algorithm' : FGP_TV, \ 'input' : phantom_noise,\ - 'regularisation_parameter':0.04,\ - 'number_of_iterations': 300,\ - 'time_marching_parameter': 0.0025,\ - 'tolerance_constant':1e-05,\ - } + 'regularisation_parameter':0.05, \ + 'number_of_iterations' :80 ,\ + 'tolerance_constant':1e-04,\ + 'methodTV': 0 ,\ + 'nonneg': 0} tic=timeit.default_timer() -fgp_gpu3D = FGP_TV(pars['input'], - pars['regularisation_parameter'], - pars['number_of_iterations'], - pars['time_marching_parameter'],'gpu') +(fgp_gpu3D) = 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 diff --git a/demos/demo_cpu_regularisers.py b/demos/demo_cpu_regularisers.py index 8fa7022..32b97ce 100644 --- a/demos/demo_cpu_regularisers.py +++ b/demos/demo_cpu_regularisers.py @@ -32,7 +32,7 @@ def printParametersToString(pars): ############################################################################### #filename = os.path.join( "data" ,"lena_gray_512.tif") -filename = "/home/kjy41806/Documents/SOFT/CCPi-Regularisation-Toolkit/test/lena_gray_512.tif" +filename = "/home/algol/Documents/DEV/CCPi-Regularisation-Toolkit/test/lena_gray_512.tif" # read image Im = plt.imread(filename) @@ -86,15 +86,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': 5000,\ + 'time_marching_parameter': 0.000385,\ + 'tolerance_constant':1e-06} + print ("#############ROF TV CPU####################") start_time = timeit.default_timer() -rof_cpu = ROF_TV(pars['input'], +(rof_cpu,info_vec) = 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() @@ -127,12 +129,11 @@ imgplot = plt.imshow(u0,cmap="gray") # set parameters pars = {'algorithm' : FGP_TV, \ 'input' : u0,\ - 'regularisation_parameter':0.04, \ + 'regularisation_parameter':0.02, \ 'number_of_iterations' :800 ,\ - 'tolerance_constant':1e-07,\ + 'tolerance_constant':1e-06,\ 'methodTV': 0 ,\ - 'nonneg': 0 - } + 'nonneg': 0} print ("#############FGP TV CPU####################") start_time = timeit.default_timer() -- cgit v1.2.3 From 47693d15132130513f8d0f74fd4831a3bbf69159 Mon Sep 17 00:00:00 2001 From: dkazanc Date: Thu, 7 Mar 2019 17:52:57 +0000 Subject: matlab cmake fixed, rof tv eps --- demos/demo_cpu_regularisers.py | 12 ++++++------ demos/demo_gpu_regularisers.py | 32 +++++++++++++++----------------- 2 files changed, 21 insertions(+), 23 deletions(-) (limited to 'demos') diff --git a/demos/demo_cpu_regularisers.py b/demos/demo_cpu_regularisers.py index 32b97ce..4866811 100644 --- a/demos/demo_cpu_regularisers.py +++ b/demos/demo_cpu_regularisers.py @@ -32,7 +32,7 @@ def printParametersToString(pars): ############################################################################### #filename = os.path.join( "data" ,"lena_gray_512.tif") -filename = "/home/algol/Documents/DEV/CCPi-Regularisation-Toolkit/test/lena_gray_512.tif" +filename = "/home/kjy41806/Documents/SOFT/CCPi-Regularisation-Toolkit/test/lena_gray_512.tif" # read image Im = plt.imread(filename) @@ -86,13 +86,13 @@ imgplot = plt.imshow(u0,cmap="gray") pars = {'algorithm': ROF_TV, \ 'input' : u0,\ 'regularisation_parameter':0.02,\ - 'number_of_iterations': 5000,\ - 'time_marching_parameter': 0.000385,\ + 'number_of_iterations': 1000,\ + 'time_marching_parameter': 0.001,\ 'tolerance_constant':1e-06} print ("#############ROF TV CPU####################") start_time = timeit.default_timer() -(rof_cpu,info_vec) = ROF_TV(pars['input'], +(rof_cpu,info_vec_cpu) = ROF_TV(pars['input'], pars['regularisation_parameter'], pars['number_of_iterations'], pars['time_marching_parameter'], @@ -130,14 +130,14 @@ imgplot = plt.imshow(u0,cmap="gray") pars = {'algorithm' : FGP_TV, \ 'input' : u0,\ 'regularisation_parameter':0.02, \ - 'number_of_iterations' :800 ,\ + 'number_of_iterations' :200 ,\ 'tolerance_constant':1e-06,\ 'methodTV': 0 ,\ 'nonneg': 0} print ("#############FGP TV CPU####################") start_time = timeit.default_timer() -fgp_cpu,info_vec = FGP_TV(pars['input'], +fgp_cpu,info_vec_cpu = FGP_TV(pars['input'], pars['regularisation_parameter'], pars['number_of_iterations'], pars['tolerance_constant'], diff --git a/demos/demo_gpu_regularisers.py b/demos/demo_gpu_regularisers.py index 89bb948..212ad5a 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': 5000,\ + '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' :300 ,\ '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______________") -- cgit v1.2.3 From 49761c3730e2ddf2ec40c84952572c43e9334ccb Mon Sep 17 00:00:00 2001 From: Daniil Kazantsev Date: Fri, 8 Mar 2019 14:22:43 +0000 Subject: SBTV,LLTROF completed --- demos/demo_cpu_regularisers.py | 89 +++++++++++++++++++--------------------- demos/demo_cpu_regularisers3D.py | 69 +++++++++++++++---------------- demos/demo_gpu_regularisers.py | 84 ++++++++++++++++++------------------- demos/demo_gpu_regularisers3D.py | 61 +++++++++++++-------------- 4 files changed, 146 insertions(+), 157 deletions(-) (limited to 'demos') diff --git a/demos/demo_cpu_regularisers.py b/demos/demo_cpu_regularisers.py index 4866811..f2d2f33 100644 --- a/demos/demo_cpu_regularisers.py +++ b/demos/demo_cpu_regularisers.py @@ -32,7 +32,7 @@ def printParametersToString(pars): ############################################################################### #filename = os.path.join( "data" ,"lena_gray_512.tif") -filename = "/home/kjy41806/Documents/SOFT/CCPi-Regularisation-Toolkit/test/lena_gray_512.tif" +filename = "/home/algol/Documents/DEV/CCPi-Regularisation-Toolkit/test/lena_gray_512.tif" # read image Im = plt.imread(filename) @@ -130,14 +130,14 @@ imgplot = plt.imshow(u0,cmap="gray") pars = {'algorithm' : FGP_TV, \ 'input' : u0,\ 'regularisation_parameter':0.02, \ - 'number_of_iterations' :200 ,\ + 'number_of_iterations' :400 ,\ 'tolerance_constant':1e-06,\ 'methodTV': 0 ,\ 'nonneg': 0} print ("#############FGP TV CPU####################") start_time = timeit.default_timer() -fgp_cpu,info_vec_cpu = FGP_TV(pars['input'], +(fgp_cpu,info_vec_cpu) = FGP_TV(pars['input'], pars['regularisation_parameter'], pars['number_of_iterations'], pars['tolerance_constant'], @@ -175,21 +175,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() @@ -209,37 +206,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) @@ -252,40 +247,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 ,\ + 'regularisation_parameter':0.04, \ + 'alpha1':1.0,\ + 'alpha0':2.0,\ + 'number_of_iterations' :1350 ,\ + 'LipshitzConstant' :12 ,\ } -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 = 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'],'cpu') + + +Qtools = QualityTools(Im, tgv_cpu) pars['rmse'] = Qtools.rmse() txtstr = printParametersToString(pars) @@ -298,7 +295,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_cpu, cmap="gray") +imgplot = plt.imshow(tgv_cpu, cmap="gray") plt.title('{}'.format('CPU results')) #%% diff --git a/demos/demo_cpu_regularisers3D.py b/demos/demo_cpu_regularisers3D.py index fd6c545..0f9cd1a 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) diff --git a/demos/demo_gpu_regularisers.py b/demos/demo_gpu_regularisers.py index 212ad5a..6aec283 100644 --- a/demos/demo_gpu_regularisers.py +++ b/demos/demo_gpu_regularisers.py @@ -84,7 +84,7 @@ imgplot = plt.imshow(u0,cmap="gray") pars = {'algorithm': ROF_TV, \ 'input' : u0,\ 'regularisation_parameter':0.02,\ - 'number_of_iterations': 5000,\ + 'number_of_iterations': 6000,\ 'time_marching_parameter': 0.001,\ 'tolerance_constant':1e-06} @@ -128,7 +128,7 @@ imgplot = plt.imshow(u0,cmap="gray") pars = {'algorithm' : FGP_TV, \ 'input' : u0,\ 'regularisation_parameter':0.02, \ - 'number_of_iterations' :300 ,\ + 'number_of_iterations' :400 ,\ 'tolerance_constant':1e-06,\ 'methodTV': 0 ,\ 'nonneg': 0} @@ -171,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() @@ -205,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) @@ -246,40 +242,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_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.04, \ + 'alpha1':1.0,\ + 'alpha0':2.0,\ + 'number_of_iterations' :1250 ,\ + 'LipshitzConstant' :12 ,\ } -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 = 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'],'gpu') + +Qtools = QualityTools(Im, tgv_gpu) pars['rmse'] = Qtools.rmse() txtstr = printParametersToString(pars) txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time) @@ -291,7 +289,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')) #%% diff --git a/demos/demo_gpu_regularisers3D.py b/demos/demo_gpu_regularisers3D.py index be16921..1a13c86 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() -- cgit v1.2.3 From e2208bfc2ed540065bef2e8e12d914d873464da7 Mon Sep 17 00:00:00 2001 From: Daniil Kazantsev Date: Sun, 10 Mar 2019 22:23:22 +0000 Subject: all python code updated --- demos/SoftwareX_supp/Demo_VolumeDenoise.py | 55 +++++-- demos/demoMatlab_denoise.m | 39 ++--- demos/demo_cpu_regularisers.py | 66 ++++---- demos/demo_cpu_regularisers3D.py | 60 +++---- demos/demo_cpu_vs_gpu_regularisers.py | 250 ++++++++++++++--------------- demos/demo_gpu_regularisers.py | 56 +++---- demos/demo_gpu_regularisers3D.py | 58 +++---- 7 files changed, 298 insertions(+), 286 deletions(-) (limited to 'demos') diff --git a/demos/SoftwareX_supp/Demo_VolumeDenoise.py b/demos/SoftwareX_supp/Demo_VolumeDenoise.py index 6e7ea46..07e3133 100644 --- a/demos/SoftwareX_supp/Demo_VolumeDenoise.py +++ b/demos/SoftwareX_supp/Demo_VolumeDenoise.py @@ -29,7 +29,7 @@ from ccpi.filters.regularisers import ROF_TV, FGP_TV, SB_TV, LLT_ROF, NDF, Diff4 #%% print ("Building 3D phantom using TomoPhantom software") tic=timeit.default_timer() -model = 9 # select a model number from the library +model = 16 # select a model number from the library N_size = 256 # Define phantom dimensions using a scalar value (cubic phantom) path = os.path.dirname(tomophantom.__file__) path_library3D = os.path.join(path, "Phantom3DLibrary.dat") @@ -66,16 +66,18 @@ print ("#############ROF TV CPU####################") # set parameters pars = {'algorithm': ROF_TV, \ 'input' : phantom_noise,\ - 'regularisation_parameter':0.04,\ - 'number_of_iterations': 600,\ - 'time_marching_parameter': 0.0025 - } + 'regularisation_parameter':0.02,\ + 'number_of_iterations': 1000,\ + 'time_marching_parameter': 0.001,\ + 'tolerance_constant':0.0} tic=timeit.default_timer() -rof_cpu3D = ROF_TV(pars['input'], +(rof_cpu3D, infcpu) = ROF_TV(pars['input'], pars['regularisation_parameter'], pars['number_of_iterations'], - pars['time_marching_parameter'],'cpu') + pars['time_marching_parameter'], + pars['tolerance_constant'],'cpu') + toc=timeit.default_timer() Run_time_rof = toc - tic @@ -94,28 +96,47 @@ print ("#############ROF TV GPU####################") # set parameters pars = {'algorithm': ROF_TV, \ 'input' : phantom_noise,\ - 'regularisation_parameter':0.04,\ - 'number_of_iterations': 600,\ - 'time_marching_parameter': 0.0025 - } + 'regularisation_parameter':0.06,\ + 'number_of_iterations': 10000,\ + 'time_marching_parameter': 0.00025,\ + 'tolerance_constant':1e-06} tic=timeit.default_timer() -rof_gpu3D = ROF_TV(pars['input'], +(rof_gpu3D, infogpu) = ROF_TV(pars['input'], pars['regularisation_parameter'], pars['number_of_iterations'], - pars['time_marching_parameter'],'gpu') + 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() +sliceNo = 128 # SSIM measure -Qtools = QualityTools(phantom_tm[128,:,:]*255, rof_gpu3D[128,:,:]*235) +Qtools = QualityTools(phantom_tm[sliceNo,:,:]*255, rof_gpu3D[sliceNo,:,:]*235) win = np.array([gaussian(11, 1.5)]) win2d = win * (win.T) ssim_rof = Qtools.ssim(win2d) +sliceSel = int(0.5*N_size) +#plt.gray() +plt.figure() +plt.subplot(131) +plt.imshow(rof_gpu3D[sliceSel,:,:],vmin=0, vmax=1.4) +plt.title('3D ROF-TV, axial view') + +plt.subplot(132) +plt.imshow(rof_gpu3D[:,sliceSel,:],vmin=0, vmax=1.4) +plt.title('3D ROF-TV, coronal view') + +plt.subplot(133) +plt.imshow(rof_gpu3D[:,:,sliceSel],vmin=0, vmax=1.4) +plt.title('3D ROF-TV, sagittal view') +plt.show() + print("ROF-TV (gpu) ____ RMSE: {}, MMSIM: {}, run time: {} sec".format(RMSE_rof,ssim_rof[0],Run_time_rof)) #%% print ("#############FGP TV CPU####################") @@ -154,13 +175,13 @@ print ("#############FGP TV GPU####################") pars = {'algorithm' : FGP_TV, \ 'input' : phantom_noise,\ 'regularisation_parameter':0.05, \ - 'number_of_iterations' :80 ,\ - 'tolerance_constant':1e-04,\ + 'number_of_iterations' :1500 ,\ + 'tolerance_constant':1e-06,\ 'methodTV': 0 ,\ 'nonneg': 0} tic=timeit.default_timer() -(fgp_gpu3D) = FGP_TV(pars['input'], +(fgp_gpu3D,infogpu) = FGP_TV(pars['input'], pars['regularisation_parameter'], pars['number_of_iterations'], pars['tolerance_constant'], diff --git a/demos/demoMatlab_denoise.m b/demos/demoMatlab_denoise.m index fa81f6d..a22b40a 100644 --- a/demos/demoMatlab_denoise.m +++ b/demos/demoMatlab_denoise.m @@ -2,11 +2,9 @@ clear; close all fsep = '/'; -%Path1 = sprintf(['..' fsep 'src' fsep 'Matlab' fsep 'mex_compile' fsep 'installed'], 1i); -Path1 = ('/home/kjy41806/Documents/SOFT/CCPi-Regularisation-Toolkit/src/Matlab/mex_compile/installed'); +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); -Path3 = '/home/kjy41806/Documents/SOFT/CCPi-Regularisation-Toolkit/src/Matlab/supp'; +Path3 = sprintf(['..' fsep 'src' fsep 'Matlab' fsep 'supp'], 1i); addpath(Path1); addpath(Path2); addpath(Path3); @@ -14,14 +12,14 @@ 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; -energyfunc_val_rof = TV_energy(single(u_rof),single(u0),lambda_reg, 1); % get energy function value +lambda_reg = 0.02; % regularsation parameter for all methods +iter_rof = 2000; % number of ROF iterations +tau_rof = 0.001; % time-marching constant +epsil_tol = 0.0; % tolerance +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); [ssimval] = ssim(u_rof*255,single(Im)*255); @@ -29,16 +27,14 @@ 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; +% tic; u_rofG = 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 = 200; % number of FGP iterations -epsil_tol = 1.0e-05; % tolerance -tic; u_fgp = FGP_TV(single(u0), lambda_reg, iter_fgp, epsil_tol); toc; +lambda_reg = 0.02; +iter_fgp = 500; % number of FGP iterations +epsil_tol = 1.0e-06; % 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); @@ -47,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 = 300; % number of SB iterations +epsil_tol = 1.0e-06; % 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); diff --git a/demos/demo_cpu_regularisers.py b/demos/demo_cpu_regularisers.py index f2d2f33..8655623 100644 --- a/demos/demo_cpu_regularisers.py +++ b/demos/demo_cpu_regularisers.py @@ -31,8 +31,7 @@ def printParametersToString(pars): return txt ############################################################################### -#filename = os.path.join( "data" ,"lena_gray_512.tif") -filename = "/home/algol/Documents/DEV/CCPi-Regularisation-Toolkit/test/lena_gray_512.tif" +filename = os.path.join( "data" ,"lena_gray_512.tif") # read image Im = plt.imread(filename) @@ -86,7 +85,7 @@ imgplot = plt.imshow(u0,cmap="gray") pars = {'algorithm': ROF_TV, \ 'input' : u0,\ 'regularisation_parameter':0.02,\ - 'number_of_iterations': 1000,\ + 'number_of_iterations': 4000,\ 'time_marching_parameter': 0.001,\ 'tolerance_constant':1e-06} @@ -265,23 +264,23 @@ imgplot = plt.imshow(u0,cmap="gray") # set parameters pars = {'algorithm' : TGV, \ 'input' : u0,\ - 'regularisation_parameter':0.04, \ + 'regularisation_parameter':0.02, \ 'alpha1':1.0,\ 'alpha0':2.0,\ - 'number_of_iterations' :1350 ,\ + 'number_of_iterations' :1000 ,\ 'LipshitzConstant' :12 ,\ - } - + 'tolerance_constant':1e-06} + print ("#############TGV CPU####################") start_time = timeit.default_timer() -tgv_cpu = TGV(pars['input'], +(tgv_cpu,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(Im, tgv_cpu) pars['rmse'] = Qtools.rmse() @@ -299,8 +298,6 @@ imgplot = plt.imshow(tgv_cpu, cmap="gray") plt.title('{}'.format('CPU results')) #%% - - print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") print ("________________NDF (2D)___________________") print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") @@ -315,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() @@ -362,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() @@ -480,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 0f9cd1a..fc1e8e6 100644 --- a/demos/demo_cpu_regularisers3D.py +++ b/demos/demo_cpu_regularisers3D.py @@ -277,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() @@ -325,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) @@ -373,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) @@ -420,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 6aec283..3efcfce 100644 --- a/demos/demo_gpu_regularisers.py +++ b/demos/demo_gpu_regularisers.py @@ -84,7 +84,7 @@ imgplot = plt.imshow(u0,cmap="gray") pars = {'algorithm': ROF_TV, \ 'input' : u0,\ 'regularisation_parameter':0.02,\ - 'number_of_iterations': 6000,\ + 'number_of_iterations': 4000,\ 'time_marching_parameter': 0.001,\ 'tolerance_constant':1e-06} @@ -261,21 +261,22 @@ imgplot = plt.imshow(u0,cmap="gray") # set parameters pars = {'algorithm' : TGV, \ 'input' : u0,\ - 'regularisation_parameter':0.04, \ + 'regularisation_parameter':0.02, \ 'alpha1':1.0,\ 'alpha0':2.0,\ - 'number_of_iterations' :1250 ,\ + 'number_of_iterations' :1000 ,\ 'LipshitzConstant' :12 ,\ - } + 'tolerance_constant':1e-06} print ("#############TGV CPU####################") start_time = timeit.default_timer() -tgv_gpu = TGV(pars['input'], +(tgv_gpu, 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(Im, tgv_gpu) pars['rmse'] = Qtools.rmse() @@ -307,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() @@ -354,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 @@ -470,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 1a13c86..ccf9694 100644 --- a/demos/demo_gpu_regularisers3D.py +++ b/demos/demo_gpu_regularisers3D.py @@ -277,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() @@ -322,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() @@ -368,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() @@ -410,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() -- cgit v1.2.3 From cd2844b6384cb74fae5ee3f7f0fdb91be752653e Mon Sep 17 00:00:00 2001 From: dkazanc Date: Mon, 11 Mar 2019 16:43:05 +0000 Subject: volume denoising complete --- demos/SoftwareX_supp/Demo_SimulData_Recon_SX.py | 2 +- demos/SoftwareX_supp/Demo_VolumeDenoise.py | 363 +++++++++++++++++++++--- 2 files changed, 331 insertions(+), 34 deletions(-) (limited to 'demos') diff --git a/demos/SoftwareX_supp/Demo_SimulData_Recon_SX.py b/demos/SoftwareX_supp/Demo_SimulData_Recon_SX.py index 93b0cef..99b9fe8 100644 --- a/demos/SoftwareX_supp/Demo_SimulData_Recon_SX.py +++ b/demos/SoftwareX_supp/Demo_SimulData_Recon_SX.py @@ -164,7 +164,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 = 1e-08, # tolerance to stop inner 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 index 07e3133..e128127 100644 --- a/demos/SoftwareX_supp/Demo_VolumeDenoise.py +++ b/demos/SoftwareX_supp/Demo_VolumeDenoise.py @@ -25,12 +25,12 @@ 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, NDF, Diff4th +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 = 256 # Define phantom dimensions using a scalar value (cubic phantom) +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) @@ -66,9 +66,9 @@ print ("#############ROF TV CPU####################") # set parameters pars = {'algorithm': ROF_TV, \ 'input' : phantom_noise,\ - 'regularisation_parameter':0.02,\ + 'regularisation_parameter':0.06,\ 'number_of_iterations': 1000,\ - 'time_marching_parameter': 0.001,\ + 'time_marching_parameter': 0.00025,\ 'tolerance_constant':0.0} tic=timeit.default_timer() @@ -85,7 +85,7 @@ Qtools = QualityTools(phantom_tm, rof_cpu3D) RMSE_rof = Qtools.rmse() # SSIM measure -Qtools = QualityTools(phantom_tm[128,:,:]*255, rof_cpu3D[128,:,:]*235) +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) @@ -97,9 +97,9 @@ print ("#############ROF TV GPU####################") pars = {'algorithm': ROF_TV, \ 'input' : phantom_noise,\ 'regularisation_parameter':0.06,\ - 'number_of_iterations': 10000,\ + 'number_of_iterations': 8330,\ 'time_marching_parameter': 0.00025,\ - 'tolerance_constant':1e-06} + 'tolerance_constant':0.0} tic=timeit.default_timer() (rof_gpu3D, infogpu) = ROF_TV(pars['input'], @@ -114,38 +114,21 @@ Run_time_rof = toc - tic Qtools = QualityTools(phantom_tm, rof_gpu3D) RMSE_rof = Qtools.rmse() -sliceNo = 128 # SSIM measure -Qtools = QualityTools(phantom_tm[sliceNo,:,:]*255, rof_gpu3D[sliceNo,:,:]*235) +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) -sliceSel = int(0.5*N_size) -#plt.gray() -plt.figure() -plt.subplot(131) -plt.imshow(rof_gpu3D[sliceSel,:,:],vmin=0, vmax=1.4) -plt.title('3D ROF-TV, axial view') - -plt.subplot(132) -plt.imshow(rof_gpu3D[:,sliceSel,:],vmin=0, vmax=1.4) -plt.title('3D ROF-TV, coronal view') - -plt.subplot(133) -plt.imshow(rof_gpu3D[:,:,sliceSel],vmin=0, vmax=1.4) -plt.title('3D ROF-TV, sagittal view') -plt.show() - 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.05, \ - 'number_of_iterations' :100 ,\ - 'tolerance_constant':1e-04,\ + 'regularisation_parameter':0.06, \ + 'number_of_iterations' : 930 ,\ + 'tolerance_constant':0.0,\ 'methodTV': 0 ,\ 'nonneg': 0} @@ -163,7 +146,7 @@ Qtools = QualityTools(phantom_tm, fgp_cpu3D) RMSE_rof = Qtools.rmse() # SSIM measure -Qtools = QualityTools(phantom_tm[128,:,:]*255, fgp_cpu3D[128,:,:]*235) +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) @@ -174,9 +157,9 @@ print ("#############FGP TV GPU####################") # set parameters pars = {'algorithm' : FGP_TV, \ 'input' : phantom_noise,\ - 'regularisation_parameter':0.05, \ - 'number_of_iterations' :1500 ,\ - 'tolerance_constant':1e-06,\ + 'regularisation_parameter':0.06, \ + 'number_of_iterations' :930 ,\ + 'tolerance_constant':0.0,\ 'methodTV': 0 ,\ 'nonneg': 0} @@ -194,13 +177,327 @@ Qtools = QualityTools(phantom_tm, fgp_gpu3D) RMSE_rof = Qtools.rmse() # SSIM measure -Qtools = QualityTools(phantom_tm[128,:,:]*255, fgp_gpu3D[128,:,:]*235) +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)) -- cgit v1.2.3 From b901525766f8e3473ef58a19bf3fadc178d3778c Mon Sep 17 00:00:00 2001 From: Daniil Kazantsev Date: Mon, 11 Mar 2019 22:27:57 +0000 Subject: fix for matlab wrappers --- demos/demoMatlab_denoise.m | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'demos') diff --git a/demos/demoMatlab_denoise.m b/demos/demoMatlab_denoise.m index a22b40a..7581068 100644 --- a/demos/demoMatlab_denoise.m +++ b/demos/demoMatlab_denoise.m @@ -19,7 +19,7 @@ iter_rof = 2000; % number of ROF iterations tau_rof = 0.001; % time-marching constant epsil_tol = 0.0; % tolerance 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 +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); [ssimval] = ssim(u_rof*255,single(Im)*255); @@ -27,7 +27,7 @@ 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'); -% tic; u_rofG = ROF_TV_GPU(single(u0), lambda_reg, iter_rof, tau_rof, epsil_tol); toc; +% 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'); @@ -59,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)'); %% @@ -69,7 +67,8 @@ 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 = 1.0e-06; % 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); @@ -85,11 +84,11 @@ figure; imshow(u_diff, [0 1]); title('Diffusion denoised image (CPU)'); % 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.045; % 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 +iter_TGV = 2500; % number of Primal-Dual iterations for TGV +tic; [u_tgv,infovec] = TGV(single(u0), lambda_TGV, alpha1, alpha0, iter_TGV); toc; rmseTGV = (RMSE(u_tgv(:),Im(:))); fprintf('%s %f \n', 'RMSE error for TGV is:', rmseTGV); [ssimval] = ssim(u_tgv*255,single(Im)*255); @@ -109,11 +108,12 @@ figure; imshow(u_tgv, [0 1]); title('TGV denoised image (CPU)'); % 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 +lambda_ROF = 0.02; % ROF regularisation parameter +lambda_LLT = 0.01; % LLT regularisation parameter +iter_LLT = 1000; % 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; +epsil_tol = 1.0e-06; % 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); @@ -132,10 +132,11 @@ figure; imshow(u_rof_llt, [0 1]); title('ROF-LLT denoised image (CPU)'); %% 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 +lambda_regDiff = 2.5; % regularisation for the diffusivity +sigmaPar = 0.03; % 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; +epsil_tol = 1.0e-06; % 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); @@ -174,10 +175,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 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)'); -- cgit v1.2.3 From 420e71a0dcb42e91e1aa93306c2e2f688b309620 Mon Sep 17 00:00:00 2001 From: dkazanc Date: Tue, 12 Mar 2019 17:29:07 +0000 Subject: cmakelists fixes, matlab wrappers done --- demos/SoftwareX_supp/Demo_RealData_Recon_SX.py | 4 +- .../SoftwareX_supp/Demo_SimulData_ParOptimis_SX.py | 2 +- demos/SoftwareX_supp/Demo_SimulData_Recon_SX.py | 3 +- demos/demoMatlab_3Ddenoise.m | 35 +++++---- demos/demoMatlab_denoise.m | 83 ++++++++-------------- 5 files changed, 55 insertions(+), 72 deletions(-) (limited to 'demos') diff --git a/demos/SoftwareX_supp/Demo_RealData_Recon_SX.py b/demos/SoftwareX_supp/Demo_RealData_Recon_SX.py index 01491d9..ca8f1d2 100644 --- a/demos/SoftwareX_supp/Demo_RealData_Recon_SX.py +++ b/demos/SoftwareX_supp/Demo_RealData_Recon_SX.py @@ -111,7 +111,7 @@ RectoolsIR = RecToolsIR(DetectorsDimH = np.size(det_y_crop), # DetectorsDimH # 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") @@ -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 99b9fe8..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 inner 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/demoMatlab_3Ddenoise.m b/demos/demoMatlab_3Ddenoise.m index cf2c88a..ec0fd88 100644 --- a/demos/demoMatlab_3Ddenoise.m +++ b/demos/demoMatlab_3Ddenoise.m @@ -23,7 +23,8 @@ lambda_reg = 0.03; % regularsation parameter for all methods fprintf('Denoise a volume using the ROF-TV model (CPU) \n'); 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); @@ -39,8 +40,8 @@ figure; imshow(u_rof(:,:,7), [0 1]); title('ROF-TV denoised volume (CPU)'); %% fprintf('Denoise a volume using the FGP-TV model (CPU) \n'); 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); @@ -56,8 +57,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); @@ -76,7 +77,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 +88,7 @@ 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; +% 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 +98,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 +109,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 +119,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 +130,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)'); @@ -136,7 +140,8 @@ 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 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, 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 +151,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, 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 +168,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 +184,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 7581068..377a447 100644 --- a/demos/demoMatlab_denoise.m +++ b/demos/demoMatlab_denoise.m @@ -14,10 +14,10 @@ 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.02; % regularsation parameter for all methods +lambda_reg = 0.03; % regularsation parameter for all methods iter_rof = 2000; % number of ROF iterations -tau_rof = 0.001; % time-marching constant -epsil_tol = 0.0; % tolerance +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(:))); @@ -26,14 +26,14 @@ 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'); -% 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 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.02; +lambda_reg = 0.03; iter_fgp = 500; % number of FGP iterations -epsil_tol = 1.0e-06; % tolerance +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(:))); @@ -48,8 +48,8 @@ figure; imshow(u_fgp, [0 1]); title('FGP-TV denoised image (CPU)'); %% fprintf('Denoise using the SB-TV model (CPU) \n'); lambda_reg = 0.03; -iter_sb = 300; % number of SB iterations -epsil_tol = 1.0e-06; % tolerance +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(:))); @@ -67,7 +67,7 @@ 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 -epsil_tol = 1.0e-06; % tolerance +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); @@ -75,20 +75,17 @@ fprintf('%s %f \n', 'RMSE error for Nonlinear Diffusion is:', rmseDiffus); 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.045; % regularisation parameter +lambda_TGV = 0.035; % regularisation parameter alpha1 = 1.0; % parameter to control the first-order term alpha0 = 2.0; % parameter to control the second-order term -iter_TGV = 2500; % number of Primal-Dual iterations for TGV -tic; [u_tgv,infovec] = TGV(single(u0), lambda_TGV, alpha1, alpha0, iter_TGV); toc; +iter_TGV = 20; % 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, epsil_tol); toc; rmseTGV = (RMSE(u_tgv(:),Im(:))); fprintf('%s %f \n', 'RMSE error for TGV is:', rmseTGV); [ssimval] = ssim(u_tgv*255,single(Im)*255); @@ -96,23 +93,15 @@ 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, 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.02; % ROF regularisation parameter -lambda_LLT = 0.01; % LLT regularisation parameter -iter_LLT = 1000; % iterations -tau_rof_llt = 0.0025; % time-marching constant -epsil_tol = 1.0e-06; % tolerance +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); @@ -121,21 +110,15 @@ 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 = 2.5; % regularisation for the diffusivity +lambda_regDiff = 3; % regularisation for the diffusivity sigmaPar = 0.03; % edge-preserving parameter -tau_param = 0.0015; % time-marching constant -epsil_tol = 1.0e-06; % tolerance +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); @@ -143,13 +126,9 @@ fprintf('%s %f \n', 'RMSE error for Fourth-order anisotropic diffusion is:', rms 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,7 +156,7 @@ u_ref = Im + .01*randn(size(Im)); u_ref(u_ref < 0) = 0; 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,infovec] = FGP_dTV(single(u0), single(u_ref), lambda_reg, iter_fgp, epsil_tol, eta); toc; rmse_dTV= (RMSE(u_fgp_dtv(:),Im(:))); -- cgit v1.2.3 From 1ac06b5ce11b247930489b7aa3afa59215e43c91 Mon Sep 17 00:00:00 2001 From: Daniil Kazantsev Date: Tue, 12 Mar 2019 22:14:27 +0000 Subject: readme updates and demos --- demos/SoftwareX_supp/Demo_RealData_Recon_SX.py | 18 +++++++++--------- demos/demoMatlab_3Ddenoise.m | 16 +++++++++++----- 2 files changed, 20 insertions(+), 14 deletions(-) (limited to 'demos') diff --git a/demos/SoftwareX_supp/Demo_RealData_Recon_SX.py b/demos/SoftwareX_supp/Demo_RealData_Recon_SX.py index ca8f1d2..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,7 +108,7 @@ 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 = 0.0, # tolerance to stop inner (regularisation) iterations earlier @@ -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') diff --git a/demos/demoMatlab_3Ddenoise.m b/demos/demoMatlab_3Ddenoise.m index ec0fd88..6b21e86 100644 --- a/demos/demoMatlab_3Ddenoise.m +++ b/demos/demoMatlab_3Ddenoise.m @@ -18,9 +18,10 @@ 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 epsil_tol = 0.0; % tolerance @@ -31,14 +32,17 @@ 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 = 0.0; % tolerance tic; [u_fgp,infovec] = FGP_TV(single(vol3D), lambda_reg, iter_fgp, epsil_tol); toc; @@ -47,9 +51,10 @@ 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); @@ -66,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); @@ -88,6 +93,7 @@ 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 +% 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); -- cgit v1.2.3 From 9633c5d701c164c3ff8f4d870624f87744d186bd Mon Sep 17 00:00:00 2001 From: Daniil Kazantsev Date: Sat, 16 Mar 2019 23:39:29 +0000 Subject: matlab demos updated --- demos/demoMatlab_3Ddenoise.m | 5 +++-- demos/demoMatlab_denoise.m | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'demos') diff --git a/demos/demoMatlab_3Ddenoise.m b/demos/demoMatlab_3Ddenoise.m index 6b21e86..3942eea 100644 --- a/demos/demoMatlab_3Ddenoise.m +++ b/demos/demoMatlab_3Ddenoise.m @@ -145,9 +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 epsil_tol = 0.0; % tolerance -tic; u_tgv = TGV(single(vol3D), lambda_TGV, alpha1, alpha0, iter_TGV, epsil_tol); toc; +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)'); @@ -157,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, epsil_tol); 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)'); diff --git a/demos/demoMatlab_denoise.m b/demos/demoMatlab_denoise.m index 377a447..9d89138 100644 --- a/demos/demoMatlab_denoise.m +++ b/demos/demoMatlab_denoise.m @@ -83,17 +83,18 @@ fprintf('Denoise using the TGV model (CPU) \n'); lambda_TGV = 0.035; % regularisation parameter alpha1 = 1.0; % parameter to control the first-order term alpha0 = 2.0; % parameter to control the second-order term -iter_TGV = 20; % number of Primal-Dual iterations for TGV +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, epsil_tol); toc; +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'); -% tic; u_tgv_gpu = TGV_GPU(single(u0), lambda_TGV, alpha1, alpha0, iter_TGV, epsil_tol); toc; +% 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'); -- cgit v1.2.3