diff options
Diffstat (limited to 'demos')
-rw-r--r-- | demos/demo_cpu_regularisers.py | 89 | ||||
-rw-r--r-- | demos/demo_cpu_regularisers3D.py | 69 | ||||
-rw-r--r-- | demos/demo_gpu_regularisers.py | 84 | ||||
-rw-r--r-- | demos/demo_gpu_regularisers3D.py | 61 |
4 files changed, 146 insertions, 157 deletions
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() |