From 5ef87da22a31868fd88c7f0ab4c2201e816e92ed Mon Sep 17 00:00:00 2001 From: Daniil Kazantsev Date: Tue, 1 May 2018 12:07:30 +0100 Subject: inpaint demo --- Wrappers/Python/demos/demo_cpu_inpainters.py | 143 +++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 Wrappers/Python/demos/demo_cpu_inpainters.py (limited to 'Wrappers/Python/demos') diff --git a/Wrappers/Python/demos/demo_cpu_inpainters.py b/Wrappers/Python/demos/demo_cpu_inpainters.py new file mode 100644 index 0000000..a022bc8 --- /dev/null +++ b/Wrappers/Python/demos/demo_cpu_inpainters.py @@ -0,0 +1,143 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Demonstration of CPU inpainters +@authors: Daniil Kazantsev, Edoardo Pasca +""" + +import matplotlib.pyplot as plt +import numpy as np +import os +import timeit +from scipy import io +from ccpi.filters.regularisers import NDF_INP +from qualitymetrics import rmse +############################################################################### +def printParametersToString(pars): + txt = r'' + for key, value in pars.items(): + if key== 'algorithm' : + txt += "{0} = {1}".format(key, value.__name__) + elif key == 'input': + txt += "{0} = {1}".format(key, np.shape(value)) + elif key == 'refdata': + txt += "{0} = {1}".format(key, np.shape(value)) + else: + txt += "{0} = {1}".format(key, value) + txt += '\n' + return txt +############################################################################### +#%% +# read sinogram and the mask +filename = os.path.join(".." , ".." , ".." , "data" ,"SinoInpaint.mat") +sino = io.loadmat(filename) +sino_no_cut = sino.get('Sinogram') +Mask = sino.get('Mask') +[angles_dim,detectors_dim] = sino_no_cut.shape +sinogram = sino_no_cut/np.max(sino_no_cut) +#apply mask to sinogram +sino_cut = sinogram*(1-Mask) + +plt.figure(1) +plt.subplot(121) +plt.imshow(sino_cut,vmin=0.0, vmax=1) +plt.title('Missing Data sinogram') +plt.subplot(122) +plt.imshow(Mask) +plt.title('Mask') +plt.show() +#%% +print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") +print ("___Inpainting using linear diffusion (2D)__") +print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") + +## plot +fig = plt.figure(2) +plt.suptitle('Performance of linear inpainting using the CPU') +a=fig.add_subplot(1,2,1) +a.set_title('Missing data sinogram') +imgplot = plt.imshow(sino_cut,cmap="gray") + +# set parameters +pars = {'algorithm' : NDF_INP, \ + 'input' : sino_cut,\ + 'maskData' : Mask,\ + 'regularisation_parameter':6000,\ + 'edge_parameter':0.0,\ + 'number_of_iterations' :5000 ,\ + 'time_marching_parameter':0.000075,\ + 'penalty_type':1 + } + +start_time = timeit.default_timer() +ndf_inp_linear = NDF_INP(pars['input'], + pars['maskData'], + pars['regularisation_parameter'], + pars['edge_parameter'], + pars['number_of_iterations'], + pars['time_marching_parameter'], + pars['penalty_type']) + +rms = rmse(sinogram, ndf_inp_linear) +pars['rmse'] = rms + +txtstr = printParametersToString(pars) +txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time) +print (txtstr) +a=fig.add_subplot(1,2,2) + +# these are matplotlib.patch.Patch properties +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(ndf_inp_linear, cmap="gray") +plt.title('{}'.format('Linear diffusion inpainting results')) +#%% +print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") +print ("_Inpainting using nonlinear diffusion (2D)_") +print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") + +## plot +fig = plt.figure(3) +plt.suptitle('Performance of nonlinear diffusion inpainting using the CPU') +a=fig.add_subplot(1,2,1) +a.set_title('Missing data sinogram') +imgplot = plt.imshow(sino_cut,cmap="gray") + +# set parameters +pars = {'algorithm' : NDF_INP, \ + 'input' : sino_cut,\ + 'maskData' : Mask,\ + 'regularisation_parameter':80,\ + 'edge_parameter':0.00009,\ + 'number_of_iterations' :1500 ,\ + 'time_marching_parameter':0.000008,\ + 'penalty_type':1 + } + +start_time = timeit.default_timer() +ndf_inp_nonlinear = NDF_INP(pars['input'], + pars['maskData'], + pars['regularisation_parameter'], + pars['edge_parameter'], + pars['number_of_iterations'], + pars['time_marching_parameter'], + pars['penalty_type']) + +rms = rmse(sinogram, ndf_inp_nonlinear) +pars['rmse'] = rms + +txtstr = printParametersToString(pars) +txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time) +print (txtstr) +a=fig.add_subplot(1,2,2) + +# these are matplotlib.patch.Patch properties +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(ndf_inp_nonlinear, cmap="gray") +plt.title('{}'.format('Nonlinear diffusion inpainting results')) +#%% \ No newline at end of file -- cgit v1.2.3 From 033c2030a05c7aa4c832e7a5e9fd13346d05e33d Mon Sep 17 00:00:00 2001 From: algol Date: Tue, 1 May 2018 14:48:45 +0100 Subject: some correction --- Wrappers/Python/demos/demo_cpu_inpainters.py | 40 ++++++++++++++++------------ 1 file changed, 23 insertions(+), 17 deletions(-) (limited to 'Wrappers/Python/demos') diff --git a/Wrappers/Python/demos/demo_cpu_inpainters.py b/Wrappers/Python/demos/demo_cpu_inpainters.py index a022bc8..b067b11 100644 --- a/Wrappers/Python/demos/demo_cpu_inpainters.py +++ b/Wrappers/Python/demos/demo_cpu_inpainters.py @@ -20,30 +20,36 @@ def printParametersToString(pars): txt += "{0} = {1}".format(key, value.__name__) elif key == 'input': txt += "{0} = {1}".format(key, np.shape(value)) - elif key == 'refdata': + elif key == 'maskData': txt += "{0} = {1}".format(key, np.shape(value)) else: txt += "{0} = {1}".format(key, value) txt += '\n' return txt ############################################################################### -#%% + # read sinogram and the mask filename = os.path.join(".." , ".." , ".." , "data" ,"SinoInpaint.mat") sino = io.loadmat(filename) -sino_no_cut = sino.get('Sinogram') +sino_full = sino.get('Sinogram') Mask = sino.get('Mask') -[angles_dim,detectors_dim] = sino_no_cut.shape -sinogram = sino_no_cut/np.max(sino_no_cut) +[angles_dim,detectors_dim] = sino_full.shape +sino_full = sino_full/np.max(sino_full) #apply mask to sinogram -sino_cut = sinogram*(1-Mask) +sino_cut = sino_full*(1-Mask) +sino_cut_new = np.zeros((angles_dim,detectors_dim),'float32') +#sino_cut_new = sino_cut.copy(order='c') +sino_cut_new[:] = sino_cut[:] +mask = np.zeros((angles_dim,detectors_dim),'uint8') +#mask =Mask.copy(order='c') +mask[:] = Mask[:] plt.figure(1) plt.subplot(121) -plt.imshow(sino_cut,vmin=0.0, vmax=1) +plt.imshow(sino_cut_new,vmin=0.0, vmax=1) plt.title('Missing Data sinogram') plt.subplot(122) -plt.imshow(Mask) +plt.imshow(mask) plt.title('Mask') plt.show() #%% @@ -56,15 +62,15 @@ fig = plt.figure(2) plt.suptitle('Performance of linear inpainting using the CPU') a=fig.add_subplot(1,2,1) a.set_title('Missing data sinogram') -imgplot = plt.imshow(sino_cut,cmap="gray") +imgplot = plt.imshow(sino_cut_new,cmap="gray") # set parameters pars = {'algorithm' : NDF_INP, \ - 'input' : sino_cut,\ - 'maskData' : Mask,\ - 'regularisation_parameter':6000,\ + 'input' : sino_cut_new,\ + 'maskData' : mask,\ + 'regularisation_parameter':1000,\ 'edge_parameter':0.0,\ - 'number_of_iterations' :5000 ,\ + 'number_of_iterations' :1000 ,\ 'time_marching_parameter':0.000075,\ 'penalty_type':1 } @@ -78,7 +84,7 @@ ndf_inp_linear = NDF_INP(pars['input'], pars['time_marching_parameter'], pars['penalty_type']) -rms = rmse(sinogram, ndf_inp_linear) +rms = rmse(sino_full, ndf_inp_linear) pars['rmse'] = rms txtstr = printParametersToString(pars) @@ -107,8 +113,8 @@ imgplot = plt.imshow(sino_cut,cmap="gray") # set parameters pars = {'algorithm' : NDF_INP, \ - 'input' : sino_cut,\ - 'maskData' : Mask,\ + 'input' : sino_cut_new,\ + 'maskData' : mask,\ 'regularisation_parameter':80,\ 'edge_parameter':0.00009,\ 'number_of_iterations' :1500 ,\ @@ -125,7 +131,7 @@ ndf_inp_nonlinear = NDF_INP(pars['input'], pars['time_marching_parameter'], pars['penalty_type']) -rms = rmse(sinogram, ndf_inp_nonlinear) +rms = rmse(sino_full, ndf_inp_nonlinear) pars['rmse'] = rms txtstr = printParametersToString(pars) -- cgit v1.2.3 From 42a10faa06bd56bff3f0f1804ddcdf1a3e1283cd Mon Sep 17 00:00:00 2001 From: Daniil Kazantsev Date: Tue, 1 May 2018 15:16:49 +0100 Subject: inpaint NVM added --- Wrappers/Python/demos/demo_cpu_inpainters.py | 45 ++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) (limited to 'Wrappers/Python/demos') diff --git a/Wrappers/Python/demos/demo_cpu_inpainters.py b/Wrappers/Python/demos/demo_cpu_inpainters.py index b067b11..ab7ed2f 100644 --- a/Wrappers/Python/demos/demo_cpu_inpainters.py +++ b/Wrappers/Python/demos/demo_cpu_inpainters.py @@ -10,7 +10,7 @@ import numpy as np import os import timeit from scipy import io -from ccpi.filters.regularisers import NDF_INP +from ccpi.filters.regularisers import NDF_INP, NVM_INP from qualitymetrics import rmse ############################################################################### def printParametersToString(pars): @@ -146,4 +146,45 @@ a.text(0.15, 0.25, txtstr, transform=a.transAxes, fontsize=14, verticalalignment='top', bbox=props) imgplot = plt.imshow(ndf_inp_nonlinear, cmap="gray") plt.title('{}'.format('Nonlinear diffusion inpainting results')) -#%% \ No newline at end of file +#%% +print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") +print ("Inpainting using nonlocal vertical marching") +print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") + +## plot +fig = plt.figure(4) +plt.suptitle('Performance of NVM inpainting using the CPU') +a=fig.add_subplot(1,2,1) +a.set_title('Missing data sinogram') +imgplot = plt.imshow(sino_cut,cmap="gray") + +# set parameters +pars = {'algorithm' : NVM_INP, \ + 'input' : sino_cut_new,\ + 'maskData' : mask,\ + 'SW_increment': 1,\ + 'number_of_iterations' :20 + } + +start_time = timeit.default_timer() +nvm_inp = NVM_INP(pars['input'], + pars['maskData'], + pars['SW_increment'], + pars['number_of_iterations']) + +rms = rmse(sino_full, nvm_inp) +pars['rmse'] = rms + +txtstr = printParametersToString(pars) +txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time) +print (txtstr) +a=fig.add_subplot(1,2,2) + +# these are matplotlib.patch.Patch properties +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(nvm_inp, cmap="gray") +plt.title('{}'.format('Nonlocal Vertical Marching inpainting results')) +#%% -- cgit v1.2.3 From c4f50db4f5b318aad785ae577908d37fe05f53d2 Mon Sep 17 00:00:00 2001 From: algol Date: Tue, 1 May 2018 15:30:28 +0100 Subject: some updates in demo --- Wrappers/Python/demos/demo_cpu_inpainters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Wrappers/Python/demos') diff --git a/Wrappers/Python/demos/demo_cpu_inpainters.py b/Wrappers/Python/demos/demo_cpu_inpainters.py index ab7ed2f..9a677c4 100644 --- a/Wrappers/Python/demos/demo_cpu_inpainters.py +++ b/Wrappers/Python/demos/demo_cpu_inpainters.py @@ -167,7 +167,7 @@ pars = {'algorithm' : NVM_INP, \ } start_time = timeit.default_timer() -nvm_inp = NVM_INP(pars['input'], +(nvm_inp, mask_upd) = NVM_INP(pars['input'], pars['maskData'], pars['SW_increment'], pars['number_of_iterations']) -- cgit v1.2.3 From 73965b6b80c49a2867d54e4a42f3069fe35d9cc6 Mon Sep 17 00:00:00 2001 From: algol Date: Wed, 2 May 2018 09:47:58 +0100 Subject: corrections to dimens issues --- Wrappers/Python/demos/demo_cpu_inpainters.py | 18 ++++++++++-------- Wrappers/Python/demos/demo_cpu_regularisers.py | 17 +++++++++++++++++ Wrappers/Python/demos/demo_gpu_regularisers.py | 16 ++++++++++++++++ 3 files changed, 43 insertions(+), 8 deletions(-) (limited to 'Wrappers/Python/demos') diff --git a/Wrappers/Python/demos/demo_cpu_inpainters.py b/Wrappers/Python/demos/demo_cpu_inpainters.py index 9a677c4..348d235 100644 --- a/Wrappers/Python/demos/demo_cpu_inpainters.py +++ b/Wrappers/Python/demos/demo_cpu_inpainters.py @@ -37,12 +37,14 @@ Mask = sino.get('Mask') sino_full = sino_full/np.max(sino_full) #apply mask to sinogram sino_cut = sino_full*(1-Mask) -sino_cut_new = np.zeros((angles_dim,detectors_dim),'float32') +#sino_cut_new = np.zeros((angles_dim,detectors_dim),'float32') #sino_cut_new = sino_cut.copy(order='c') -sino_cut_new[:] = sino_cut[:] -mask = np.zeros((angles_dim,detectors_dim),'uint8') +#sino_cut_new[:] = sino_cut[:] +sino_cut_new = np.ascontiguousarray(sino_cut, dtype=np.float32); +#mask = np.zeros((angles_dim,detectors_dim),'uint8') #mask =Mask.copy(order='c') -mask[:] = Mask[:] +#mask[:] = Mask[:] +mask = np.ascontiguousarray(Mask, dtype=np.uint8); plt.figure(1) plt.subplot(121) @@ -68,11 +70,11 @@ imgplot = plt.imshow(sino_cut_new,cmap="gray") pars = {'algorithm' : NDF_INP, \ 'input' : sino_cut_new,\ 'maskData' : mask,\ - 'regularisation_parameter':1000,\ - 'edge_parameter':0.0,\ + 'regularisation_parameter':5000,\ + 'edge_parameter':0,\ 'number_of_iterations' :1000 ,\ 'time_marching_parameter':0.000075,\ - 'penalty_type':1 + 'penalty_type':0 } start_time = timeit.default_timer() @@ -163,7 +165,7 @@ pars = {'algorithm' : NVM_INP, \ 'input' : sino_cut_new,\ 'maskData' : mask,\ 'SW_increment': 1,\ - 'number_of_iterations' :20 + 'number_of_iterations' :0 } start_time = timeit.default_timer() diff --git a/Wrappers/Python/demos/demo_cpu_regularisers.py b/Wrappers/Python/demos/demo_cpu_regularisers.py index 3567f91..f803870 100644 --- a/Wrappers/Python/demos/demo_cpu_regularisers.py +++ b/Wrappers/Python/demos/demo_cpu_regularisers.py @@ -50,7 +50,24 @@ u_ref = Im + np.random.normal(loc = 0 , u0 = u0.astype('float32') u_ref = u_ref.astype('float32') +# change dims to check that modules work with non-squared images +(N,M) = np.shape(u0) +u_ref2 = np.zeros([N,M-100],dtype='float32') +u_ref2[:,0:M-100] = u_ref[:,0:M-100] +u_ref = u_ref2 +del u_ref2 + +u02 = np.zeros([N,M-100],dtype='float32') +u02[:,0:M-100] = u0[:,0:M-100] +u0 = u02 +del u02 + +Im2 = np.zeros([N,M-100],dtype='float32') +Im2[:,0:M-100] = Im[:,0:M-100] +Im = Im2 +del Im2 +#%% print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") print ("_______________ROF-TV (2D)_________________") print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") diff --git a/Wrappers/Python/demos/demo_gpu_regularisers.py b/Wrappers/Python/demos/demo_gpu_regularisers.py index b873700..dfdceee 100644 --- a/Wrappers/Python/demos/demo_gpu_regularisers.py +++ b/Wrappers/Python/demos/demo_gpu_regularisers.py @@ -49,6 +49,22 @@ u_ref = Im + np.random.normal(loc = 0 , u0 = u0.astype('float32') u_ref = u_ref.astype('float32') +(N,M) = np.shape(u0) +u_ref2 = np.zeros([N,M-100],dtype='float32') +u_ref2[:,0:M-100] = u_ref[:,0:M-100] +u_ref = u_ref2 +del u_ref2 + +u02 = np.zeros([N,M-100],dtype='float32') +u02[:,0:M-100] = u0[:,0:M-100] +u0 = u02 +del u02 + +Im2 = np.zeros([N,M-100],dtype='float32') +Im2[:,0:M-100] = Im[:,0:M-100] +Im = Im2 +del Im2 + print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") print ("____________ROF-TV regulariser_____________") print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") -- cgit v1.2.3 From 985fee04ac1abef2aaa69f282ae6c207e438b4af Mon Sep 17 00:00:00 2001 From: algol Date: Wed, 2 May 2018 11:01:57 +0100 Subject: bugs in cython files --- Wrappers/Python/demos/demo_cpu_inpainters.py | 2 +- Wrappers/Python/demos/demo_cpu_regularisers.py | 40 +++++++++++--------------- Wrappers/Python/demos/demo_gpu_regularisers.py | 18 ++++++------ 3 files changed, 28 insertions(+), 32 deletions(-) (limited to 'Wrappers/Python/demos') diff --git a/Wrappers/Python/demos/demo_cpu_inpainters.py b/Wrappers/Python/demos/demo_cpu_inpainters.py index 348d235..7f452c1 100644 --- a/Wrappers/Python/demos/demo_cpu_inpainters.py +++ b/Wrappers/Python/demos/demo_cpu_inpainters.py @@ -72,7 +72,7 @@ pars = {'algorithm' : NDF_INP, \ 'maskData' : mask,\ 'regularisation_parameter':5000,\ 'edge_parameter':0,\ - 'number_of_iterations' :1000 ,\ + 'number_of_iterations' :5000 ,\ 'time_marching_parameter':0.000075,\ 'penalty_type':0 } diff --git a/Wrappers/Python/demos/demo_cpu_regularisers.py b/Wrappers/Python/demos/demo_cpu_regularisers.py index f803870..986e3e9 100644 --- a/Wrappers/Python/demos/demo_cpu_regularisers.py +++ b/Wrappers/Python/demos/demo_cpu_regularisers.py @@ -44,29 +44,30 @@ u0 = Im + np.random.normal(loc = 0 , u_ref = Im + np.random.normal(loc = 0 , scale = 0.01 * Im , size = np.shape(Im)) - +(N,M) = np.shape(u0) # map the u0 u0->u0>0 # f = np.frompyfunc(lambda x: 0 if x < 0 else x, 1,1) u0 = u0.astype('float32') u_ref = u_ref.astype('float32') # change dims to check that modules work with non-squared images -(N,M) = np.shape(u0) -u_ref2 = np.zeros([N,M-100],dtype='float32') -u_ref2[:,0:M-100] = u_ref[:,0:M-100] +""" +M = M-100 +u_ref2 = np.zeros([N,M],dtype='float32') +u_ref2[:,0:M] = u_ref[:,0:M] u_ref = u_ref2 del u_ref2 -u02 = np.zeros([N,M-100],dtype='float32') -u02[:,0:M-100] = u0[:,0:M-100] +u02 = np.zeros([N,M],dtype='float32') +u02[:,0:M] = u0[:,0:M] u0 = u02 del u02 -Im2 = np.zeros([N,M-100],dtype='float32') -Im2[:,0:M-100] = Im[:,0:M-100] +Im2 = np.zeros([N,M],dtype='float32') +Im2[:,0:M] = Im[:,0:M] Im = Im2 del Im2 - +""" #%% print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") print ("_______________ROF-TV (2D)_________________") @@ -305,7 +306,6 @@ a.text(0.15, 0.25, txtstr, transform=a.transAxes, fontsize=14, imgplot = plt.imshow(fgp_dtv_cpu, cmap="gray") plt.title('{}'.format('CPU results')) - print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") print ("__________Total nuclear Variation__________") print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") @@ -318,9 +318,8 @@ a.set_title('Noisy Image') imgplot = plt.imshow(u0,cmap="gray") channelsNo = 5 -N = 512 -noisyVol = np.zeros((channelsNo,N,N),dtype='float32') -idealVol = np.zeros((channelsNo,N,N),dtype='float32') +noisyVol = np.zeros((channelsNo,N,M),dtype='float32') +idealVol = np.zeros((channelsNo,N,M),dtype='float32') for i in range (channelsNo): noisyVol[i,:,:] = Im + np.random.normal(loc = 0 , scale = perc * Im , size = np.shape(Im)) @@ -361,25 +360,19 @@ plt.title('{}'.format('CPU results')) # Uncomment to test 3D regularisation performance #%% """ -N = 512 slices = 20 - -filename = os.path.join(".." , ".." , ".." , "data" ,"lena_gray_512.tif") -Im = plt.imread(filename) -Im = np.asarray(Im, dtype='float32') - -Im = Im/255 perc = 0.05 -noisyVol = np.zeros((slices,N,N),dtype='float32') -noisyRef = np.zeros((slices,N,N),dtype='float32') -idealVol = np.zeros((slices,N,N),dtype='float32') +noisyVol = np.zeros((slices,N,M),dtype='float32') +noisyRef = np.zeros((slices,N,M),dtype='float32') +idealVol = np.zeros((slices,N,M),dtype='float32') for i in range (slices): noisyVol[i,:,:] = Im + np.random.normal(loc = 0 , scale = perc * Im , size = np.shape(Im)) noisyRef[i,:,:] = Im + np.random.normal(loc = 0 , scale = 0.01 * Im , size = np.shape(Im)) idealVol[i,:,:] = Im + print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") print ("_______________ROF-TV (3D)_________________") print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") @@ -420,6 +413,7 @@ a.text(0.15, 0.25, txtstr, transform=a.transAxes, fontsize=14, imgplot = plt.imshow(rof_cpu3D[10,:,:], cmap="gray") plt.title('{}'.format('Recovered volume on the CPU using ROF-TV')) + print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") print ("_______________FGP-TV (3D)__________________") print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") diff --git a/Wrappers/Python/demos/demo_gpu_regularisers.py b/Wrappers/Python/demos/demo_gpu_regularisers.py index dfdceee..f3ed50c 100644 --- a/Wrappers/Python/demos/demo_gpu_regularisers.py +++ b/Wrappers/Python/demos/demo_gpu_regularisers.py @@ -44,26 +44,28 @@ u0 = Im + np.random.normal(loc = 0 , u_ref = Im + np.random.normal(loc = 0 , scale = 0.01 * Im , size = np.shape(Im)) +(N,M) = np.shape(u0) # map the u0 u0->u0>0 # f = np.frompyfunc(lambda x: 0 if x < 0 else x, 1,1) u0 = u0.astype('float32') u_ref = u_ref.astype('float32') - -(N,M) = np.shape(u0) -u_ref2 = np.zeros([N,M-100],dtype='float32') -u_ref2[:,0:M-100] = u_ref[:,0:M-100] +""" +M = M-100 +u_ref2 = np.zeros([N,M],dtype='float32') +u_ref2[:,0:M] = u_ref[:,0:M] u_ref = u_ref2 del u_ref2 -u02 = np.zeros([N,M-100],dtype='float32') -u02[:,0:M-100] = u0[:,0:M-100] +u02 = np.zeros([N,M],dtype='float32') +u02[:,0:M] = u0[:,0:M] u0 = u02 del u02 -Im2 = np.zeros([N,M-100],dtype='float32') -Im2[:,0:M-100] = Im[:,0:M-100] +Im2 = np.zeros([N,M],dtype='float32') +Im2[:,0:M] = Im[:,0:M] Im = Im2 del Im2 +""" print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") print ("____________ROF-TV regulariser_____________") -- cgit v1.2.3 From 14edd18d07c871c0a355d70e68350a899014dbc7 Mon Sep 17 00:00:00 2001 From: algol Date: Wed, 2 May 2018 13:11:50 +0100 Subject: bugs in NVM fixed --- Wrappers/Python/demos/demo_cpu_inpainters.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'Wrappers/Python/demos') diff --git a/Wrappers/Python/demos/demo_cpu_inpainters.py b/Wrappers/Python/demos/demo_cpu_inpainters.py index 7f452c1..9197e91 100644 --- a/Wrappers/Python/demos/demo_cpu_inpainters.py +++ b/Wrappers/Python/demos/demo_cpu_inpainters.py @@ -55,6 +55,7 @@ plt.imshow(mask) plt.title('Mask') plt.show() #%% +""" print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") print ("___Inpainting using linear diffusion (2D)__") print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") @@ -111,7 +112,7 @@ fig = plt.figure(3) plt.suptitle('Performance of nonlinear diffusion inpainting using the CPU') a=fig.add_subplot(1,2,1) a.set_title('Missing data sinogram') -imgplot = plt.imshow(sino_cut,cmap="gray") +imgplot = plt.imshow(sino_cut_new,cmap="gray") # set parameters pars = {'algorithm' : NDF_INP, \ @@ -148,6 +149,7 @@ a.text(0.15, 0.25, txtstr, transform=a.transAxes, fontsize=14, verticalalignment='top', bbox=props) imgplot = plt.imshow(ndf_inp_nonlinear, cmap="gray") plt.title('{}'.format('Nonlinear diffusion inpainting results')) +""" #%% print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") print ("Inpainting using nonlocal vertical marching") @@ -165,7 +167,7 @@ pars = {'algorithm' : NVM_INP, \ 'input' : sino_cut_new,\ 'maskData' : mask,\ 'SW_increment': 1,\ - 'number_of_iterations' :0 + 'number_of_iterations' : 150 } start_time = timeit.default_timer() -- cgit v1.2.3 From 6e285c109938a43b5f8a84b7a48afaeb6b058c90 Mon Sep 17 00:00:00 2001 From: algol Date: Wed, 2 May 2018 15:43:55 +0100 Subject: demo inpainters fixed for python --- Wrappers/Python/demos/demo_cpu_inpainters.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'Wrappers/Python/demos') diff --git a/Wrappers/Python/demos/demo_cpu_inpainters.py b/Wrappers/Python/demos/demo_cpu_inpainters.py index 9197e91..3b4191b 100644 --- a/Wrappers/Python/demos/demo_cpu_inpainters.py +++ b/Wrappers/Python/demos/demo_cpu_inpainters.py @@ -55,7 +55,6 @@ plt.imshow(mask) plt.title('Mask') plt.show() #%% -""" print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") print ("___Inpainting using linear diffusion (2D)__") print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") @@ -149,7 +148,6 @@ a.text(0.15, 0.25, txtstr, transform=a.transAxes, fontsize=14, verticalalignment='top', bbox=props) imgplot = plt.imshow(ndf_inp_nonlinear, cmap="gray") plt.title('{}'.format('Nonlinear diffusion inpainting results')) -""" #%% print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") print ("Inpainting using nonlocal vertical marching") -- cgit v1.2.3