From 9633c5d701c164c3ff8f4d870624f87744d186bd Mon Sep 17 00:00:00 2001 From: Daniil Kazantsev Date: Sat, 16 Mar 2019 23:39:29 +0000 Subject: matlab demos updated --- demos/demoMatlab_3Ddenoise.m | 5 +-- demos/demoMatlab_denoise.m | 9 +++--- src/Matlab/mex_compile/regularisers_CPU/TGV.c | 44 +++++++++++++-------------- 3 files changed, 30 insertions(+), 28 deletions(-) diff --git a/demos/demoMatlab_3Ddenoise.m b/demos/demoMatlab_3Ddenoise.m index 6b21e86..3942eea 100644 --- a/demos/demoMatlab_3Ddenoise.m +++ b/demos/demoMatlab_3Ddenoise.m @@ -145,9 +145,10 @@ fprintf('Denoise using the TGV model (CPU) \n'); lambda_TGV = 0.03; % regularisation parameter alpha1 = 1.0; % parameter to control the first-order term alpha0 = 2.0; % parameter to control the second-order term +L2 = 12.0; % convergence parameter iter_TGV = 500; % number of Primal-Dual iterations for TGV epsil_tol = 0.0; % tolerance -tic; u_tgv = TGV(single(vol3D), lambda_TGV, alpha1, alpha0, iter_TGV, epsil_tol); toc; +tic; u_tgv = TGV(single(vol3D), lambda_TGV, alpha1, alpha0, iter_TGV, L2, epsil_tol); toc; rmseTGV = RMSE(Ideal3D(:),u_tgv(:)); fprintf('%s %f \n', 'RMSE error for TGV is:', rmseTGV); figure; imshow(u_tgv(:,:,3), [0 1]); title('TGV denoised volume (CPU)'); @@ -157,7 +158,7 @@ figure; imshow(u_tgv(:,:,3), [0 1]); title('TGV denoised volume (CPU)'); % alpha1 = 1.0; % parameter to control the first-order term % alpha0 = 2.0; % parameter to control the second-order term % iter_TGV = 500; % number of Primal-Dual iterations for TGV -% tic; u_tgv_gpu = TGV_GPU(single(vol3D), lambda_TGV, alpha1, alpha0, iter_TGV, epsil_tol); toc; +% tic; u_tgv_gpu = TGV_GPU(single(vol3D), lambda_TGV, alpha1, alpha0, iter_TGV, L2, epsil_tol); toc; % rmseTGV = RMSE(Ideal3D(:),u_tgv_gpu(:)); % fprintf('%s %f \n', 'RMSE error for TGV is:', rmseTGV); % figure; imshow(u_tgv_gpu(:,:,3), [0 1]); title('TGV denoised volume (GPU)'); diff --git a/demos/demoMatlab_denoise.m b/demos/demoMatlab_denoise.m index 377a447..9d89138 100644 --- a/demos/demoMatlab_denoise.m +++ b/demos/demoMatlab_denoise.m @@ -83,17 +83,18 @@ fprintf('Denoise using the TGV model (CPU) \n'); lambda_TGV = 0.035; % regularisation parameter alpha1 = 1.0; % parameter to control the first-order term alpha0 = 2.0; % parameter to control the second-order term -iter_TGV = 20; % number of Primal-Dual iterations for TGV +L2 = 12.0; % convergence parameter +iter_TGV = 1200; % number of Primal-Dual iterations for TGV epsil_tol = 0.0; % tolerance -tic; [u_tgv,infovec] = TGV(single(u0), lambda_TGV, alpha1, alpha0, iter_TGV, epsil_tol); toc; +tic; [u_tgv,infovec] = TGV(single(u0), lambda_TGV, alpha1, alpha0, iter_TGV, L2, epsil_tol); toc; +figure; imshow(u_tgv, [0 1]); title('TGV denoised image (CPU)'); rmseTGV = (RMSE(u_tgv(:),Im(:))); fprintf('%s %f \n', 'RMSE error for TGV is:', rmseTGV); [ssimval] = ssim(u_tgv*255,single(Im)*255); fprintf('%s %f \n', 'MSSIM error for TGV is:', ssimval); -figure; imshow(u_tgv, [0 1]); title('TGV denoised image (CPU)'); %% % fprintf('Denoise using the TGV model (GPU) \n'); -% tic; u_tgv_gpu = TGV_GPU(single(u0), lambda_TGV, alpha1, alpha0, iter_TGV, epsil_tol); toc; +% tic; u_tgv_gpu = TGV_GPU(single(u0), lambda_TGV, alpha1, alpha0, iter_TGV, L2, epsil_tol); toc; % figure; imshow(u_tgv_gpu, [0 1]); title('TGV denoised image (GPU)'); %% fprintf('Denoise using the ROF-LLT model (CPU) \n'); diff --git a/src/Matlab/mex_compile/regularisers_CPU/TGV.c b/src/Matlab/mex_compile/regularisers_CPU/TGV.c index 2c0fcbd..9e32ae4 100644 --- a/src/Matlab/mex_compile/regularisers_CPU/TGV.c +++ b/src/Matlab/mex_compile/regularisers_CPU/TGV.c @@ -20,7 +20,7 @@ limitations under the License. #include "mex.h" #include "TGV_core.h" -/* C-OMP implementation of Primal-Dual denoising method for +/* C-OMP implementation of Primal-Dual denoising method for * Total Generilized Variation (TGV)-L2 model [1] (2D/3D) * * Input Parameters: @@ -33,7 +33,7 @@ limitations under the License. * 7. eplsilon - tolerance constant [OPTIONAL parameter] * * Output: - * [1] Regularized image/volume + * [1] Regularized image/volume * [2] Information vector which contains [iteration no., reached tolerance] * * @@ -44,51 +44,51 @@ limitations under the License. void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) - + { int number_of_dims, iter; mwSize dimX, dimY, dimZ; const mwSize *dim_array; - + float *Input, *Output=NULL, lambda, alpha0, alpha1, L2, epsil; float *infovec=NULL; - + number_of_dims = mxGetNumberOfDimensions(prhs[0]); dim_array = mxGetDimensions(prhs[0]); - + /*Handling Matlab input data*/ - if ((nrhs < 2) || (nrhs > 7)) mexErrMsgTxt("At least 2 parameters is required, all parameters are: Image(2D), Regularisation parameter, alpha0, alpha1, iterations number, Lipshitz Constant"); - + if ((nrhs < 2) || (nrhs > 7)) mexErrMsgTxt("At least 2 parameters is required, all parameters are: Image(2D), Regularisation parameter, alpha0, alpha1, iterations number, Lipshitz Constant, tolerance"); + Input = (float *) mxGetData(prhs[0]); /*noisy image/volume */ lambda = (float) mxGetScalar(prhs[1]); /* regularisation parameter */ - alpha1 = 1.0f; /* parameter to control the first-order term */ + alpha1 = 1.0f; /* parameter to control the first-order term */ alpha0 = 2.0f; /* parameter to control the second-order term */ - iter = 500; /* Iterations number */ + iter = 500; /* Iterations number */ L2 = 12.0f; /* Lipshitz constant */ epsil = 1.0e-06; /*tolerance parameter*/ - - if (mxGetClassID(prhs[0]) != mxSINGLE_CLASS) {mexErrMsgTxt("The input image must be in a single precision"); } - if ((nrhs == 3) || (nrhs == 4) || (nrhs == 5) || (nrhs == 6) || (nrhs == 7)) alpha1 = (float) mxGetScalar(prhs[2]); /* parameter to control the first-order term */ + + if (mxGetClassID(prhs[0]) != mxSINGLE_CLASS) {mexErrMsgTxt("The input image must be in a single precision"); } + if ((nrhs == 3) || (nrhs == 4) || (nrhs == 5) || (nrhs == 6) || (nrhs == 7)) alpha1 = (float) mxGetScalar(prhs[2]); /* parameter to control the first-order term */ if ((nrhs == 4) || (nrhs == 5) || (nrhs == 6) || (nrhs == 7)) alpha0 = (float) mxGetScalar(prhs[3]); /* parameter to control the second-order term */ - if ((nrhs == 5) || (nrhs == 6) || (nrhs == 7)) iter = (int) mxGetScalar(prhs[4]); /* Iterations number */ + if ((nrhs == 5) || (nrhs == 6) || (nrhs == 7)) iter = (int) mxGetScalar(prhs[4]); /* Iterations number */ if ((nrhs == 6) || (nrhs == 7)) L2 = (float) mxGetScalar(prhs[5]); /* Lipshitz constant */ if (nrhs == 7) epsil = (float) mxGetScalar(prhs[6]); /* epsilon */ - + /*Handling Matlab output data*/ dimX = dim_array[0]; dimY = dim_array[1]; dimZ = dim_array[2]; - + if (number_of_dims == 2) { dimZ = 1; /*2D case*/ - Output = (float*)mxGetPr(plhs[0] = mxCreateNumericArray(2, dim_array, mxSINGLE_CLASS, mxREAL)); + Output = (float*)mxGetPr(plhs[0] = mxCreateNumericArray(2, dim_array, mxSINGLE_CLASS, mxREAL)); } if (number_of_dims == 3) { Output = (float*)mxGetPr(plhs[0] = mxCreateNumericArray(3, dim_array, mxSINGLE_CLASS, mxREAL)); - } - + } + mwSize vecdim[1]; vecdim[0] = 2; - infovec = (float*)mxGetPr(plhs[1] = mxCreateNumericArray(1, vecdim, mxSINGLE_CLASS, mxREAL)); - + infovec = (float*)mxGetPr(plhs[1] = mxCreateNumericArray(1, vecdim, mxSINGLE_CLASS, mxREAL)); + /* running the function */ - TGV_main(Input, Output, infovec, lambda, alpha1, alpha0, iter, L2, epsil, dimX, dimY, dimZ); + TGV_main(Input, Output, infovec, lambda, alpha1, alpha0, iter, L2, epsil, dimX, dimY, dimZ); } -- cgit v1.2.3