diff options
author | algol <dkazanc@hotmail.com> | 2018-05-02 13:11:50 +0100 |
---|---|---|
committer | algol <dkazanc@hotmail.com> | 2018-05-02 13:11:50 +0100 |
commit | 14edd18d07c871c0a355d70e68350a899014dbc7 (patch) | |
tree | 2b6ffc91561a78455931730f9b3a760eebb201ba | |
parent | 7066b1122a11bba244777052b24c103e612f7977 (diff) | |
download | regularization-14edd18d07c871c0a355d70e68350a899014dbc7.tar.gz regularization-14edd18d07c871c0a355d70e68350a899014dbc7.tar.bz2 regularization-14edd18d07c871c0a355d70e68350a899014dbc7.tar.xz regularization-14edd18d07c871c0a355d70e68350a899014dbc7.zip |
bugs in NVM fixed
-rw-r--r-- | Core/inpainters_CPU/NonlocalMarching_Inpaint_core.c | 48 | ||||
-rw-r--r-- | Wrappers/Python/demos/demo_cpu_inpainters.py | 6 | ||||
-rw-r--r-- | Wrappers/Python/src/cpu_regularisers.pyx | 12 |
3 files changed, 48 insertions, 18 deletions
diff --git a/Core/inpainters_CPU/NonlocalMarching_Inpaint_core.c b/Core/inpainters_CPU/NonlocalMarching_Inpaint_core.c index 3a846bb..a197375 100644 --- a/Core/inpainters_CPU/NonlocalMarching_Inpaint_core.c +++ b/Core/inpainters_CPU/NonlocalMarching_Inpaint_core.c @@ -42,7 +42,7 @@ float NonlocalMarching_Inpaint_main(float *Input, unsigned char *M, float *Outpu { int i, j, i_m, j_m, counter, iter, iterations_number, W_fullsize, switchmask, switchcurr, counterElements; float *Gauss_weights; - + /* copying M to M_upd */ copyIm_unchar(M, M_upd, dimX, dimY, 1); @@ -54,11 +54,11 @@ float NonlocalMarching_Inpaint_main(float *Input, unsigned char *M, float *Outpu iterations_number = 0; for (i=0; i<dimY*dimX; i++) { if (M[i] == 1) iterations_number++; - } + } + if ((int)(iterations_number/dimY) > dimX) iterations_number = dimX; } - else iterations_number = (int)(iterationsNumb/dimX); - if (iterations_number > dimX) iterations_number = dimX; - + else iterations_number = iterationsNumb; + if (iterations_number == 0) printf("%s \n", "Nothing to inpaint, zero mask!"); else { @@ -81,11 +81,38 @@ float NonlocalMarching_Inpaint_main(float *Input, unsigned char *M, float *Outpu counter++; } } + + if (trigger == 0) { + /*Matlab*/ + #pragma omp parallel for shared(Output, M_upd, Gauss_weights) private(i, j, switchmask, switchcurr) + for(j=0; j<dimY; j++) { + switchmask = 0; + for(i=0; i<dimX; i++) { + switchcurr = 0; + if ((M_upd[j*dimX + i] == 1) && (switchmask == 0)) { + /* perform inpainting of the current pixel */ + inpaint_func(Output, M_upd, Gauss_weights, i, j, dimX, dimY, W_halfsize, W_fullsize); + /* add value to the mask*/ + M_upd[j*dimX + i] = 0; + switchmask = 1; switchcurr = 1; + } + if ((M_upd[j*dimX + i] == 0) && (switchmask == 1) && (switchcurr == 0)) { + /* perform inpainting of the previous (i-1) pixel */ + inpaint_func(Output, M_upd, Gauss_weights, i-1, j, dimX, dimY, W_halfsize, W_fullsize); + /* add value to the mask*/ + M_upd[(j)*dimX + i-1] = 0; + switchmask = 0; + } + } + } + } + else { + /*Python*/ /* find a point in the mask to inpaint */ #pragma omp parallel for shared(Output, M_upd, Gauss_weights) private(i, j, switchmask, switchcurr) - for(j=0; j<dimY; j++) { - switchmask = 0; - for(i=0; i<dimX; i++) { + for(i=0; i<dimX; i++) { + switchmask = 0; + for(j=0; j<dimY; j++) { switchcurr = 0; if ((M_upd[j*dimX + i] == 1) && (switchmask == 0)) { /* perform inpainting of the current pixel */ @@ -96,13 +123,14 @@ float NonlocalMarching_Inpaint_main(float *Input, unsigned char *M, float *Outpu } if ((M_upd[j*dimX + i] == 0) && (switchmask == 1) && (switchcurr == 0)) { /* perform inpainting of the previous (j-1) pixel */ - inpaint_func(Output, M_upd, Gauss_weights, i-1, j, dimX, dimY, W_halfsize, W_fullsize); + inpaint_func(Output, M_upd, Gauss_weights, i, j-1, dimX, dimY, W_halfsize, W_fullsize); /* add value to the mask*/ - M_upd[(j)*dimX + i-1] = 0; + M_upd[(j-1)*dimX + i] = 0; switchmask = 0; } } } + } free(Gauss_weights); /* check if possible to terminate iterations earlier */ 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() diff --git a/Wrappers/Python/src/cpu_regularisers.pyx b/Wrappers/Python/src/cpu_regularisers.pyx index 7c06c28..732b4cb 100644 --- a/Wrappers/Python/src/cpu_regularisers.pyx +++ b/Wrappers/Python/src/cpu_regularisers.pyx @@ -27,7 +27,6 @@ cdef extern float dTV_FGP_CPU_main(float *Input, float *InputRef, float *Output, cdef extern float Diffusion_Inpaint_CPU_main(float *Input, unsigned char *Mask, float *Output, float lambdaPar, float sigmaPar, int iterationsNumb, float tau, int penaltytype, int dimX, int dimY, int dimZ); cdef extern float NonlocalMarching_Inpaint_main(float *Input, unsigned char *M, float *Output, unsigned char *M_upd, int SW_increment, int iterationsNumb, int dimX, int dimY, int dimZ); - #****************************************************************# #********************** Total-variation ROF *********************# #****************************************************************# @@ -374,14 +373,14 @@ def NDF_INP_3D(np.ndarray[np.float32_t, ndim=3, mode="c"] inputData, #*********************Inpainting WITH****************************# #***************Nonlocal Vertical Marching method****************# #****************************************************************# -def NVM_INPAINT_CPU(inputData, maskData, SW_increment, iterations): +def NVM_INPAINT_CPU(inputData, maskData, SW_increment, iterationsNumb): if inputData.ndim == 2: - return NVM_INP_2D(inputData, maskData, SW_increment, iterations) + return NVM_INP_2D(inputData, maskData, SW_increment, iterationsNumb) elif inputData.ndim == 3: return def NVM_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, int SW_increment, int iterationsNumb): cdef long dims[2] @@ -395,7 +394,8 @@ def NVM_INP_2D(np.ndarray[np.float32_t, ndim=2, mode="c"] inputData, np.zeros([dims[0],dims[1]], dtype='uint8') # Run Inpaiting by Nonlocal vertical marching method for 2D data - NonlocalMarching_Inpaint_main(&inputData[0,0], &maskData[0,0], &outputData[0,0], &maskData_upd[0,0], - SW_increment, iterationsNumb,dims[1], dims[0], 1) + NonlocalMarching_Inpaint_main(&inputData[0,0], &maskData[0,0], &outputData[0,0], + &maskData_upd[0,0], + SW_increment, iterationsNumb, dims[1], dims[0], 1) return (outputData, maskData_upd) |