diff options
author | Daniil Kazantsev <dkazanc3@googlemail.com> | 2019-04-15 15:42:29 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-15 15:42:29 +0100 |
commit | 6040e1e1f501f501e8da628b065fd16d35133519 (patch) | |
tree | 3aa1382838ce6b9b856ace373f1d864683f10277 /src/Python | |
parent | d882861f8cfc59ffe70aa2f286dda83b348d7a70 (diff) | |
parent | e6842ec7f2cdbd46a004758bc3a6543012c6a74a (diff) | |
download | regularization-6040e1e1f501f501e8da628b065fd16d35133519.tar.gz regularization-6040e1e1f501f501e8da628b065fd16d35133519.tar.bz2 regularization-6040e1e1f501f501e8da628b065fd16d35133519.tar.xz regularization-6040e1e1f501f501e8da628b065fd16d35133519.zip |
Merge pull request #117 from vais-ral/diffcon
Connected labels merging function
Diffstat (limited to 'src/Python')
-rw-r--r-- | src/Python/ccpi/filters/regularisers.py | 14 | ||||
-rw-r--r-- | src/Python/src/cpu_regularisers.pyx | 34 |
2 files changed, 47 insertions, 1 deletions
diff --git a/src/Python/ccpi/filters/regularisers.py b/src/Python/ccpi/filters/regularisers.py index 398e11c..2fee8b3 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, Diff4th_CPU, TGV_CPU, LLT_ROF_CPU, PATCHSEL_CPU, NLTV_CPU, MASK_CORR_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 @@ -212,3 +212,15 @@ def NDF_INP(inputData, maskData, regularisation_parameter, edge_parameter, itera def NVM_INP(inputData, maskData, SW_increment, iterations): return NVM_INPAINT_CPU(inputData, maskData, SW_increment, iterations) + +def MASK_CORR(maskdata, select_classes, total_classesNum, CorrectionWindow, device='cpu'): + if device == 'cpu': + return MASK_CORR_CPU(maskdata, select_classes, total_classesNum, CorrectionWindow) + elif device == 'gpu' and gpu_enabled: + return MASK_CORR_CPU(maskdata, select_classes, total_classesNum, CorrectionWindow) + 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)) + diff --git a/src/Python/src/cpu_regularisers.pyx b/src/Python/src/cpu_regularisers.pyx index add641b..a63ecfa 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 Mask_merge_main(unsigned char *MASK, unsigned char *MASK_upd, unsigned char *CORRECTEDRegions, unsigned char *SelClassesList, int SelClassesList_length, int classesNumb, int CorrectionWindow, 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,7 @@ def NDF_3D(np.ndarray[np.float32_t, ndim=3, mode="c"] inputData, tolerance_param, dims[2], dims[1], dims[0]) return (outputData,infovec) + #****************************************************************# #*************Anisotropic Fourth-Order diffusion*****************# #****************************************************************# @@ -692,6 +694,38 @@ def NVM_INP_2D(np.ndarray[np.float32_t, ndim=2, mode="c"] inputData, return (outputData, maskData_upd) +############################################################################## +#****************************************************************# +#********Mask (segmented image) correction module **************# +#****************************************************************# +def MASK_CORR_CPU(maskData, select_classes, total_classesNum, CorrectionWindow): + if maskData.ndim == 2: + return MASK_CORR_CPU_2D(maskData, select_classes, total_classesNum, CorrectionWindow) + elif maskData.ndim == 3: + return 0 + +def MASK_CORR_CPU_2D(np.ndarray[np.uint8_t, ndim=2, mode="c"] maskData, + np.ndarray[np.uint8_t, ndim=1, mode="c"] select_classes, + int total_classesNum, + int CorrectionWindow): + + cdef long dims[2] + dims[0] = maskData.shape[0] + dims[1] = maskData.shape[1] + + select_classes_length = select_classes.shape[0] + + cdef np.ndarray[np.uint8_t, ndim=2, mode="c"] mask_upd = \ + np.zeros([dims[0],dims[1]], dtype='uint8') + cdef np.ndarray[np.uint8_t, ndim=2, mode="c"] corr_regions = \ + np.zeros([dims[0],dims[1]], dtype='uint8') + + # Run the function to process given MASK + Mask_merge_main(&maskData[0,0], &mask_upd[0,0], &corr_regions[0,0], &select_classes[0], select_classes_length, + total_classesNum, CorrectionWindow, dims[1], dims[0], 1) + return (mask_upd,corr_regions) + +############################################################################## #****************************************************************# #***************Calculation of TV-energy functional**************# |