diff options
author | dkazanc <dkazanc@hotmail.com> | 2019-04-09 16:44:39 +0100 |
---|---|---|
committer | dkazanc <dkazanc@hotmail.com> | 2019-04-09 16:44:39 +0100 |
commit | d6ee5585e696f855d1c687d34efa04328729e94c (patch) | |
tree | 5ff04822b93d69a37a9cfce8a2e473ebc9d0ef18 /src/Python | |
parent | d882861f8cfc59ffe70aa2f286dda83b348d7a70 (diff) | |
download | regularization-d6ee5585e696f855d1c687d34efa04328729e94c.tar.gz regularization-d6ee5585e696f855d1c687d34efa04328729e94c.tar.bz2 regularization-d6ee5585e696f855d1c687d34efa04328729e94c.tar.xz regularization-d6ee5585e696f855d1c687d34efa04328729e94c.zip |
2D CPU version for constrained diffusion
Diffstat (limited to 'src/Python')
-rw-r--r-- | src/Python/ccpi/filters/regularisers.py | 27 | ||||
-rw-r--r-- | src/Python/src/cpu_regularisers.pyx | 37 |
2 files changed, 63 insertions, 1 deletions
diff --git a/src/Python/ccpi/filters/regularisers.py b/src/Python/ccpi/filters/regularisers.py index 398e11c..1e427bf 100644 --- a/src/Python/ccpi/filters/regularisers.py +++ b/src/Python/ccpi/filters/regularisers.py @@ -2,7 +2,7 @@ script which assigns a proper device core function based on a flag ('cpu' or 'gpu') """ -from ccpi.filters.cpu_regularisers import TV_ROF_CPU, TV_FGP_CPU, TV_SB_CPU, dTV_FGP_CPU, TNV_CPU, NDF_CPU, Diff4th_CPU, TGV_CPU, LLT_ROF_CPU, PATCHSEL_CPU, NLTV_CPU +from ccpi.filters.cpu_regularisers import TV_ROF_CPU, TV_FGP_CPU, TV_SB_CPU, dTV_FGP_CPU, TNV_CPU, NDF_CPU, NDF_MASK_CPU, Diff4th_CPU, TGV_CPU, LLT_ROF_CPU, PATCHSEL_CPU, NLTV_CPU try: from ccpi.filters.gpu_regularisers import TV_ROF_GPU, TV_FGP_GPU, TV_SB_GPU, dTV_FGP_GPU, NDF_GPU, Diff4th_GPU, TGV_GPU, LLT_ROF_GPU, PATCHSEL_GPU gpu_enabled = True @@ -127,6 +127,31 @@ def NDF(inputData, regularisation_parameter, edge_parameter, iterations, raise ValueError ('GPU is not available') raise ValueError('Unknown device {0}. Expecting gpu or cpu'\ .format(device)) +def NDF_MASK(inputData, diffuswindow, regularisation_parameter, edge_parameter, iterations, + time_marching_parameter, penalty_type, tolerance_param, device='cpu'): + if device == 'cpu': + return NDF_MASK_CPU(inputData, + diffuswindow, + regularisation_parameter, + edge_parameter, + iterations, + time_marching_parameter, + penalty_type, + tolerance_param) + elif device == 'gpu' and gpu_enabled: + return NDF_MASK_CPU(inputData, + diffuswindow, + regularisation_parameter, + edge_parameter, + iterations, + time_marching_parameter, + penalty_type, + tolerance_param) + else: + if not gpu_enabled and device == 'gpu': + raise ValueError ('GPU is not available') + raise ValueError('Unknown device {0}. Expecting gpu or cpu'\ + .format(device)) def Diff4th(inputData, regularisation_parameter, edge_parameter, iterations, time_marching_parameter, tolerance_param, device='cpu'): if device == 'cpu': diff --git a/src/Python/src/cpu_regularisers.pyx b/src/Python/src/cpu_regularisers.pyx index add641b..305ee1f 100644 --- a/src/Python/src/cpu_regularisers.pyx +++ b/src/Python/src/cpu_regularisers.pyx @@ -24,6 +24,7 @@ cdef extern float SB_TV_CPU_main(float *Input, float *Output, float *infovector, cdef extern float LLT_ROF_CPU_main(float *Input, float *Output, float *infovector, float lambdaROF, float lambdaLLT, int iterationsNumb, float tau, float epsil, int dimX, int dimY, int dimZ); cdef extern float TGV_main(float *Input, float *Output, float *infovector, float lambdaPar, float alpha1, float alpha0, int iterationsNumb, float L2, float epsil, int dimX, int dimY, int dimZ); cdef extern float Diffusion_CPU_main(float *Input, float *Output, float *infovector, float lambdaPar, float sigmaPar, int iterationsNumb, float tau, int penaltytype, float epsil, int dimX, int dimY, int dimZ); +cdef extern float DiffusionMASK_CPU_main(float *Input, unsigned char *MASK, float *Output, float *infovector, int DiffusWindow, float lambdaPar, float sigmaPar, int iterationsNumb, float tau, int penaltytype, float epsil, int dimX, int dimY, int dimZ); cdef extern float Diffus4th_CPU_main(float *Input, float *Output, float *infovector, float lambdaPar, float sigmaPar, int iterationsNumb, float tau, float epsil, int dimX, int dimY, int dimZ); cdef extern float dTV_FGP_CPU_main(float *Input, float *InputRef, float *Output, float *infovector, float lambdaPar, int iterationsNumb, float epsil, float eta, int methodTV, int nonneg, int dimX, int dimY, int dimZ); cdef extern float TNV_CPU_main(float *Input, float *u, float lambdaPar, int maxIter, float tol, int dimX, int dimY, int dimZ); @@ -379,6 +380,42 @@ def NDF_3D(np.ndarray[np.float32_t, ndim=3, mode="c"] inputData, tolerance_param, dims[2], dims[1], dims[0]) return (outputData,infovec) + +#****************************************************************# +#********Constrained Nonlinear(Isotropic) Diffusion**************# +#****************************************************************# +def NDF_MASK_CPU(inputData, maskData, diffuswindow, regularisation_parameter, edge_parameter, iterationsNumb,time_marching_parameter, penalty_type, tolerance_param): + if inputData.ndim == 2: + return NDF_MASK_2D(inputData, maskData, diffuswindow, regularisation_parameter, edge_parameter, iterationsNumb, time_marching_parameter, penalty_type, tolerance_param) + elif inputData.ndim == 3: + return 0 + +def NDF_MASK_2D(np.ndarray[np.float32_t, ndim=2, mode="c"] inputData, + np.ndarray[np.uint8_t, ndim=2, mode="c"] maskData, + int diffuswindow, + float regularisation_parameter, + float edge_parameter, + int iterationsNumb, + float time_marching_parameter, + int penalty_type, + float tolerance_param): + 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') + cdef np.ndarray[np.float32_t, ndim=1, mode="c"] infovec = \ + np.zeros([2], dtype='float32') + + # Run constrained nonlinear diffusion iterations for 2D data + DiffusionMASK_CPU_main(&inputData[0,0], &maskData[0,0], &outputData[0,0], &infovec[0], + diffuswindow, regularisation_parameter, edge_parameter, iterationsNumb, + time_marching_parameter, penalty_type, + tolerance_param, + dims[1], dims[0], 1) + return (outputData,infovec) + #****************************************************************# #*************Anisotropic Fourth-Order diffusion*****************# #****************************************************************# |