diff options
author | Daniil Kazantsev <dkazanc@hotmail.com> | 2018-02-09 16:11:04 +0000 |
---|---|---|
committer | Edoardo Pasca <edo.paskino@gmail.com> | 2018-02-09 16:24:47 +0000 |
commit | d57b398a39d64e2ed8ab7bbc65be5e04f013d5ea (patch) | |
tree | fe57ed1f63ce07eefe7f979acc175caa641d6f9f /Wrappers | |
parent | 821c37c37c60dd76a102867d7a8e8c0d6e06af70 (diff) | |
download | regularization-d57b398a39d64e2ed8ab7bbc65be5e04f013d5ea.tar.gz regularization-d57b398a39d64e2ed8ab7bbc65be5e04f013d5ea.tar.bz2 regularization-d57b398a39d64e2ed8ab7bbc65be5e04f013d5ea.tar.xz regularization-d57b398a39d64e2ed8ab7bbc65be5e04f013d5ea.zip |
GPU regularizers fixed, the demo runs smoothly
Diffstat (limited to 'Wrappers')
-rw-r--r-- | Wrappers/Python/src/gpu_regularizers.pyx | 38 | ||||
-rw-r--r-- | Wrappers/Python/test/test_gpu_regularizers.py | 54 |
2 files changed, 48 insertions, 44 deletions
diff --git a/Wrappers/Python/src/gpu_regularizers.pyx b/Wrappers/Python/src/gpu_regularizers.pyx index dc625c3..84fc30a 100644 --- a/Wrappers/Python/src/gpu_regularizers.pyx +++ b/Wrappers/Python/src/gpu_regularizers.pyx @@ -31,19 +31,22 @@ cdef extern float pad_crop(float *A, float *Ap, int padXY, int switchpad_crop); def Diff4thHajiaboli(inputData, - regularization_parameter, + edge_preserv_parameter, iterations, - edge_preserving_parameter): + time_marching_parameter, + regularization_parameter): if inputData.ndim == 2: return Diff4thHajiaboli2D(inputData, - regularization_parameter, + edge_preserv_parameter, iterations, - edge_preserving_parameter) + time_marching_parameter, + regularization_parameter) elif inputData.ndim == 3: return Diff4thHajiaboli3D(inputData, - regularization_parameter, + edge_preserv_parameter, iterations, - edge_preserving_parameter) + time_marching_parameter, + regularization_parameter) def NML(inputData, SearchW_real, @@ -64,9 +67,10 @@ def NML(inputData, lambdaf) def Diff4thHajiaboli2D(np.ndarray[np.float32_t, ndim=2, mode="c"] inputData, - float regularization_parameter, + float edge_preserv_parameter, int iterations, - float edge_preserving_parameter): + float time_marching_parameter, + float regularization_parameter): cdef long dims[2] dims[0] = inputData.shape[0] @@ -74,9 +78,6 @@ def Diff4thHajiaboli2D(np.ndarray[np.float32_t, ndim=2, mode="c"] inputData, N = dims[0] + 2; M = dims[1] + 2; - #time step is sufficiently small for an explicit methods - tau = 0.01 - #A_L = (float*)mxGetData(mxCreateNumericMatrix(N, M, mxSINGLE_CLASS, mxREAL)); #B_L = (float*)mxGetData(mxCreateNumericMatrix(N, M, mxSINGLE_CLASS, mxREAL)); cdef np.ndarray[np.float32_t, ndim=2, mode="c"] A_L = \ @@ -102,9 +103,9 @@ def Diff4thHajiaboli2D(np.ndarray[np.float32_t, ndim=2, mode="c"] inputData, #<float*> A_L.data, <float*> B_L.data, &A_L[0,0], &B_L[0,0], N, M, 0, - edge_preserving_parameter, + edge_preserv_parameter, iterations , - tau, + time_marching_parameter, regularization_parameter); # copy the processed B_L to a smaller B for i in range(N): @@ -120,9 +121,10 @@ def Diff4thHajiaboli2D(np.ndarray[np.float32_t, ndim=2, mode="c"] inputData, return B def Diff4thHajiaboli3D(np.ndarray[np.float32_t, ndim=3, mode="c"] inputData, - float regularization_parameter, + float edge_preserv_parameter, int iterations, - float edge_preserving_parameter): + float time_marching_parameter, + float regularization_parameter): cdef long dims[3] dims[0] = inputData.shape[0] @@ -132,8 +134,6 @@ def Diff4thHajiaboli3D(np.ndarray[np.float32_t, ndim=3, mode="c"] inputData, M = dims[1] + 2 Z = dims[2] + 2 - # Time Step is small for an explicit methods - tau = 0.0007; #A_L = (float*)mxGetData(mxCreateNumericMatrix(N, M, mxSINGLE_CLASS, mxREAL)); #B_L = (float*)mxGetData(mxCreateNumericMatrix(N, M, mxSINGLE_CLASS, mxREAL)); @@ -162,9 +162,9 @@ def Diff4thHajiaboli3D(np.ndarray[np.float32_t, ndim=3, mode="c"] inputData, #<float*> A_L.data, <float*> B_L.data, &A_L[0,0,0], &B_L[0,0,0], N, M, Z, - edge_preserving_parameter, + edge_preserv_parameter, iterations , - tau, + time_marching_parameter, regularization_parameter); # copy the processed B_L to a smaller B for i in range(N): diff --git a/Wrappers/Python/test/test_gpu_regularizers.py b/Wrappers/Python/test/test_gpu_regularizers.py index 18fbdd3..735a25d 100644 --- a/Wrappers/Python/test/test_gpu_regularizers.py +++ b/Wrappers/Python/test/test_gpu_regularizers.py @@ -40,7 +40,8 @@ filename = os.path.join(".." , ".." , ".." , "data" ,"lena_gray_512.tif") Im = plt.imread(filename) Im = np.asarray(Im, dtype='float32') -perc = 0.15 +Im = Im/255 +perc = 0.075 u0 = Im + np.random.normal(loc = Im , scale = perc * Im , size = np.shape(Im)) @@ -53,49 +54,52 @@ fig = plt.figure() a=fig.add_subplot(2,3,1) a.set_title('noise') -imgplot = plt.imshow(u0#,cmap="gray" - ) +imgplot = plt.imshow(u0,cmap="gray") ## Diff4thHajiaboli start_time = timeit.default_timer() pars = {'algorithm' : Diff4thHajiaboli , \ 'input' : u0, - 'regularization_parameter':0.02 , \ -'number_of_iterations' :150 ,\ -'edge_preserving_parameter':0.001 + 'edge_preserv_parameter':0.1 , \ +'number_of_iterations' :250 ,\ +'time_marching_parameter':0.03 ,\ +'regularization_parameter':0.7 } + + d4h = Diff4thHajiaboli(pars['input'], - pars['regularization_parameter'], + pars['edge_preserv_parameter'], pars['number_of_iterations'], - pars['edge_preserving_parameter']) + pars['time_marching_parameter'], + pars['regularization_parameter']) +rms = rmse(Im, d4h) +pars['rmse'] = rms txtstr = printParametersToString(pars) txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time) print (txtstr) a=fig.add_subplot(2,3,2) # these are matplotlib.patch.Patch properties -props = dict(boxstyle='round', facecolor='wheat', alpha=0.5) +props = dict(boxstyle='round', facecolor='wheat', alpha=0.75) # place a text box in upper left in axes coords -a.text(0.05, 0.95, txtstr, transform=a.transAxes, fontsize=14, +a.text(0.15, 0.25, txtstr, transform=a.transAxes, fontsize=12, verticalalignment='top', bbox=props) -imgplot = plt.imshow(d4h #, cmap="gray" - ) +imgplot = plt.imshow(d4h, cmap="gray") a=fig.add_subplot(2,3,5) # these are matplotlib.patch.Patch properties props = dict(boxstyle='round', facecolor='wheat', alpha=0.5) # place a text box in upper left in axes coords -a.text(0.05, 0.95, 'd4h - u0', transform=a.transAxes, fontsize=14, +a.text(0.05, 0.95, 'd4h - u0', transform=a.transAxes, fontsize=12, verticalalignment='top', bbox=props) -imgplot = plt.imshow(d4h - u0 #, cmap="gray" - ) +imgplot = plt.imshow((d4h - u0)**2, cmap="gray") ## Patch Based Regul NML start_time = timeit.default_timer() - +""" pars = {'algorithm' : NML , \ 'input' : u0, 'SearchW_real':3 , \ @@ -103,13 +107,15 @@ pars = {'algorithm' : NML , \ 'h':0.05 ,# 'lambda' : 0.08 } +""" pars = { 'input' : u0, - 'regularization_parameter': 0.05,\ + 'regularization_parameter': 0.01,\ 'searching_window_ratio':3, \ 'similarity_window_ratio':1,\ - 'PB_filtering_parameter': 0.06 + 'PB_filtering_parameter': 0.2 } + nml = NML(pars['input'], pars['searching_window_ratio'], pars['similarity_window_ratio'], @@ -123,12 +129,11 @@ print (txtstr) a=fig.add_subplot(2,3,3) # these are matplotlib.patch.Patch properties -props = dict(boxstyle='round', facecolor='wheat', alpha=0.5) +props = dict(boxstyle='round', facecolor='wheat', alpha=0.75) # place a text box in upper left in axes coords -a.text(0.05, 0.95, txtstr, transform=a.transAxes, fontsize=14, +a.text(0.15, 0.25, txtstr, transform=a.transAxes, fontsize=12, verticalalignment='top', bbox=props) -imgplot = plt.imshow(nml #, cmap="gray" - ) +imgplot = plt.imshow(nml, cmap="gray") a=fig.add_subplot(2,3,6) @@ -137,8 +142,7 @@ props = dict(boxstyle='round', facecolor='wheat', alpha=0.5) # place a text box in upper left in axes coords a.text(0.05, 0.95, 'nml - u0', transform=a.transAxes, fontsize=14, verticalalignment='top', bbox=props) -imgplot = plt.imshow(nml - u0 #, cmap="gray" - ) +imgplot = plt.imshow((nml - u0)**2, cmap="gray") plt.show() -
\ No newline at end of file + |