summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniil Kazantsev <dkazanc@hotmail.com>2018-05-02 15:47:19 +0100
committerDaniil Kazantsev <dkazanc@hotmail.com>2018-05-02 15:47:19 +0100
commit37ae2bdb0a15298f312e9f6545a465d4d20c57f1 (patch)
treeab57969c171b7bbb6f0c4cb5e7b8d7feb71a0721
parent14edd18d07c871c0a355d70e68350a899014dbc7 (diff)
downloadregularization-37ae2bdb0a15298f312e9f6545a465d4d20c57f1.tar.gz
regularization-37ae2bdb0a15298f312e9f6545a465d4d20c57f1.tar.bz2
regularization-37ae2bdb0a15298f312e9f6545a465d4d20c57f1.tar.xz
regularization-37ae2bdb0a15298f312e9f6545a465d4d20c57f1.zip
bugs of NVM are fixed
-rw-r--r--Core/inpainters_CPU/NonlocalMarching_Inpaint_core.c100
-rw-r--r--Core/inpainters_CPU/NonlocalMarching_Inpaint_core.h2
-rw-r--r--Wrappers/Matlab/mex_compile/regularisers_CPU/NonlocalMarching_Inpaint.c2
-rw-r--r--Wrappers/Python/src/cpu_regularisers.pyx4
4 files changed, 54 insertions, 54 deletions
diff --git a/Core/inpainters_CPU/NonlocalMarching_Inpaint_core.c b/Core/inpainters_CPU/NonlocalMarching_Inpaint_core.c
index a197375..66be15c 100644
--- a/Core/inpainters_CPU/NonlocalMarching_Inpaint_core.c
+++ b/Core/inpainters_CPU/NonlocalMarching_Inpaint_core.c
@@ -30,7 +30,7 @@
* 1. 2D image or sinogram with horizontal or inclined regions of missing data
* 2. Mask of the same size as A in 'unsigned char' format (ones mark the region to inpaint, zeros belong to the data)
* 3. Linear increment to increase searching window size in iterations, values from 1-3 is a good choice
-
+ *
* Output:
* 1. Inpainted image or a sinogram
* 2. updated mask
@@ -38,11 +38,11 @@
* Reference: TBA
*/
-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)
+float NonlocalMarching_Inpaint_main(float *Input, unsigned char *M, float *Output, unsigned char *M_upd, int SW_increment, int iterationsNumb, int trigger, int dimX, int dimY, int dimZ)
{
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;
+ }
+ if ((int)(iterations_number/dimY) > dimX) iterations_number = dimX;
}
- else iterations_number = iterationsNumb;
-
+ else iterations_number = iterationsNumb;
+
if (iterations_number == 0) printf("%s \n", "Nothing to inpaint, zero mask!");
else {
@@ -83,54 +83,54 @@ float NonlocalMarching_Inpaint_main(float *Input, unsigned char *M, float *Outpu
}
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(i=0; i<dimX; i++) {
- switchmask = 0;
+ /*Matlab*/
+#pragma omp parallel for shared(Output, M_upd, Gauss_weights) private(i, j, switchmask, switchcurr)
for(j=0; j<dimY; j++) {
- 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;
+ 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;
+ }
}
- 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, j-1, dimX, dimY, W_halfsize, W_fullsize);
- /* add value to the mask*/
- M_upd[(j-1)*dimX + i] = 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(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 */
+ 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 (j-1) pixel */
+ inpaint_func(Output, M_upd, Gauss_weights, i, j-1, dimX, dimY, W_halfsize, W_fullsize);
+ /* add value to the mask*/
+ M_upd[(j-1)*dimX + i] = 0;
+ switchmask = 0;
+ }
}
}
}
- }
free(Gauss_weights);
/* check if possible to terminate iterations earlier */
diff --git a/Core/inpainters_CPU/NonlocalMarching_Inpaint_core.h b/Core/inpainters_CPU/NonlocalMarching_Inpaint_core.h
index 199820c..0f99ed4 100644
--- a/Core/inpainters_CPU/NonlocalMarching_Inpaint_core.h
+++ b/Core/inpainters_CPU/NonlocalMarching_Inpaint_core.h
@@ -47,7 +47,7 @@ limitations under the License.
#ifdef __cplusplus
extern "C" {
#endif
-CCPI_EXPORT 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);
+CCPI_EXPORT float NonlocalMarching_Inpaint_main(float *Input, unsigned char *M, float *Output, unsigned char *M_upd, int SW_increment, int iterationsNumb, int trigger, int dimX, int dimY, int dimZ);
CCPI_EXPORT float inpaint_func(float *U, unsigned char *M_upd, float *Gauss_weights, int i, int j, int dimX, int dimY, int W_halfsize, int W_fullsize);
#ifdef __cplusplus
}
diff --git a/Wrappers/Matlab/mex_compile/regularisers_CPU/NonlocalMarching_Inpaint.c b/Wrappers/Matlab/mex_compile/regularisers_CPU/NonlocalMarching_Inpaint.c
index 5e4ab1f..36cf05c 100644
--- a/Wrappers/Matlab/mex_compile/regularisers_CPU/NonlocalMarching_Inpaint.c
+++ b/Wrappers/Matlab/mex_compile/regularisers_CPU/NonlocalMarching_Inpaint.c
@@ -78,5 +78,5 @@ void mexFunction(
if (number_of_dims == 3) {
mexErrMsgTxt("Currently 2D supported only");
}
- NonlocalMarching_Inpaint_main(Input, Mask, Output, Mask_upd, SW_increment, iterations, dimX, dimY, dimZ);
+ NonlocalMarching_Inpaint_main(Input, Mask, Output, Mask_upd, SW_increment, iterations, 0, dimX, dimY, dimZ);
} \ No newline at end of file
diff --git a/Wrappers/Python/src/cpu_regularisers.pyx b/Wrappers/Python/src/cpu_regularisers.pyx
index 732b4cb..c934f1d 100644
--- a/Wrappers/Python/src/cpu_regularisers.pyx
+++ b/Wrappers/Python/src/cpu_regularisers.pyx
@@ -26,7 +26,7 @@ cdef extern float TNV_CPU_main(float *Input, float *u, float lambdaPar, int maxI
cdef extern float dTV_FGP_CPU_main(float *Input, float *InputRef, float *Output, float lambdaPar, int iterationsNumb, float epsil, float eta, int methodTV, int nonneg, int printM, int dimX, int dimY, int dimZ);
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);
+cdef extern float NonlocalMarching_Inpaint_main(float *Input, unsigned char *M, float *Output, unsigned char *M_upd, int SW_increment, int iterationsNumb, int trigger, int dimX, int dimY, int dimZ);
#****************************************************************#
#********************** Total-variation ROF *********************#
#****************************************************************#
@@ -396,6 +396,6 @@ def NVM_INP_2D(np.ndarray[np.float32_t, ndim=2, mode="c"] inputData,
# 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)
+ SW_increment, iterationsNumb, 1, dims[1], dims[0], 1)
return (outputData, maskData_upd)