diff options
-rw-r--r-- | Wrappers/Python/demos/demo_cpu_inpainters.py | 18 | ||||
-rw-r--r-- | Wrappers/Python/demos/demo_cpu_regularisers.py | 17 | ||||
-rw-r--r-- | Wrappers/Python/demos/demo_gpu_regularisers.py | 16 | ||||
-rw-r--r-- | Wrappers/Python/src/cpu_regularisers.pyx | 10 |
4 files changed, 49 insertions, 12 deletions
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 ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") diff --git a/Wrappers/Python/src/cpu_regularisers.pyx b/Wrappers/Python/src/cpu_regularisers.pyx index 52befd7..21a1a00 100644 --- a/Wrappers/Python/src/cpu_regularisers.pyx +++ b/Wrappers/Python/src/cpu_regularisers.pyx @@ -49,7 +49,7 @@ def TV_ROF_2D(np.ndarray[np.float32_t, ndim=2, mode="c"] inputData, np.zeros([dims[0],dims[1]], dtype='float32') # Run ROF iterations for 2D data - TV_ROF_CPU_main(&inputData[0,0], &outputData[0,0], regularisation_parameter, iterationsNumb, marching_step_parameter, dims[0], dims[1], 1) + TV_ROF_CPU_main(&inputData[0,0], &outputData[0,0], regularisation_parameter, iterationsNumb, marching_step_parameter, dims[1], dims[0], 1) return outputData @@ -333,18 +333,20 @@ def NDF_INPAINT_CPU(inputData, maskData, regularisation_parameter, edge_paramete return NDF_INP_3D(inputData, maskData, regularisation_parameter, edge_parameter, iterationsNumb, time_marching_parameter, penalty_type) def NDF_INP_2D(np.ndarray[np.float32_t, ndim=2, mode="c"] inputData, - np.ndarray[np.uint8_t, ndim=2, mode="c"] maskData, + np.ndarray[np.uint8_t, ndim=2, mode="c"] maskData, float regularisation_parameter, float edge_parameter, int iterationsNumb, float time_marching_parameter, int penalty_type): + cdef long dims[2] dims[0] = inputData.shape[0] dims[1] = inputData.shape[1] - + + cdef np.ndarray[np.float32_t, ndim=2, mode="c"] outputData = \ - np.zeros([dims[0],dims[1]], dtype='float32') + np.zeros([dims[0],dims[1]], dtype='float32') # Run Inpaiting by Diffusion iterations for 2D data Diffusion_Inpaint_CPU_main(&inputData[0,0], &maskData[0,0], &outputData[0,0], regularisation_parameter, edge_parameter, iterationsNumb, time_marching_parameter, penalty_type, dims[0], dims[1], 1) |