diff options
-rw-r--r-- | Core/regularizers_CPU/PatchBased_Regul.c | 140 | ||||
-rw-r--r-- | Core/regularizers_GPU/Diffus_HO/Diff4thHajiaboli_GPU.cpp | 114 | ||||
-rw-r--r-- | Core/regularizers_GPU/NL_Regul/NLM_GPU.cpp | 171 | ||||
-rw-r--r-- | Wrappers/Matlab/compile_mex.m | 11 | ||||
-rw-r--r-- | Wrappers/Matlab/demos/Demo_Phantom3D_Cone.m (renamed from demos/Demo_Phantom3D_Cone.m) | 0 | ||||
-rw-r--r-- | Wrappers/Matlab/demos/Demo_Phantom3D_Parallel.m (renamed from demos/Demo_Phantom3D_Parallel.m) | 0 | ||||
-rw-r--r-- | Wrappers/Matlab/demos/Demo_RealData3D_Parallel.m (renamed from demos/Demo_RealData3D_Parallel.m) | 0 | ||||
-rw-r--r-- | Wrappers/Matlab/demos/exportDemoRD2Data.m (renamed from demos/exportDemoRD2Data.m) | 0 | ||||
-rw-r--r-- | Wrappers/Matlab/mex_compile/compile_mex.m (renamed from main_func/compile_mex.m) | 0 | ||||
-rw-r--r-- | Wrappers/Matlab/mex_compile/regularizers_CPU/FGP_TV.c (renamed from Core/regularizers_CPU/FGP_TV.c) | 0 | ||||
-rw-r--r-- | Wrappers/Matlab/mex_compile/regularizers_CPU/FGP_TV_core.c (renamed from main_func/regularizers_CPU/FGP_TV_core.c) | 0 | ||||
-rw-r--r-- | Wrappers/Matlab/mex_compile/regularizers_CPU/FGP_TV_core.h (renamed from main_func/regularizers_CPU/FGP_TV_core.h) | 0 | ||||
-rw-r--r-- | Wrappers/Matlab/mex_compile/regularizers_CPU/LLT_model.c (renamed from Core/regularizers_CPU/LLT_model.c) | 0 | ||||
-rw-r--r-- | Wrappers/Matlab/mex_compile/regularizers_CPU/LLT_model_core.c (renamed from main_func/regularizers_CPU/LLT_model_core.c) | 0 | ||||
-rw-r--r-- | Wrappers/Matlab/mex_compile/regularizers_CPU/LLT_model_core.h (renamed from main_func/regularizers_CPU/LLT_model_core.h) | 0 | ||||
-rw-r--r-- | Wrappers/Matlab/mex_compile/regularizers_CPU/PatchBased_Regul.c (renamed from main_func/regularizers_CPU/PatchBased_Regul.c) | 0 | ||||
-rw-r--r-- | Wrappers/Matlab/mex_compile/regularizers_CPU/PatchBased_Regul_core.c (renamed from main_func/regularizers_CPU/PatchBased_Regul_core.c) | 0 | ||||
-rw-r--r-- | Wrappers/Matlab/mex_compile/regularizers_CPU/PatchBased_Regul_core.h (renamed from main_func/regularizers_CPU/PatchBased_Regul_core.h) | 0 | ||||
-rw-r--r-- | Wrappers/Matlab/mex_compile/regularizers_CPU/SplitBregman_TV.c (renamed from Core/regularizers_CPU/SplitBregman_TV.c) | 0 | ||||
-rw-r--r-- | Wrappers/Matlab/mex_compile/regularizers_CPU/SplitBregman_TV_core.c (renamed from main_func/regularizers_CPU/SplitBregman_TV_core.c) | 0 | ||||
-rw-r--r-- | Wrappers/Matlab/mex_compile/regularizers_CPU/SplitBregman_TV_core.h (renamed from main_func/regularizers_CPU/SplitBregman_TV_core.h) | 0 | ||||
-rw-r--r-- | Wrappers/Matlab/mex_compile/regularizers_CPU/TGV_PD.c (renamed from Core/regularizers_CPU/TGV_PD.c) | 0 | ||||
-rw-r--r-- | Wrappers/Matlab/mex_compile/regularizers_CPU/TGV_PD_core.c (renamed from main_func/regularizers_CPU/TGV_PD_core.c) | 0 | ||||
-rw-r--r-- | Wrappers/Matlab/mex_compile/regularizers_CPU/TGV_PD_core.h (renamed from main_func/regularizers_CPU/TGV_PD_core.h) | 0 | ||||
-rw-r--r-- | Wrappers/Matlab/mex_compile/regularizers_CPU/utils.c (renamed from main_func/regularizers_CPU/utils.c) | 0 | ||||
-rw-r--r-- | Wrappers/Matlab/mex_compile/regularizers_CPU/utils.h (renamed from main_func/regularizers_CPU/utils.h) | 0 | ||||
-rw-r--r-- | Wrappers/Matlab/mex_compile/regularizers_GPU/Diffus_HO/Diff4thHajiaboli_GPU.cpp (renamed from main_func/regularizers_GPU/Diffus_HO/Diff4thHajiaboli_GPU.cpp) | 0 | ||||
-rw-r--r-- | Wrappers/Matlab/mex_compile/regularizers_GPU/Diffus_HO/Diff4th_GPU_kernel.cu (renamed from main_func/regularizers_GPU/Diffus_HO/Diff4th_GPU_kernel.cu) | 0 | ||||
-rw-r--r-- | Wrappers/Matlab/mex_compile/regularizers_GPU/Diffus_HO/Diff4th_GPU_kernel.h (renamed from main_func/regularizers_GPU/Diffus_HO/Diff4th_GPU_kernel.h) | 0 | ||||
-rw-r--r-- | Wrappers/Matlab/mex_compile/regularizers_GPU/NL_Regul/NLM_GPU.cpp (renamed from main_func/regularizers_GPU/NL_Regul/NLM_GPU.cpp) | 0 | ||||
-rw-r--r-- | Wrappers/Matlab/mex_compile/regularizers_GPU/NL_Regul/NLM_GPU_kernel.cu (renamed from main_func/regularizers_GPU/NL_Regul/NLM_GPU_kernel.cu) | 0 | ||||
-rw-r--r-- | Wrappers/Matlab/mex_compile/regularizers_GPU/NL_Regul/NLM_GPU_kernel.h (renamed from main_func/regularizers_GPU/NL_Regul/NLM_GPU_kernel.h) | 0 | ||||
-rw-r--r-- | Wrappers/Matlab/supp/RMSE.m (renamed from supp/RMSE.m) | 0 | ||||
-rw-r--r-- | Wrappers/Matlab/supp/my_red_yellowMAP.mat (renamed from supp/my_red_yellowMAP.mat) | bin | 1761 -> 1761 bytes | |||
-rw-r--r-- | Wrappers/Matlab/supp/sino_add_artifacts.m (renamed from supp/sino_add_artifacts.m) | 0 | ||||
-rw-r--r-- | Wrappers/Matlab/supp/studentst.m (renamed from Wrappers/Matlab/studentst.m) | 0 | ||||
-rw-r--r-- | Wrappers/Matlab/supp/zing_rings_add.m (renamed from supp/zing_rings_add.m) | 0 | ||||
-rw-r--r-- | demos/DendrData.h5 | bin | 72598872 -> 0 bytes | |||
-rw-r--r-- | main_func/FISTA_REC.m | 704 | ||||
-rw-r--r-- | main_func/regularizers_CPU/FGP_TV.c | 216 | ||||
-rw-r--r-- | main_func/regularizers_CPU/LLT_model.c | 169 | ||||
-rw-r--r-- | main_func/regularizers_CPU/SplitBregman_TV.c | 179 | ||||
-rw-r--r-- | main_func/regularizers_CPU/TGV_PD.c | 144 | ||||
-rw-r--r-- | main_func/studentst.m | 47 | ||||
-rw-r--r-- | src/Python/conda-recipe/meta.yaml | 4 |
45 files changed, 2 insertions, 1897 deletions
diff --git a/Core/regularizers_CPU/PatchBased_Regul.c b/Core/regularizers_CPU/PatchBased_Regul.c deleted file mode 100644 index 5d89b0c..0000000 --- a/Core/regularizers_CPU/PatchBased_Regul.c +++ /dev/null @@ -1,140 +0,0 @@ -/* -This work is part of the Core Imaging Library developed by -Visual Analytics and Imaging System Group of the Science Technology -Facilities Council, STFC - -Copyright 2017 Daniil Kazantsev -Copyright 2017 Srikanth Nagella, Edoardo Pasca - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at -http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -#include "mex.h" -#include "matrix.h" -#include "PatchBased_Regul_core.h" - - -/* C-OMP implementation of patch-based (PB) regularization (2D and 3D cases). - * This method finds self-similar patches in data and performs one fixed point iteration to mimimize the PB penalty function - * - * References: 1. Yang Z. & Jacob M. "Nonlocal Regularization of Inverse Problems" - * 2. Kazantsev D. et al. "4D-CT reconstruction with unified spatial-temporal patch-based regularization" - * - * Input Parameters: - * 1. Image (2D or 3D) [required] - * 2. ratio of the searching window (e.g. 3 = (2*3+1) = 7 pixels window) [optional] - * 3. ratio of the similarity window (e.g. 1 = (2*1+1) = 3 pixels window) [optional] - * 4. h - parameter for the PB penalty function [optional] - * 5. lambda - regularization parameter [optional] - - * Output: - * 1. regularized (denoised) Image (N x N)/volume (N x N x N) - * - * 2D denoising example in Matlab: - Im = double(imread('lena_gray_256.tif'))/255; % loading image - u0 = Im + .03*randn(size(Im)); u0(u0<0) = 0; % adding noise - ImDen = PatchBased_Regul(single(u0), 3, 1, 0.08, 0.05); - * - * Matlab + C/mex compilers needed - * to compile with OMP support: mex PatchBased_Regul.c CFLAGS="\$CFLAGS -fopenmp -Wall" LDFLAGS="\$LDFLAGS -fopenmp" - * - * D. Kazantsev * - * 02/07/2014 - * Harwell, UK - */ - - -void mexFunction( - int nlhs, mxArray *plhs[], - int nrhs, const mxArray *prhs[]) -{ - int N, M, Z, numdims, SearchW, SimilW, SearchW_real, padXY, newsizeX, newsizeY, newsizeZ, switchpad_crop; - const int *dims; - float *A, *B=NULL, *Ap=NULL, *Bp=NULL, h, lambda; - - numdims = mxGetNumberOfDimensions(prhs[0]); - dims = mxGetDimensions(prhs[0]); - - N = dims[0]; - M = dims[1]; - Z = dims[2]; - - if ((numdims < 2) || (numdims > 3)) {mexErrMsgTxt("The input is 2D image or 3D volume");} - if (mxGetClassID(prhs[0]) != mxSINGLE_CLASS) {mexErrMsgTxt("The input in single precision is required"); } - - if(nrhs != 5) mexErrMsgTxt("Five inputs reqired: Image(2D,3D), SearchW, SimilW, Threshold, Regularization parameter"); - - /*Handling inputs*/ - A = (float *) mxGetData(prhs[0]); /* the image/volume to regularize/filter */ - SearchW_real = 3; /*default value*/ - SimilW = 1; /*default value*/ - h = 0.1; - lambda = 0.1; - - if ((nrhs == 2) || (nrhs == 3) || (nrhs == 4) || (nrhs == 5)) SearchW_real = (int) mxGetScalar(prhs[1]); /* the searching window ratio */ - if ((nrhs == 3) || (nrhs == 4) || (nrhs == 5)) SimilW = (int) mxGetScalar(prhs[2]); /* the similarity window ratio */ - if ((nrhs == 4) || (nrhs == 5)) h = (float) mxGetScalar(prhs[3]); /* parameter for the PB filtering function */ - if ((nrhs == 5)) lambda = (float) mxGetScalar(prhs[4]); /* regularization parameter */ - - - if (h <= 0) mexErrMsgTxt("Parmeter for the PB penalty function should be > 0"); - if (lambda <= 0) mexErrMsgTxt(" Regularization parmeter should be > 0"); - - SearchW = SearchW_real + 2*SimilW; - - /* SearchW_full = 2*SearchW + 1; */ /* the full searching window size */ - /* SimilW_full = 2*SimilW + 1; */ /* the full similarity window size */ - - padXY = SearchW + 2*SimilW; /* padding sizes */ - newsizeX = N + 2*(padXY); /* the X size of the padded array */ - newsizeY = M + 2*(padXY); /* the Y size of the padded array */ - newsizeZ = Z + 2*(padXY); /* the Z size of the padded array */ - int N_dims[] = {newsizeX, newsizeY, newsizeZ}; - - /******************************2D case ****************************/ - if (numdims == 2) { - /*Handling output*/ - B = (float*)mxGetData(plhs[0] = mxCreateNumericMatrix(N, M, mxSINGLE_CLASS, mxREAL)); - /*allocating memory for the padded arrays */ - Ap = (float*)mxGetData(mxCreateNumericMatrix(newsizeX, newsizeY, mxSINGLE_CLASS, mxREAL)); - Bp = (float*)mxGetData(mxCreateNumericMatrix(newsizeX, newsizeY, mxSINGLE_CLASS, mxREAL)); - /**************************************************************************/ - /*Perform padding of image A to the size of [newsizeX * newsizeY] */ - switchpad_crop = 0; /*padding*/ - pad_crop(A, Ap, M, N, 0, newsizeY, newsizeX, 0, padXY, switchpad_crop); - - /* Do PB regularization with the padded array */ - PB_FUNC2D(Ap, Bp, newsizeY, newsizeX, padXY, SearchW, SimilW, (float)h, (float)lambda); - - switchpad_crop = 1; /*cropping*/ - pad_crop(Bp, B, M, N, 0, newsizeY, newsizeX, 0, padXY, switchpad_crop); - } - else - { - /******************************3D case ****************************/ - /*Handling output*/ - B = (float*)mxGetPr(plhs[0] = mxCreateNumericArray(3, dims, mxSINGLE_CLASS, mxREAL)); - /*allocating memory for the padded arrays */ - Ap = (float*)mxGetPr(mxCreateNumericArray(3, N_dims, mxSINGLE_CLASS, mxREAL)); - Bp = (float*)mxGetPr(mxCreateNumericArray(3, N_dims, mxSINGLE_CLASS, mxREAL)); - /**************************************************************************/ - - /*Perform padding of image A to the size of [newsizeX * newsizeY * newsizeZ] */ - switchpad_crop = 0; /*padding*/ - pad_crop(A, Ap, M, N, Z, newsizeY, newsizeX, newsizeZ, padXY, switchpad_crop); - - /* Do PB regularization with the padded array */ - PB_FUNC3D(Ap, Bp, newsizeY, newsizeX, newsizeZ, padXY, SearchW, SimilW, (float)h, (float)lambda); - - switchpad_crop = 1; /*cropping*/ - pad_crop(Bp, B, M, N, Z, newsizeY, newsizeX, newsizeZ, padXY, switchpad_crop); - } /*end else ndims*/ -} diff --git a/Core/regularizers_GPU/Diffus_HO/Diff4thHajiaboli_GPU.cpp b/Core/regularizers_GPU/Diffus_HO/Diff4thHajiaboli_GPU.cpp deleted file mode 100644 index e5b1ee0..0000000 --- a/Core/regularizers_GPU/Diffus_HO/Diff4thHajiaboli_GPU.cpp +++ /dev/null @@ -1,114 +0,0 @@ -#include "mex.h" -#include <matrix.h> -#include <math.h> -#include <stdlib.h> -#include <memory.h> -#include <stdio.h> -#include <iostream> -#include "Diff4th_GPU_kernel.h" - -/* - * 2D and 3D CUDA implementation of the 4th order PDE denoising model by Hajiaboli - * - * Reference : - * "An anisotropic fourth-order diffusion filter for image noise removal" by M. Hajiaboli - * - * Example - * figure; - * Im = double(imread('lena_gray_256.tif'))/255; % loading image - * u0 = Im + .05*randn(size(Im)); % adding noise - * u = Diff4thHajiaboli_GPU(single(u0), 0.02, 150); - * subplot (1,2,1); imshow(u0,[ ]); title('Noisy Image') - * subplot (1,2,2); imshow(u,[ ]); title('Denoised Image') - * - * - * Linux/Matlab compilation: - * compile in terminal: nvcc -Xcompiler -fPIC -shared -o Diff4th_GPU_kernel.o Diff4th_GPU_kernel.cu - * then compile in Matlab: mex -I/usr/local/cuda-7.5/include -L/usr/local/cuda-7.5/lib64 -lcudart Diff4thHajiaboli_GPU.cpp Diff4th_GPU_kernel.o - */ - -void mexFunction( - int nlhs, mxArray *plhs[], - int nrhs, const mxArray *prhs[]) -{ - int numdims, dimZ, size; - float *A, *B, *A_L, *B_L; - const int *dims; - - numdims = mxGetNumberOfDimensions(prhs[0]); - dims = mxGetDimensions(prhs[0]); - - float sigma = (float)mxGetScalar(prhs[1]); /* edge-preserving parameter */ - float lambda = (float)mxGetScalar(prhs[2]); /* regularization parameter */ - int iter = (int)mxGetScalar(prhs[3]); /* iterations number */ - - if (numdims == 2) { - - int N, M, Z, i, j; - Z = 0; // for the 2D case - float tau = 0.01; // time step is sufficiently small for an explicit methods - - /*Input data*/ - A = (float*)mxGetData(prhs[0]); - N = dims[0] + 2; - M = dims[1] + 2; - A_L = (float*)mxGetData(mxCreateNumericMatrix(N, M, mxSINGLE_CLASS, mxREAL)); - B_L = (float*)mxGetData(mxCreateNumericMatrix(N, M, mxSINGLE_CLASS, mxREAL)); - - /*Output data*/ - B = (float*)mxGetData(plhs[0] = mxCreateNumericMatrix(dims[0], dims[1], mxSINGLE_CLASS, mxREAL)); - - // copy A to the bigger A_L with boundaries - #pragma omp parallel for shared(A_L, A) private(i,j) - for (i=0; i < N; i++) { - for (j=0; j < M; j++) { - if (((i > 0) && (i < N-1)) && ((j > 0) && (j < M-1))) A_L[i*M+j] = A[(i-1)*(dims[1])+(j-1)]; - }} - - // Running CUDA code here - Diff4th_GPU_kernel(A_L, B_L, N, M, Z, (float)sigma, iter, (float)tau, lambda); - - // copy the processed B_L to a smaller B - #pragma omp parallel for shared(B_L, B) private(i,j) - for (i=0; i < N; i++) { - for (j=0; j < M; j++) { - if (((i > 0) && (i < N-1)) && ((j > 0) && (j < M-1))) B[(i-1)*(dims[1])+(j-1)] = B_L[i*M+j]; - }} - } - if (numdims == 3) { - // 3D image denoising / regularization - int N, M, Z, i, j, k; - float tau = 0.0007; // Time Step is small for an explicit methods - A = (float*)mxGetData(prhs[0]); - N = dims[0] + 2; - M = dims[1] + 2; - Z = dims[2] + 2; - int N_dims[] = {N, M, Z}; - A_L = (float*)mxGetPr(mxCreateNumericArray(3, N_dims, mxSINGLE_CLASS, mxREAL)); - B_L = (float*)mxGetPr(mxCreateNumericArray(3, N_dims, mxSINGLE_CLASS, mxREAL)); - - /* output data */ - B = (float*)mxGetPr(plhs[0] = mxCreateNumericArray(3, dims, mxSINGLE_CLASS, mxREAL)); - - // copy A to the bigger A_L with boundaries - #pragma omp parallel for shared(A_L, A) private(i,j,k) - for (i=0; i < N; i++) { - for (j=0; j < M; j++) { - for (k=0; k < Z; k++) { - if (((i > 0) && (i < N-1)) && ((j > 0) && (j < M-1)) && ((k > 0) && (k < Z-1))) { - A_L[(N*M)*(k)+(i)*M+(j)] = A[(dims[0]*dims[1])*(k-1)+(i-1)*dims[1]+(j-1)]; - }}}} - - // Running CUDA kernel here for diffusivity - Diff4th_GPU_kernel(A_L, B_L, N, M, Z, (float)sigma, iter, (float)tau, lambda); - - // copy the processed B_L to a smaller B - #pragma omp parallel for shared(B_L, B) private(i,j,k) - for (i=0; i < N; i++) { - for (j=0; j < M; j++) { - for (k=0; k < Z; k++) { - if (((i > 0) && (i < N-1)) && ((j > 0) && (j < M-1)) && ((k > 0) && (k < Z-1))) { - B[(dims[0]*dims[1])*(k-1)+(i-1)*dims[1]+(j-1)] = B_L[(N*M)*(k)+(i)*M+(j)]; - }}}} - } -}
\ No newline at end of file diff --git a/Core/regularizers_GPU/NL_Regul/NLM_GPU.cpp b/Core/regularizers_GPU/NL_Regul/NLM_GPU.cpp deleted file mode 100644 index 858b865..0000000 --- a/Core/regularizers_GPU/NL_Regul/NLM_GPU.cpp +++ /dev/null @@ -1,171 +0,0 @@ -#include "mex.h" -#include <matrix.h> -#include <math.h> -#include <stdlib.h> -#include <memory.h> -#include <stdio.h> -#include <iostream> -#include "NLM_GPU_kernel.h" - -/* CUDA implementation of the patch-based (PB) regularization for 2D and 3D images/volumes - * This method finds self-similar patches in data and performs one fixed point iteration to mimimize the PB penalty function - * - * References: 1. Yang Z. & Jacob M. "Nonlocal Regularization of Inverse Problems" - * 2. Kazantsev D. at. all "4D-CT reconstruction with unified spatial-temporal patch-based regularization" - * - * Input Parameters (mandatory): - * 1. Image/volume (2D/3D) - * 2. ratio of the searching window (e.g. 3 = (2*3+1) = 7 pixels window) - * 3. ratio of the similarity window (e.g. 1 = (2*1+1) = 3 pixels window) - * 4. h - parameter for the PB penalty function - * 5. lambda - regularization parameter - - * Output: - * 1. regularized (denoised) Image/volume (N x N x N) - * - * In matlab check what kind of GPU you have with "gpuDevice" command, - * then set your ComputeCapability, here I use -arch compute_35 - * - * Quick 2D denoising example in Matlab: - Im = double(imread('lena_gray_256.tif'))/255; % loading image - u0 = Im + .03*randn(size(Im)); u0(u0<0) = 0; % adding noise - ImDen = NLM_GPU(single(u0), 3, 2, 0.15, 1); - - * Linux/Matlab compilation: - * compile in terminal: nvcc -Xcompiler -fPIC -shared -o NLM_GPU_kernel.o NLM_GPU_kernel.cu - * then compile in Matlab: mex -I/usr/local/cuda-7.5/include -L/usr/local/cuda-7.5/lib64 -lcudart NLM_GPU.cpp NLM_GPU_kernel.o - * - * D. Kazantsev - * 2014-17 - * Harwell/Manchester UK - */ - -float pad_crop(float *A, float *Ap, int OldSizeX, int OldSizeY, int OldSizeZ, int NewSizeX, int NewSizeY, int NewSizeZ, int padXY, int switchpad_crop); - -void mexFunction( - int nlhs, mxArray *plhs[], - int nrhs, const mxArray *prhs[]) -{ - int N, M, Z, i_n, j_n, k_n, numdims, SearchW, SimilW, SearchW_real, padXY, newsizeX, newsizeY, newsizeZ, switchpad_crop, count, SearchW_full, SimilW_full; - const int *dims; - float *A, *B=NULL, *Ap=NULL, *Bp=NULL, *Eucl_Vec, h, h2, lambda, val, denh2; - - numdims = mxGetNumberOfDimensions(prhs[0]); - dims = mxGetDimensions(prhs[0]); - - N = dims[0]; - M = dims[1]; - Z = dims[2]; - - if ((numdims < 2) || (numdims > 3)) {mexErrMsgTxt("The input should be 2D image or 3D volume");} - if (mxGetClassID(prhs[0]) != mxSINGLE_CLASS) {mexErrMsgTxt("The input in single precision is required"); } - - if(nrhs != 5) mexErrMsgTxt("Five inputs reqired: Image(2D,3D), SearchW, SimilW, Threshold, Regularization parameter"); - - /*Handling inputs*/ - A = (float *) mxGetData(prhs[0]); /* the image to regularize/filter */ - SearchW_real = (int) mxGetScalar(prhs[1]); /* the searching window ratio */ - SimilW = (int) mxGetScalar(prhs[2]); /* the similarity window ratio */ - h = (float) mxGetScalar(prhs[3]); /* parameter for the PB filtering function */ - lambda = (float) mxGetScalar(prhs[4]); - - if (h <= 0) mexErrMsgTxt("Parmeter for the PB penalty function should be > 0"); - - SearchW = SearchW_real + 2*SimilW; - - SearchW_full = 2*SearchW + 1; /* the full searching window size */ - SimilW_full = 2*SimilW + 1; /* the full similarity window size */ - h2 = h*h; - - padXY = SearchW + 2*SimilW; /* padding sizes */ - newsizeX = N + 2*(padXY); /* the X size of the padded array */ - newsizeY = M + 2*(padXY); /* the Y size of the padded array */ - newsizeZ = Z + 2*(padXY); /* the Z size of the padded array */ - int N_dims[] = {newsizeX, newsizeY, newsizeZ}; - - /******************************2D case ****************************/ - if (numdims == 2) { - /*Handling output*/ - B = (float*)mxGetData(plhs[0] = mxCreateNumericMatrix(N, M, mxSINGLE_CLASS, mxREAL)); - /*allocating memory for the padded arrays */ - Ap = (float*)mxGetData(mxCreateNumericMatrix(newsizeX, newsizeY, mxSINGLE_CLASS, mxREAL)); - Bp = (float*)mxGetData(mxCreateNumericMatrix(newsizeX, newsizeY, mxSINGLE_CLASS, mxREAL)); - Eucl_Vec = (float*)mxGetData(mxCreateNumericMatrix(SimilW_full*SimilW_full, 1, mxSINGLE_CLASS, mxREAL)); - - /*Gaussian kernel */ - count = 0; - for(i_n=-SimilW; i_n<=SimilW; i_n++) { - for(j_n=-SimilW; j_n<=SimilW; j_n++) { - val = (float)(i_n*i_n + j_n*j_n)/(2*SimilW*SimilW); - Eucl_Vec[count] = exp(-val); - count = count + 1; - }} /*main neighb loop */ - - /**************************************************************************/ - /*Perform padding of image A to the size of [newsizeX * newsizeY] */ - switchpad_crop = 0; /*padding*/ - pad_crop(A, Ap, M, N, 0, newsizeY, newsizeX, 0, padXY, switchpad_crop); - - /* Do PB regularization with the padded array */ - NLM_GPU_kernel(Ap, Bp, Eucl_Vec, newsizeY, newsizeX, 0, numdims, SearchW, SimilW, SearchW_real, (float)h2, (float)lambda); - - switchpad_crop = 1; /*cropping*/ - pad_crop(Bp, B, M, N, 0, newsizeY, newsizeX, 0, padXY, switchpad_crop); - } - else - { - /******************************3D case ****************************/ - /*Handling output*/ - B = (float*)mxGetPr(plhs[0] = mxCreateNumericArray(3, dims, mxSINGLE_CLASS, mxREAL)); - /*allocating memory for the padded arrays */ - Ap = (float*)mxGetPr(mxCreateNumericArray(3, N_dims, mxSINGLE_CLASS, mxREAL)); - Bp = (float*)mxGetPr(mxCreateNumericArray(3, N_dims, mxSINGLE_CLASS, mxREAL)); - Eucl_Vec = (float*)mxGetData(mxCreateNumericMatrix(SimilW_full*SimilW_full*SimilW_full, 1, mxSINGLE_CLASS, mxREAL)); - - /*Gaussian kernel */ - count = 0; - for(i_n=-SimilW; i_n<=SimilW; i_n++) { - for(j_n=-SimilW; j_n<=SimilW; j_n++) { - for(k_n=-SimilW; k_n<=SimilW; k_n++) { - val = (float)(i_n*i_n + j_n*j_n + k_n*k_n)/(2*SimilW*SimilW*SimilW); - Eucl_Vec[count] = exp(-val); - count = count + 1; - }}} /*main neighb loop */ - /**************************************************************************/ - /*Perform padding of image A to the size of [newsizeX * newsizeY * newsizeZ] */ - switchpad_crop = 0; /*padding*/ - pad_crop(A, Ap, M, N, Z, newsizeY, newsizeX, newsizeZ, padXY, switchpad_crop); - - /* Do PB regularization with the padded array */ - NLM_GPU_kernel(Ap, Bp, Eucl_Vec, newsizeY, newsizeX, newsizeZ, numdims, SearchW, SimilW, SearchW_real, (float)h2, (float)lambda); - - switchpad_crop = 1; /*cropping*/ - pad_crop(Bp, B, M, N, Z, newsizeY, newsizeX, newsizeZ, padXY, switchpad_crop); - } /*end else ndims*/ -} - -float pad_crop(float *A, float *Ap, int OldSizeX, int OldSizeY, int OldSizeZ, int NewSizeX, int NewSizeY, int NewSizeZ, int padXY, int switchpad_crop) -{ - /* padding-cropping function */ - int i,j,k; - if (NewSizeZ > 1) { - for (i=0; i < NewSizeX; i++) { - for (j=0; j < NewSizeY; j++) { - for (k=0; k < NewSizeZ; k++) { - if (((i >= padXY) && (i < NewSizeX-padXY)) && ((j >= padXY) && (j < NewSizeY-padXY)) && ((k >= padXY) && (k < NewSizeZ-padXY))) { - if (switchpad_crop == 0) Ap[NewSizeX*NewSizeY*k + i*NewSizeY+j] = A[OldSizeX*OldSizeY*(k - padXY) + (i-padXY)*(OldSizeY)+(j-padXY)]; - else Ap[OldSizeX*OldSizeY*(k - padXY) + (i-padXY)*(OldSizeY)+(j-padXY)] = A[NewSizeX*NewSizeY*k + i*NewSizeY+j]; - } - }}} - } - else { - for (i=0; i < NewSizeX; i++) { - for (j=0; j < NewSizeY; j++) { - if (((i >= padXY) && (i < NewSizeX-padXY)) && ((j >= padXY) && (j < NewSizeY-padXY))) { - if (switchpad_crop == 0) Ap[i*NewSizeY+j] = A[(i-padXY)*(OldSizeY)+(j-padXY)]; - else Ap[(i-padXY)*(OldSizeY)+(j-padXY)] = A[i*NewSizeY+j]; - } - }} - } - return *Ap; -}
\ No newline at end of file diff --git a/Wrappers/Matlab/compile_mex.m b/Wrappers/Matlab/compile_mex.m deleted file mode 100644 index 66c05da..0000000 --- a/Wrappers/Matlab/compile_mex.m +++ /dev/null @@ -1,11 +0,0 @@ -% compile mex's in Matlab once -cd regularizers_CPU/ - -mex LLT_model.c LLT_model_core.c CFLAGS="\$CFLAGS -fopenmp -Wall -std=c99" LDFLAGS="\$LDFLAGS -fopenmp" -mex FGP_TV.c FGP_TV_core.c CFLAGS="\$CFLAGS -fopenmp -Wall -std=c99" LDFLAGS="\$LDFLAGS -fopenmp" -mex SplitBregman_TV.c SplitBregman_TV_core.c CFLAGS="\$CFLAGS -fopenmp -Wall -std=c99" LDFLAGS="\$LDFLAGS -fopenmp" -mex TGV_PD.c TGV_PD_core.c CFLAGS="\$CFLAGS -fopenmp -Wall -std=c99" LDFLAGS="\$LDFLAGS -fopenmp" -mex PatchBased_Regul.c PatchBased_Regul_core.c CFLAGS="\$CFLAGS -fopenmp -Wall -std=c99" LDFLAGS="\$LDFLAGS -fopenmp" - -cd ../../ -cd demos diff --git a/demos/Demo_Phantom3D_Cone.m b/Wrappers/Matlab/demos/Demo_Phantom3D_Cone.m index a8f2c92..a8f2c92 100644 --- a/demos/Demo_Phantom3D_Cone.m +++ b/Wrappers/Matlab/demos/Demo_Phantom3D_Cone.m diff --git a/demos/Demo_Phantom3D_Parallel.m b/Wrappers/Matlab/demos/Demo_Phantom3D_Parallel.m index 4219bd1..4219bd1 100644 --- a/demos/Demo_Phantom3D_Parallel.m +++ b/Wrappers/Matlab/demos/Demo_Phantom3D_Parallel.m diff --git a/demos/Demo_RealData3D_Parallel.m b/Wrappers/Matlab/demos/Demo_RealData3D_Parallel.m index f82e0b0..f82e0b0 100644 --- a/demos/Demo_RealData3D_Parallel.m +++ b/Wrappers/Matlab/demos/Demo_RealData3D_Parallel.m diff --git a/demos/exportDemoRD2Data.m b/Wrappers/Matlab/demos/exportDemoRD2Data.m index 028353b..028353b 100644 --- a/demos/exportDemoRD2Data.m +++ b/Wrappers/Matlab/demos/exportDemoRD2Data.m diff --git a/main_func/compile_mex.m b/Wrappers/Matlab/mex_compile/compile_mex.m index 1353859..1353859 100644 --- a/main_func/compile_mex.m +++ b/Wrappers/Matlab/mex_compile/compile_mex.m diff --git a/Core/regularizers_CPU/FGP_TV.c b/Wrappers/Matlab/mex_compile/regularizers_CPU/FGP_TV.c index 30cea1a..30cea1a 100644 --- a/Core/regularizers_CPU/FGP_TV.c +++ b/Wrappers/Matlab/mex_compile/regularizers_CPU/FGP_TV.c diff --git a/main_func/regularizers_CPU/FGP_TV_core.c b/Wrappers/Matlab/mex_compile/regularizers_CPU/FGP_TV_core.c index 03cd445..03cd445 100644 --- a/main_func/regularizers_CPU/FGP_TV_core.c +++ b/Wrappers/Matlab/mex_compile/regularizers_CPU/FGP_TV_core.c diff --git a/main_func/regularizers_CPU/FGP_TV_core.h b/Wrappers/Matlab/mex_compile/regularizers_CPU/FGP_TV_core.h index 6430bf2..6430bf2 100644 --- a/main_func/regularizers_CPU/FGP_TV_core.h +++ b/Wrappers/Matlab/mex_compile/regularizers_CPU/FGP_TV_core.h diff --git a/Core/regularizers_CPU/LLT_model.c b/Wrappers/Matlab/mex_compile/regularizers_CPU/LLT_model.c index 0b07b47..0b07b47 100644 --- a/Core/regularizers_CPU/LLT_model.c +++ b/Wrappers/Matlab/mex_compile/regularizers_CPU/LLT_model.c diff --git a/main_func/regularizers_CPU/LLT_model_core.c b/Wrappers/Matlab/mex_compile/regularizers_CPU/LLT_model_core.c index 3a853d2..3a853d2 100644 --- a/main_func/regularizers_CPU/LLT_model_core.c +++ b/Wrappers/Matlab/mex_compile/regularizers_CPU/LLT_model_core.c diff --git a/main_func/regularizers_CPU/LLT_model_core.h b/Wrappers/Matlab/mex_compile/regularizers_CPU/LLT_model_core.h index 13fce5a..13fce5a 100644 --- a/main_func/regularizers_CPU/LLT_model_core.h +++ b/Wrappers/Matlab/mex_compile/regularizers_CPU/LLT_model_core.h diff --git a/main_func/regularizers_CPU/PatchBased_Regul.c b/Wrappers/Matlab/mex_compile/regularizers_CPU/PatchBased_Regul.c index 9c925df..9c925df 100644 --- a/main_func/regularizers_CPU/PatchBased_Regul.c +++ b/Wrappers/Matlab/mex_compile/regularizers_CPU/PatchBased_Regul.c diff --git a/main_func/regularizers_CPU/PatchBased_Regul_core.c b/Wrappers/Matlab/mex_compile/regularizers_CPU/PatchBased_Regul_core.c index acfb464..acfb464 100644 --- a/main_func/regularizers_CPU/PatchBased_Regul_core.c +++ b/Wrappers/Matlab/mex_compile/regularizers_CPU/PatchBased_Regul_core.c diff --git a/main_func/regularizers_CPU/PatchBased_Regul_core.h b/Wrappers/Matlab/mex_compile/regularizers_CPU/PatchBased_Regul_core.h index d4a8a46..d4a8a46 100644 --- a/main_func/regularizers_CPU/PatchBased_Regul_core.h +++ b/Wrappers/Matlab/mex_compile/regularizers_CPU/PatchBased_Regul_core.h diff --git a/Core/regularizers_CPU/SplitBregman_TV.c b/Wrappers/Matlab/mex_compile/regularizers_CPU/SplitBregman_TV.c index 38f6a9d..38f6a9d 100644 --- a/Core/regularizers_CPU/SplitBregman_TV.c +++ b/Wrappers/Matlab/mex_compile/regularizers_CPU/SplitBregman_TV.c diff --git a/main_func/regularizers_CPU/SplitBregman_TV_core.c b/Wrappers/Matlab/mex_compile/regularizers_CPU/SplitBregman_TV_core.c index 4109a4b..4109a4b 100644 --- a/main_func/regularizers_CPU/SplitBregman_TV_core.c +++ b/Wrappers/Matlab/mex_compile/regularizers_CPU/SplitBregman_TV_core.c diff --git a/main_func/regularizers_CPU/SplitBregman_TV_core.h b/Wrappers/Matlab/mex_compile/regularizers_CPU/SplitBregman_TV_core.h index 6ed3ff9..6ed3ff9 100644 --- a/main_func/regularizers_CPU/SplitBregman_TV_core.h +++ b/Wrappers/Matlab/mex_compile/regularizers_CPU/SplitBregman_TV_core.h diff --git a/Core/regularizers_CPU/TGV_PD.c b/Wrappers/Matlab/mex_compile/regularizers_CPU/TGV_PD.c index c9cb440..c9cb440 100644 --- a/Core/regularizers_CPU/TGV_PD.c +++ b/Wrappers/Matlab/mex_compile/regularizers_CPU/TGV_PD.c diff --git a/main_func/regularizers_CPU/TGV_PD_core.c b/Wrappers/Matlab/mex_compile/regularizers_CPU/TGV_PD_core.c index 4139d10..4139d10 100644 --- a/main_func/regularizers_CPU/TGV_PD_core.c +++ b/Wrappers/Matlab/mex_compile/regularizers_CPU/TGV_PD_core.c diff --git a/main_func/regularizers_CPU/TGV_PD_core.h b/Wrappers/Matlab/mex_compile/regularizers_CPU/TGV_PD_core.h index d5378df..d5378df 100644 --- a/main_func/regularizers_CPU/TGV_PD_core.h +++ b/Wrappers/Matlab/mex_compile/regularizers_CPU/TGV_PD_core.h diff --git a/main_func/regularizers_CPU/utils.c b/Wrappers/Matlab/mex_compile/regularizers_CPU/utils.c index 0e83d2c..0e83d2c 100644 --- a/main_func/regularizers_CPU/utils.c +++ b/Wrappers/Matlab/mex_compile/regularizers_CPU/utils.c diff --git a/main_func/regularizers_CPU/utils.h b/Wrappers/Matlab/mex_compile/regularizers_CPU/utils.h index 53463a3..53463a3 100644 --- a/main_func/regularizers_CPU/utils.h +++ b/Wrappers/Matlab/mex_compile/regularizers_CPU/utils.h diff --git a/main_func/regularizers_GPU/Diffus_HO/Diff4thHajiaboli_GPU.cpp b/Wrappers/Matlab/mex_compile/regularizers_GPU/Diffus_HO/Diff4thHajiaboli_GPU.cpp index 5a8c7c0..5a8c7c0 100644 --- a/main_func/regularizers_GPU/Diffus_HO/Diff4thHajiaboli_GPU.cpp +++ b/Wrappers/Matlab/mex_compile/regularizers_GPU/Diffus_HO/Diff4thHajiaboli_GPU.cpp diff --git a/main_func/regularizers_GPU/Diffus_HO/Diff4th_GPU_kernel.cu b/Wrappers/Matlab/mex_compile/regularizers_GPU/Diffus_HO/Diff4th_GPU_kernel.cu index 178af00..178af00 100644 --- a/main_func/regularizers_GPU/Diffus_HO/Diff4th_GPU_kernel.cu +++ b/Wrappers/Matlab/mex_compile/regularizers_GPU/Diffus_HO/Diff4th_GPU_kernel.cu diff --git a/main_func/regularizers_GPU/Diffus_HO/Diff4th_GPU_kernel.h b/Wrappers/Matlab/mex_compile/regularizers_GPU/Diffus_HO/Diff4th_GPU_kernel.h index cfbb45a..cfbb45a 100644 --- a/main_func/regularizers_GPU/Diffus_HO/Diff4th_GPU_kernel.h +++ b/Wrappers/Matlab/mex_compile/regularizers_GPU/Diffus_HO/Diff4th_GPU_kernel.h diff --git a/main_func/regularizers_GPU/NL_Regul/NLM_GPU.cpp b/Wrappers/Matlab/mex_compile/regularizers_GPU/NL_Regul/NLM_GPU.cpp index ff0cc90..ff0cc90 100644 --- a/main_func/regularizers_GPU/NL_Regul/NLM_GPU.cpp +++ b/Wrappers/Matlab/mex_compile/regularizers_GPU/NL_Regul/NLM_GPU.cpp diff --git a/main_func/regularizers_GPU/NL_Regul/NLM_GPU_kernel.cu b/Wrappers/Matlab/mex_compile/regularizers_GPU/NL_Regul/NLM_GPU_kernel.cu index 17da3a8..17da3a8 100644 --- a/main_func/regularizers_GPU/NL_Regul/NLM_GPU_kernel.cu +++ b/Wrappers/Matlab/mex_compile/regularizers_GPU/NL_Regul/NLM_GPU_kernel.cu diff --git a/main_func/regularizers_GPU/NL_Regul/NLM_GPU_kernel.h b/Wrappers/Matlab/mex_compile/regularizers_GPU/NL_Regul/NLM_GPU_kernel.h index bc9d4a3..bc9d4a3 100644 --- a/main_func/regularizers_GPU/NL_Regul/NLM_GPU_kernel.h +++ b/Wrappers/Matlab/mex_compile/regularizers_GPU/NL_Regul/NLM_GPU_kernel.h diff --git a/supp/RMSE.m b/Wrappers/Matlab/supp/RMSE.m index 002f776..002f776 100644 --- a/supp/RMSE.m +++ b/Wrappers/Matlab/supp/RMSE.m diff --git a/supp/my_red_yellowMAP.mat b/Wrappers/Matlab/supp/my_red_yellowMAP.mat Binary files differindex c2a5b87..c2a5b87 100644 --- a/supp/my_red_yellowMAP.mat +++ b/Wrappers/Matlab/supp/my_red_yellowMAP.mat diff --git a/supp/sino_add_artifacts.m b/Wrappers/Matlab/supp/sino_add_artifacts.m index f601914..f601914 100644 --- a/supp/sino_add_artifacts.m +++ b/Wrappers/Matlab/supp/sino_add_artifacts.m diff --git a/Wrappers/Matlab/studentst.m b/Wrappers/Matlab/supp/studentst.m index 99fed1e..99fed1e 100644 --- a/Wrappers/Matlab/studentst.m +++ b/Wrappers/Matlab/supp/studentst.m diff --git a/supp/zing_rings_add.m b/Wrappers/Matlab/supp/zing_rings_add.m index d197b1f..d197b1f 100644 --- a/supp/zing_rings_add.m +++ b/Wrappers/Matlab/supp/zing_rings_add.m diff --git a/demos/DendrData.h5 b/demos/DendrData.h5 Binary files differdeleted file mode 100644 index f048268..0000000 --- a/demos/DendrData.h5 +++ /dev/null diff --git a/main_func/FISTA_REC.m b/main_func/FISTA_REC.m deleted file mode 100644 index d717a03..0000000 --- a/main_func/FISTA_REC.m +++ /dev/null @@ -1,704 +0,0 @@ -function [X, output] = FISTA_REC(params) - -% <<<< FISTA-based reconstruction routine using ASTRA-toolbox >>>> -% This code solves regularised PWLS problem using FISTA approach. -% The code contains multiple regularisation penalties as well as it can be -% accelerated by using ordered-subset version. Various projection -% geometries supported. - -% DISCLAIMER -% It is recommended to use ASTRA version 1.8 or later in order to avoid -% crashing due to GPU memory overflow for big datasets - -% ___Input___: -% params.[] file: -%----------------General Parameters------------------------ -% - .proj_geom (geometry of the projector) [required] -% - .vol_geom (geometry of the reconstructed object) [required] -% - .sino (2D or 3D sinogram) [required] -% - .iterFISTA (iterations for the main loop, default 40) -% - .L_const (Lipschitz constant, default Power method) ) -% - .X_ideal (ideal image, if given) -% - .weights (statisitcal weights for the PWLS model, size of the sinogram) -% - .fidelity (use 'studentt' fidelity) -% - .ROI (Region-of-interest, only if X_ideal is given) -% - .initialize (a 'warm start' using SIRT method from ASTRA) -%----------------Regularization choices------------------------ -% 1 .Regul_Lambda_FGPTV (FGP-TV regularization parameter) -% 2 .Regul_Lambda_SBTV (SplitBregman-TV regularization parameter) -% 3 .Regul_LambdaLLT (Higher order LLT regularization parameter) -% 3.1 .Regul_tauLLT (time step parameter for LLT (HO) term) -% 4 .Regul_LambdaPatchBased_CPU (Patch-based nonlocal regularization parameter) -% 4.1 .Regul_PB_SearchW (ratio of the searching window (e.g. 3 = (2*3+1) = 7 pixels window)) -% 4.2 .Regul_PB_SimilW (ratio of the similarity window (e.g. 1 = (2*1+1) = 3 pixels window)) -% 4.3 .Regul_PB_h (PB penalty function threshold) -% 5 .Regul_LambdaPatchBased_GPU (Patch-based nonlocal regularization parameter) -% 5.1 .Regul_PB_SearchW (ratio of the searching window (e.g. 3 = (2*3+1) = 7 pixels window)) -% 5.2 .Regul_PB_SimilW (ratio of the similarity window (e.g. 1 = (2*1+1) = 3 pixels window)) -% 5.3 .Regul_PB_h (PB penalty function threshold) -% 6 .Regul_LambdaDiffHO (Higher-Order Diffusion regularization parameter) -% 6.1 .Regul_DiffHO_EdgePar (edge-preserving noise related parameter) -% 7 .Regul_LambdaTGV (Total Generalized variation regularization parameter) -% - .Regul_tol (tolerance to terminate regul iterations, default 1.0e-04) -% - .Regul_Iterations (iterations for the selected penalty, default 25) -% - .Regul_Dimension ('2D' or '3D' way to apply regularization, '3D' is the default) -%----------------Ring removal------------------------ -% - .Ring_LambdaR_L1 (regularization parameter for L1-ring minimization, if lambdaR_L1 > 0 then switch on ring removal) -% - .Ring_Alpha (larger values can accelerate convergence but check stability, default 1) -%----------------Visualization parameters------------------------ -% - .show (visualize reconstruction 1/0, (0 default)) -% - .maxvalplot (maximum value to use for imshow[0 maxvalplot]) -% - .slice (for 3D volumes - slice number to imshow) -% ___Output___: -% 1. X - reconstructed image/volume -% 2. output - a structure with -% - .Resid_error - residual error (if X_ideal is given) -% - .objective: value of the objective function -% - .L_const: Lipshitz constant to avoid recalculations - -% References: -% 1. "A Fast Iterative Shrinkage-Thresholding Algorithm for Linear Inverse -% Problems" by A. Beck and M Teboulle -% 2. "Ring artifacts correction in compressed sensing..." by P. Paleo -% 3. "A novel tomographic reconstruction method based on the robust -% Student's t function for suppressing data outliers" D. Kazantsev et.al. -% D. Kazantsev, 2016-17 - -% Dealing with input parameters -if (isfield(params,'proj_geom') == 0) - error('%s \n', 'Please provide ASTRA projection geometry - proj_geom'); -else - proj_geom = params.proj_geom; -end -if (isfield(params,'vol_geom') == 0) - error('%s \n', 'Please provide ASTRA object geometry - vol_geom'); -else - vol_geom = params.vol_geom; -end -N = params.vol_geom.GridColCount; -if (isfield(params,'sino')) - sino = params.sino; - [Detectors, anglesNumb, SlicesZ] = size(sino); - fprintf('%s %i %s %i %s %i %s \n', 'Sinogram has a dimension of', Detectors, 'detectors;', anglesNumb, 'projections;', SlicesZ, 'vertical slices.'); -else - error('%s \n', 'Please provide a sinogram'); -end -if (isfield(params,'iterFISTA')) - iterFISTA = params.iterFISTA; -else - iterFISTA = 40; -end -if (isfield(params,'weights')) - weights = params.weights; -else - weights = ones(size(sino)); -end -if (isfield(params,'fidelity')) - studentt = 0; - if (strcmp(params.fidelity,'studentt') == 1) - studentt = 1; - end -else - studentt = 0; -end -if (isfield(params,'L_const')) - L_const = params.L_const; -else - % using Power method (PM) to establish L constant - fprintf('%s %s %s \n', 'Calculating Lipshitz constant for',proj_geom.type, 'beam geometry...'); - if (strcmp(proj_geom.type,'parallel') || strcmp(proj_geom.type,'fanflat') || strcmp(proj_geom.type,'fanflat_vec')) - % for 2D geometry we can do just one selected slice - niter = 15; % number of iteration for the PM - x1 = rand(N,N,1); - sqweight = sqrt(weights(:,:,1)); - [sino_id, y] = astra_create_sino_cuda(x1, proj_geom, vol_geom); - y = sqweight.*y'; - astra_mex_data2d('delete', sino_id); - for i = 1:niter - [x1] = astra_create_backprojection_cuda((sqweight.*y)', proj_geom, vol_geom); - s = norm(x1(:)); - x1 = x1./s; - [sino_id, y] = astra_create_sino_cuda(x1, proj_geom, vol_geom); - y = sqweight.*y'; - astra_mex_data2d('delete', sino_id); - end - elseif (strcmp(proj_geom.type,'cone') || strcmp(proj_geom.type,'parallel3d') || strcmp(proj_geom.type,'parallel3d_vec') || strcmp(proj_geom.type,'cone_vec')) - % 3D geometry - niter = 8; % number of iteration for PM - x1 = rand(N,N,SlicesZ); - sqweight = sqrt(weights); - [sino_id, y] = astra_create_sino3d_cuda(x1, proj_geom, vol_geom); - y = sqweight.*y; - astra_mex_data3d('delete', sino_id); - - for i = 1:niter - [id,x1] = astra_create_backprojection3d_cuda(sqweight.*y, proj_geom, vol_geom); - s = norm(x1(:)); - x1 = x1/s; - [sino_id, y] = astra_create_sino3d_cuda(x1, proj_geom, vol_geom); - y = sqweight.*y; - astra_mex_data3d('delete', sino_id); - astra_mex_data3d('delete', id); - end - clear x1 - else - error('%s \n', 'No suitable geometry has been found!'); - end - L_const = s; -end -if (isfield(params,'X_ideal')) - X_ideal = params.X_ideal; -else - X_ideal = 'none'; -end -if (isfield(params,'ROI')) - ROI = params.ROI; -else - ROI = find(X_ideal>=0.0); -end -if (isfield(params,'Regul_Lambda_FGPTV')) - lambdaFGP_TV = params.Regul_Lambda_FGPTV; -else - lambdaFGP_TV = 0; -end -if (isfield(params,'Regul_Lambda_SBTV')) - lambdaSB_TV = params.Regul_Lambda_SBTV; -else - lambdaSB_TV = 0; -end -if (isfield(params,'Regul_tol')) - tol = params.Regul_tol; -else - tol = 1.0e-05; -end -if (isfield(params,'Regul_Iterations')) - IterationsRegul = params.Regul_Iterations; -else - IterationsRegul = 45; -end -if (isfield(params,'Regul_LambdaLLT')) - lambdaHO = params.Regul_LambdaLLT; -else - lambdaHO = 0; -end -if (isfield(params,'Regul_iterHO')) - iterHO = params.Regul_iterHO; -else - iterHO = 50; -end -if (isfield(params,'Regul_tauLLT')) - tauHO = params.Regul_tauLLT; -else - tauHO = 0.0001; -end -if (isfield(params,'Regul_LambdaPatchBased_CPU')) - lambdaPB = params.Regul_LambdaPatchBased_CPU; -else - lambdaPB = 0; -end -if (isfield(params,'Regul_LambdaPatchBased_GPU')) - lambdaPB_GPU = params.Regul_LambdaPatchBased_GPU; -else - lambdaPB_GPU = 0; -end -if (isfield(params,'Regul_PB_SearchW')) - SearchW = params.Regul_PB_SearchW; -else - SearchW = 3; % default -end -if (isfield(params,'Regul_PB_SimilW')) - SimilW = params.Regul_PB_SimilW; -else - SimilW = 1; % default -end -if (isfield(params,'Regul_PB_h')) - h_PB = params.Regul_PB_h; -else - h_PB = 0.1; % default -end -if (isfield(params,'Regul_LambdaDiffHO')) - LambdaDiff_HO = params.Regul_LambdaDiffHO; -else - LambdaDiff_HO = 0; -end -if (isfield(params,'Regul_DiffHO_EdgePar')) - LambdaDiff_HO_EdgePar = params.Regul_DiffHO_EdgePar; -else - LambdaDiff_HO_EdgePar = 0.01; -end -if (isfield(params,'Regul_LambdaTGV')) - LambdaTGV = params.Regul_LambdaTGV; -else - LambdaTGV = 0; -end -if (isfield(params,'Ring_LambdaR_L1')) - lambdaR_L1 = params.Ring_LambdaR_L1; -else - lambdaR_L1 = 0; -end -if (isfield(params,'Ring_Alpha')) - alpha_ring = params.Ring_Alpha; % higher values can accelerate ring removal procedure -else - alpha_ring = 1; -end -if (isfield(params,'Regul_Dimension')) - Dimension = params.Regul_Dimension; - if ((strcmp('2D', Dimension) ~= 1) && (strcmp('3D', Dimension) ~= 1)) - Dimension = '3D'; - end -else - Dimension = '3D'; -end -if (isfield(params,'show')) - show = params.show; -else - show = 0; -end -if (isfield(params,'maxvalplot')) - maxvalplot = params.maxvalplot; -else - maxvalplot = 1; -end -if (isfield(params,'slice')) - slice = params.slice; -else - slice = 1; -end -if (isfield(params,'initialize')) - X = params.initialize; - if ((size(X,1) ~= N) || (size(X,2) ~= N) || (size(X,3) ~= SlicesZ)) - error('%s \n', 'The initialized volume has different dimensions!'); - end -else - X = zeros(N,N,SlicesZ, 'single'); % storage for the solution -end -if (isfield(params,'subsets')) - % Ordered Subsets reorganisation of data and angles - subsets = params.subsets; % subsets number - angles = proj_geom.ProjectionAngles; - binEdges = linspace(min(angles),max(angles),subsets+1); - - % assign values to bins - [binsDiscr,~] = histc(angles, [binEdges(1:end-1) Inf]); - - % get rearranged subset indices - IndicesReorg = zeros(length(angles),1); - counterM = 0; - for ii = 1:max(binsDiscr(:)) - counter = 0; - for jj = 1:subsets - curr_index = ii+jj-1 + counter; - if (binsDiscr(jj) >= ii) - counterM = counterM + 1; - IndicesReorg(counterM) = curr_index; - end - counter = (counter + binsDiscr(jj)) - 1; - end - end -else - subsets = 0; % Classical FISTA -end - -%----------------Reconstruction part------------------------ -Resid_error = zeros(iterFISTA,1); % errors vector (if the ground truth is given) -objective = zeros(iterFISTA,1); % objective function values vector - - -if (subsets == 0) - % Classical FISTA - t = 1; - X_t = X; - - r = zeros(Detectors,SlicesZ, 'single'); % 2D array (for 3D data) of sparse "ring" vectors - r_x = r; % another ring variable - residual = zeros(size(sino),'single'); - - % Outer FISTA iterations loop - for i = 1:iterFISTA - - X_old = X; - t_old = t; - r_old = r; - - - if (strcmp(proj_geom.type,'parallel') || strcmp(proj_geom.type,'fanflat') || strcmp(proj_geom.type,'fanflat_vec')) - % if geometry is 2D use slice-by-slice projection-backprojection routine - sino_updt = zeros(size(sino),'single'); - for kkk = 1:SlicesZ - [sino_id, sinoT] = astra_create_sino_cuda(X_t(:,:,kkk), proj_geom, vol_geom); - sino_updt(:,:,kkk) = sinoT'; - astra_mex_data2d('delete', sino_id); - end - else - % for 3D geometry (watch the GPU memory overflow in earlier ASTRA versions < 1.8) - [sino_id, sino_updt] = astra_create_sino3d_cuda(X_t, proj_geom, vol_geom); - astra_mex_data3d('delete', sino_id); - end - - if (lambdaR_L1 > 0) - % the ring removal part (Group-Huber fidelity) - for kkk = 1:anglesNumb - residual(:,kkk,:) = squeeze(weights(:,kkk,:)).*(squeeze(sino_updt(:,kkk,:)) - (squeeze(sino(:,kkk,:)) - alpha_ring.*r_x)); - end - vec = sum(residual,2); - if (SlicesZ > 1) - vec = squeeze(vec(:,1,:)); - end - r = r_x - (1./L_const).*vec; - objective(i) = (0.5*sum(residual(:).^2)); % for the objective function output - elseif (studentt > 0) - % artifacts removal with Students t penalty - residual = weights.*(sino_updt - sino); - for kkk = 1:SlicesZ - res_vec = reshape(residual(:,:,kkk), Detectors*anglesNumb, 1); % 1D vectorized sinogram - %s = 100; - %gr = (2)*res_vec./(s*2 + conj(res_vec).*res_vec); - [ff, gr] = studentst(res_vec, 1); - residual(:,:,kkk) = reshape(gr, Detectors, anglesNumb); - end - objective(i) = ff; % for the objective function output - else - % no ring removal (LS model) - residual = weights.*(sino_updt - sino); - objective(i) = 0.5*norm(residual(:)); % for the objective function output - end - - % if the geometry is 2D use slice-by-slice projection-backprojection routine - if (strcmp(proj_geom.type,'parallel') || strcmp(proj_geom.type,'fanflat') || strcmp(proj_geom.type,'fanflat_vec')) - x_temp = zeros(size(X),'single'); - for kkk = 1:SlicesZ - [x_temp(:,:,kkk)] = astra_create_backprojection_cuda(squeeze(residual(:,:,kkk))', proj_geom, vol_geom); - end - else - [id, x_temp] = astra_create_backprojection3d_cuda(residual, proj_geom, vol_geom); - astra_mex_data3d('delete', id); - end - X = X_t - (1/L_const).*x_temp; - - % ----------------Regularization part------------------------% - if (lambdaFGP_TV > 0) - % FGP-TV regularization - if ((strcmp('2D', Dimension) == 1)) - % 2D regularization - for kkk = 1:SlicesZ - [X(:,:,kkk), f_val] = FGP_TV(single(X(:,:,kkk)), lambdaFGP_TV/L_const, IterationsRegul, tol, 'iso'); - end - else - % 3D regularization - [X, f_val] = FGP_TV(single(X), lambdaFGP_TV/L_const, IterationsRegul, tol, 'iso'); - end - objective(i) = (objective(i) + f_val)./(Detectors*anglesNumb*SlicesZ); - end - if (lambdaSB_TV > 0) - % Split Bregman regularization - if ((strcmp('2D', Dimension) == 1)) - % 2D regularization - for kkk = 1:SlicesZ - X(:,:,kkk) = SplitBregman_TV(single(X(:,:,kkk)), lambdaSB_TV/L_const, IterationsRegul, tol); % (more memory efficent) - end - else - % 3D regularization - X = SplitBregman_TV(single(X), lambdaSB_TV/L_const, IterationsRegul, tol); % (more memory efficent) - end - end - if (lambdaHO > 0) - % Higher Order (LLT) regularization - X2 = zeros(N,N,SlicesZ,'single'); - if ((strcmp('2D', Dimension) == 1)) - % 2D regularization - for kkk = 1:SlicesZ - X2(:,:,kkk) = LLT_model(single(X(:,:,kkk)), lambdaHO/L_const, tauHO, iterHO, 3.0e-05, 0); - end - else - % 3D regularization - X2 = LLT_model(single(X), lambdaHO/L_const, tauHO, iterHO, 3.0e-05, 0); - end - X = 0.5.*(X + X2); % averaged combination of two solutions - - end - if (lambdaPB > 0) - % Patch-Based regularization (can be very slow on CPU) - if ((strcmp('2D', Dimension) == 1)) - % 2D regularization - for kkk = 1:SlicesZ - X(:,:,kkk) = PatchBased_Regul(single(X(:,:,kkk)), SearchW, SimilW, h_PB, lambdaPB/L_const); - end - else - X = PatchBased_Regul(single(X), SearchW, SimilW, h_PB, lambdaPB/L_const); - end - end - if (lambdaPB_GPU > 0) - % Patch-Based regularization (GPU CUDA implementation) - if ((strcmp('2D', Dimension) == 1)) - % 2D regularization - for kkk = 1:SlicesZ - X(:,:,kkk) = NLM_GPU(single(X(:,:,kkk)), SearchW, SimilW, h_PB, lambdaPB_GPU/L_const); - end - else - X = NLM_GPU(single(X), SearchW, SimilW, h_PB, lambdaPB_GPU/L_const); - end - end - if (LambdaDiff_HO > 0) - % Higher-order diffusion penalty (GPU CUDA implementation) - if ((strcmp('2D', Dimension) == 1)) - % 2D regularization - for kkk = 1:SlicesZ - X(:,:,kkk) = Diff4thHajiaboli_GPU(single(X(:,:,kkk)), LambdaDiff_HO_EdgePar, LambdaDiff_HO/L_const, IterationsRegul); - end - else - X = Diff4thHajiaboli_GPU(X, LambdaDiff_HO_EdgePar, LambdaDiff_HO/L_const, IterationsRegul); - end - end - if (LambdaTGV > 0) - % Total Generalized variation (currently only 2D) - lamTGV1 = 1.1; % smoothing trade-off parameters, see Pock's paper - lamTGV2 = 0.8; % second-order term - for kkk = 1:SlicesZ - X(:,:,kkk) = TGV_PD(single(X(:,:,kkk)), LambdaTGV/L_const, lamTGV1, lamTGV2, IterationsRegul); - end - end - - if (lambdaR_L1 > 0) - r = max(abs(r)-lambdaR_L1, 0).*sign(r); % soft-thresholding operator for ring vector - end - - t = (1 + sqrt(1 + 4*t^2))/2; % updating t - X_t = X + ((t_old-1)/t).*(X - X_old); % updating X - - if (lambdaR_L1 > 0) - r_x = r + ((t_old-1)/t).*(r - r_old); % updating r - end - - if (show == 1) - figure(10); imshow(X(:,:,slice), [0 maxvalplot]); - if (lambdaR_L1 > 0) - figure(11); plot(r); title('Rings offset vector') - end - pause(0.01); - end - if (strcmp(X_ideal, 'none' ) == 0) - Resid_error(i) = RMSE(X(ROI), X_ideal(ROI)); - fprintf('%s %i %s %s %.4f %s %s %f \n', 'Iteration Number:', i, '|', 'Error RMSE:', Resid_error(i), '|', 'Objective:', objective(i)); - else - fprintf('%s %i %s %s %f \n', 'Iteration Number:', i, '|', 'Objective:', objective(i)); - end - end -else - % Ordered Subsets (OS) FISTA reconstruction routine (normally one order of magnitude faster than the classical version) - t = 1; - X_t = X; - proj_geomSUB = proj_geom; - - r = zeros(Detectors,SlicesZ, 'single'); % 2D array (for 3D data) of sparse "ring" vectors - r_x = r; % another ring variable - residual2 = zeros(size(sino),'single'); - sino_updt_FULL = zeros(size(sino),'single'); - - - % Outer FISTA iterations loop - for i = 1:iterFISTA - - if ((i > 1) && (lambdaR_L1 > 0)) - % in order to make Group-Huber fidelity work with ordered subsets - % we still need to work with full sinogram - - % the offset variable must be calculated for the whole - % updated sinogram - sino_updt_FULL - for kkk = 1:anglesNumb - residual2(:,kkk,:) = squeeze(weights(:,kkk,:)).*(squeeze(sino_updt_FULL(:,kkk,:)) - (squeeze(sino(:,kkk,:)) - alpha_ring.*r_x)); - end - - r_old = r; - vec = sum(residual2,2); - if (SlicesZ > 1) - vec = squeeze(vec(:,1,:)); - end - r = r_x - (1./L_const).*vec; % update ring variable - end - - % subsets loop - counterInd = 1; - for ss = 1:subsets - X_old = X; - t_old = t; - - numProjSub = binsDiscr(ss); % the number of projections per subset - sino_updt_Sub = zeros(Detectors, numProjSub, SlicesZ,'single'); - CurrSubIndeces = IndicesReorg(counterInd:(counterInd + numProjSub - 1)); % extract indeces attached to the subset - proj_geomSUB.ProjectionAngles = angles(CurrSubIndeces); - - if (strcmp(proj_geom.type,'parallel') || strcmp(proj_geom.type,'fanflat') || strcmp(proj_geom.type,'fanflat_vec')) - % if geometry is 2D use slice-by-slice projection-backprojection routine - for kkk = 1:SlicesZ - [sino_id, sinoT] = astra_create_sino_cuda(X_t(:,:,kkk), proj_geomSUB, vol_geom); - sino_updt_Sub(:,:,kkk) = sinoT'; - astra_mex_data2d('delete', sino_id); - end - else - % for 3D geometry (watch the GPU memory overflow in earlier ASTRA versions < 1.8) - [sino_id, sino_updt_Sub] = astra_create_sino3d_cuda(X_t, proj_geomSUB, vol_geom); - astra_mex_data3d('delete', sino_id); - end - - if (lambdaR_L1 > 0) - % Group-Huber fidelity (ring removal) - residualSub = zeros(Detectors, numProjSub, SlicesZ,'single'); % residual for a chosen subset - for kkk = 1:numProjSub - indC = CurrSubIndeces(kkk); - residualSub(:,kkk,:) = squeeze(weights(:,indC,:)).*(squeeze(sino_updt_Sub(:,kkk,:)) - (squeeze(sino(:,indC,:)) - alpha_ring.*r_x)); - sino_updt_FULL(:,indC,:) = squeeze(sino_updt_Sub(:,kkk,:)); % filling the full sinogram - end - - elseif (studentt > 0) - % student t data fidelity - - % artifacts removal with Students t penalty - residualSub = squeeze(weights(:,CurrSubIndeces,:)).*(sino_updt_Sub - squeeze(sino(:,CurrSubIndeces,:))); - - for kkk = 1:SlicesZ - res_vec = reshape(residualSub(:,:,kkk), Detectors*numProjSub, 1); % 1D vectorized sinogram - %s = 100; - %gr = (2)*res_vec./(s*2 + conj(res_vec).*res_vec); - [ff, gr] = studentst(res_vec, 1); - residualSub(:,:,kkk) = reshape(gr, Detectors, numProjSub); - end - objective(i) = ff; % for the objective function output - else - % PWLS model - residualSub = squeeze(weights(:,CurrSubIndeces,:)).*(sino_updt_Sub - squeeze(sino(:,CurrSubIndeces,:))); - objective(i) = 0.5*norm(residualSub(:)); % for the objective function output - end - - % perform backprojection of a subset - if (strcmp(proj_geom.type,'parallel') || strcmp(proj_geom.type,'fanflat') || strcmp(proj_geom.type,'fanflat_vec')) - % if geometry is 2D use slice-by-slice projection-backprojection routine - x_temp = zeros(size(X),'single'); - for kkk = 1:SlicesZ - [x_temp(:,:,kkk)] = astra_create_backprojection_cuda(squeeze(residualSub(:,:,kkk))', proj_geomSUB, vol_geom); - end - else - [id, x_temp] = astra_create_backprojection3d_cuda(residualSub, proj_geomSUB, vol_geom); - astra_mex_data3d('delete', id); - end - - X = X_t - (1/L_const).*x_temp; - - % ----------------Regularization part------------------------% - if (lambdaFGP_TV > 0) - % FGP-TV regularization - if ((strcmp('2D', Dimension) == 1)) - % 2D regularization - for kkk = 1:SlicesZ - [X(:,:,kkk), f_val] = FGP_TV(single(X(:,:,kkk)), lambdaFGP_TV/(subsets*L_const), IterationsRegul, tol, 'iso'); - end - else - % 3D regularization - [X, f_val] = FGP_TV(single(X), lambdaFGP_TV/(subsets*L_const), IterationsRegul, tol, 'iso'); - end - objective(i) = objective(i) + f_val; - end - if (lambdaSB_TV > 0) - % Split Bregman regularization - if ((strcmp('2D', Dimension) == 1)) - % 2D regularization - for kkk = 1:SlicesZ - X(:,:,kkk) = SplitBregman_TV(single(X(:,:,kkk)), lambdaSB_TV/(subsets*L_const), IterationsRegul, tol); % (more memory efficent) - end - else - % 3D regularization - X = SplitBregman_TV(single(X), lambdaSB_TV/(subsets*L_const), IterationsRegul, tol); % (more memory efficent) - end - end - if (lambdaHO > 0) - % Higher Order (LLT) regularization - X2 = zeros(N,N,SlicesZ,'single'); - if ((strcmp('2D', Dimension) == 1)) - % 2D regularization - for kkk = 1:SlicesZ - X2(:,:,kkk) = LLT_model(single(X(:,:,kkk)), lambdaHO/(subsets*L_const), tauHO/subsets, iterHO, 2.0e-05, 0); - end - else - % 3D regularization - X2 = LLT_model(single(X), lambdaHO/(subsets*L_const), tauHO/subsets, iterHO, 2.0e-05, 0); - end - X = 0.5.*(X + X2); % the averaged combination of two solutions - end - if (lambdaPB > 0) - % Patch-Based regularization (can be slow on CPU) - if ((strcmp('2D', Dimension) == 1)) - % 2D regularization - for kkk = 1:SlicesZ - X(:,:,kkk) = PatchBased_Regul(single(X(:,:,kkk)), SearchW, SimilW, h_PB, lambdaPB/(subsets*L_const)); - end - else - X = PatchBased_Regul(single(X), SearchW, SimilW, h_PB, lambdaPB/(subsets*L_const)); - end - end - if (lambdaPB_GPU > 0) - % Patch-Based regularization (GPU CUDA implementation) - if ((strcmp('2D', Dimension) == 1)) - % 2D regularization - for kkk = 1:SlicesZ - X(:,:,kkk) = NLM_GPU(single(X(:,:,kkk)), SearchW, SimilW, h_PB, lambdaPB_GPU/(subsets*L_const)); - end - else - X = NLM_GPU(single(X), SearchW, SimilW, h_PB, lambdaPB_GPU/(subsets*L_const)); - end - end - if (LambdaDiff_HO > 0) - % Higher-order diffusion penalty (GPU CUDA implementation) - if ((strcmp('2D', Dimension) == 1)) - % 2D regularization - for kkk = 1:SlicesZ - X(:,:,kkk) = Diff4thHajiaboli_GPU(single(X(:,:,kkk)), LambdaDiff_HO_EdgePar, LambdaDiff_HO/(subsets*L_const), round(IterationsRegul/subsets)); - end - else - X = Diff4thHajiaboli_GPU(X, LambdaDiff_HO_EdgePar, LambdaDiff_HO/(subsets*L_const), round(IterationsRegul/subsets)); - end - end - if (LambdaTGV > 0) - % Total Generalized variation (currently only 2D) - lamTGV1 = 1.1; % smoothing trade-off parameters, see Pock's paper - lamTGV2 = 0.5; % second-order term - for kkk = 1:SlicesZ - X(:,:,kkk) = TGV_PD(single(X(:,:,kkk)), LambdaTGV/(subsets*L_const), lamTGV1, lamTGV2, IterationsRegul); - end - end - - t = (1 + sqrt(1 + 4*t^2))/2; % updating t - X_t = X + ((t_old-1)/t).*(X - X_old); % updating X - counterInd = counterInd + numProjSub; - end - - if (i == 1) - r_old = r; - end - - % working with a 'ring vector' - if (lambdaR_L1 > 0) - r = max(abs(r)-lambdaR_L1, 0).*sign(r); % soft-thresholding operator for ring vector - r_x = r + ((t_old-1)/t).*(r - r_old); % updating r - end - - if (show == 1) - figure(10); imshow(X(:,:,slice), [0 maxvalplot]); - if (lambdaR_L1 > 0) - figure(11); plot(r); title('Rings offset vector') - end - pause(0.01); - end - - if (strcmp(X_ideal, 'none' ) == 0) - Resid_error(i) = RMSE(X(ROI), X_ideal(ROI)); - fprintf('%s %i %s %s %.4f %s %s %f \n', 'Iteration Number:', i, '|', 'Error RMSE:', Resid_error(i), '|', 'Objective:', objective(i)); - else - fprintf('%s %i %s %s %f \n', 'Iteration Number:', i, '|', 'Objective:', objective(i)); - end - end -end - -output.Resid_error = Resid_error; -output.objective = objective; -output.L_const = L_const; - -end diff --git a/main_func/regularizers_CPU/FGP_TV.c b/main_func/regularizers_CPU/FGP_TV.c deleted file mode 100644 index 30cea1a..0000000 --- a/main_func/regularizers_CPU/FGP_TV.c +++ /dev/null @@ -1,216 +0,0 @@ -/* -This work is part of the Core Imaging Library developed by -Visual Analytics and Imaging System Group of the Science Technology -Facilities Council, STFC - -Copyright 2017 Daniil Kazantsev -Copyright 2017 Srikanth Nagella, Edoardo Pasca - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at -http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -#include "matrix.h" -#include "mex.h" -#include "FGP_TV_core.h" - -/* C-OMP implementation of FGP-TV [1] denoising/regularization model (2D/3D case) - * - * Input Parameters: - * 1. Noisy image/volume [REQUIRED] - * 2. lambda - regularization parameter [REQUIRED] - * 3. Number of iterations [OPTIONAL parameter] - * 4. eplsilon: tolerance constant [OPTIONAL parameter] - * 5. TV-type: 'iso' or 'l1' [OPTIONAL parameter] - * - * Output: - * [1] Filtered/regularized image - * [2] last function value - * - * Example of image denoising: - * figure; - * Im = double(imread('lena_gray_256.tif'))/255; % loading image - * u0 = Im + .05*randn(size(Im)); % adding noise - * u = FGP_TV(single(u0), 0.05, 100, 1e-04); - * - * to compile with OMP support: mex FGP_TV.c CFLAGS="\$CFLAGS -fopenmp -Wall -std=c99" LDFLAGS="\$LDFLAGS -fopenmp" - * This function is based on the Matlab's code and paper by - * [1] Amir Beck and Marc Teboulle, "Fast Gradient-Based Algorithms for Constrained Total Variation Image Denoising and Deblurring Problems" - * - * D. Kazantsev, 2016-17 - * - */ - - -void mexFunction( - int nlhs, mxArray *plhs[], - int nrhs, const mxArray *prhs[]) - -{ - int number_of_dims, iter, dimX, dimY, dimZ, ll, j, count, methTV; - const int *dim_array; - float *A, *D=NULL, *D_old=NULL, *P1=NULL, *P2=NULL, *P3=NULL, *P1_old=NULL, *P2_old=NULL, *P3_old=NULL, *R1=NULL, *R2=NULL, *R3=NULL, lambda, tk, tkp1, re, re1, re_old, epsil; - - number_of_dims = mxGetNumberOfDimensions(prhs[0]); - dim_array = mxGetDimensions(prhs[0]); - - /*Handling Matlab input data*/ - if ((nrhs < 2) || (nrhs > 5)) mexErrMsgTxt("At least 2 parameters is required: Image(2D/3D), Regularization parameter. The full list of parameters: Image(2D/3D), Regularization parameter, iterations number, tolerance, penalty type ('iso' or 'l1')"); - - A = (float *) mxGetData(prhs[0]); /*noisy image (2D/3D) */ - lambda = (float) mxGetScalar(prhs[1]); /* regularization parameter */ - iter = 50; /* default iterations number */ - epsil = 0.0001; /* default tolerance constant */ - methTV = 0; /* default isotropic TV penalty */ - - if ((nrhs == 3) || (nrhs == 4) || (nrhs == 5)) iter = (int) mxGetScalar(prhs[2]); /* iterations number */ - if ((nrhs == 4) || (nrhs == 5)) epsil = (float) mxGetScalar(prhs[3]); /* tolerance constant */ - if (nrhs == 5) { - char *penalty_type; - penalty_type = mxArrayToString(prhs[4]); /* choosing TV penalty: 'iso' or 'l1', 'iso' is the default */ - if ((strcmp(penalty_type, "l1") != 0) && (strcmp(penalty_type, "iso") != 0)) mexErrMsgTxt("Choose TV type: 'iso' or 'l1',"); - if (strcmp(penalty_type, "l1") == 0) methTV = 1; /* enable 'l1' penalty */ - mxFree(penalty_type); - } - /*output function value (last iteration) */ - plhs[1] = mxCreateNumericMatrix(1, 1, mxSINGLE_CLASS, mxREAL); - float *funcvalA = (float *) mxGetData(plhs[1]); - - if (mxGetClassID(prhs[0]) != mxSINGLE_CLASS) {mexErrMsgTxt("The input image must be in a single precision"); } - - /*Handling Matlab output data*/ - dimX = dim_array[0]; dimY = dim_array[1]; dimZ = dim_array[2]; - - tk = 1.0f; - tkp1=1.0f; - count = 0; - re_old = 0.0f; - - if (number_of_dims == 2) { - dimZ = 1; /*2D case*/ - D = (float*)mxGetPr(plhs[0] = mxCreateNumericArray(2, dim_array, mxSINGLE_CLASS, mxREAL)); - D_old = (float*)mxGetPr(mxCreateNumericArray(2, dim_array, mxSINGLE_CLASS, mxREAL)); - P1 = (float*)mxGetPr(mxCreateNumericArray(2, dim_array, mxSINGLE_CLASS, mxREAL)); - P2 = (float*)mxGetPr(mxCreateNumericArray(2, dim_array, mxSINGLE_CLASS, mxREAL)); - P1_old = (float*)mxGetPr(mxCreateNumericArray(2, dim_array, mxSINGLE_CLASS, mxREAL)); - P2_old = (float*)mxGetPr(mxCreateNumericArray(2, dim_array, mxSINGLE_CLASS, mxREAL)); - R1 = (float*)mxGetPr(mxCreateNumericArray(2, dim_array, mxSINGLE_CLASS, mxREAL)); - R2 = (float*)mxGetPr(mxCreateNumericArray(2, dim_array, mxSINGLE_CLASS, mxREAL)); - - /* begin iterations */ - for(ll=0; ll<iter; ll++) { - - /* computing the gradient of the objective function */ - Obj_func2D(A, D, R1, R2, lambda, dimX, dimY); - - /*Taking a step towards minus of the gradient*/ - Grad_func2D(P1, P2, D, R1, R2, lambda, dimX, dimY); - - /* projection step */ - Proj_func2D(P1, P2, methTV, dimX, dimY); - - /*updating R and t*/ - tkp1 = (1.0f + sqrt(1.0f + 4.0f*tk*tk))*0.5f; - Rupd_func2D(P1, P1_old, P2, P2_old, R1, R2, tkp1, tk, dimX, dimY); - - /* calculate norm */ - re = 0.0f; re1 = 0.0f; - for(j=0; j<dimX*dimY*dimZ; j++) - { - re += pow(D[j] - D_old[j],2); - re1 += pow(D[j],2); - } - re = sqrt(re)/sqrt(re1); - if (re < epsil) count++; - if (count > 4) { - Obj_func_CALC2D(A, D, funcvalA, lambda, dimX, dimY); - break; } - - /* check that the residual norm is decreasing */ - if (ll > 2) { - if (re > re_old) { - Obj_func_CALC2D(A, D, funcvalA, lambda, dimX, dimY); - break; }} - re_old = re; - /*printf("%f %i %i \n", re, ll, count); */ - - /*storing old values*/ - copyIm(D, D_old, dimX, dimY, dimZ); - copyIm(P1, P1_old, dimX, dimY, dimZ); - copyIm(P2, P2_old, dimX, dimY, dimZ); - tk = tkp1; - - /* calculating the objective function value */ - if (ll == (iter-1)) Obj_func_CALC2D(A, D, funcvalA, lambda, dimX, dimY); - } - printf("FGP-TV iterations stopped at iteration %i with the function value %f \n", ll, funcvalA[0]); - } - if (number_of_dims == 3) { - D = (float*)mxGetPr(plhs[0] = mxCreateNumericArray(3, dim_array, mxSINGLE_CLASS, mxREAL)); - D_old = (float*)mxGetPr(mxCreateNumericArray(3, dim_array, mxSINGLE_CLASS, mxREAL)); - P1 = (float*)mxGetPr(mxCreateNumericArray(3, dim_array, mxSINGLE_CLASS, mxREAL)); - P2 = (float*)mxGetPr(mxCreateNumericArray(3, dim_array, mxSINGLE_CLASS, mxREAL)); - P3 = (float*)mxGetPr(mxCreateNumericArray(3, dim_array, mxSINGLE_CLASS, mxREAL)); - P1_old = (float*)mxGetPr(mxCreateNumericArray(3, dim_array, mxSINGLE_CLASS, mxREAL)); - P2_old = (float*)mxGetPr(mxCreateNumericArray(3, dim_array, mxSINGLE_CLASS, mxREAL)); - P3_old = (float*)mxGetPr(mxCreateNumericArray(3, dim_array, mxSINGLE_CLASS, mxREAL)); - R1 = (float*)mxGetPr(mxCreateNumericArray(3, dim_array, mxSINGLE_CLASS, mxREAL)); - R2 = (float*)mxGetPr(mxCreateNumericArray(3, dim_array, mxSINGLE_CLASS, mxREAL)); - R3 = (float*)mxGetPr(mxCreateNumericArray(3, dim_array, mxSINGLE_CLASS, mxREAL)); - - /* begin iterations */ - for(ll=0; ll<iter; ll++) { - - /* computing the gradient of the objective function */ - Obj_func3D(A, D, R1, R2, R3,lambda, dimX, dimY, dimZ); - - /*Taking a step towards minus of the gradient*/ - Grad_func3D(P1, P2, P3, D, R1, R2, R3, lambda, dimX, dimY, dimZ); - - /* projection step */ - Proj_func3D(P1, P2, P3, dimX, dimY, dimZ); - - /*updating R and t*/ - tkp1 = (1.0f + sqrt(1.0f + 4.0f*tk*tk))*0.5f; - Rupd_func3D(P1, P1_old, P2, P2_old, P3, P3_old, R1, R2, R3, tkp1, tk, dimX, dimY, dimZ); - - /* calculate norm - stopping rules*/ - re = 0.0f; re1 = 0.0f; - for(j=0; j<dimX*dimY*dimZ; j++) - { - re += pow(D[j] - D_old[j],2); - re1 += pow(D[j],2); - } - re = sqrt(re)/sqrt(re1); - /* stop if the norm residual is less than the tolerance EPS */ - if (re < epsil) count++; - if (count > 3) { - Obj_func_CALC3D(A, D, funcvalA, lambda, dimX, dimY, dimZ); - break;} - - /* check that the residual norm is decreasing */ - if (ll > 2) { - if (re > re_old) { - Obj_func_CALC3D(A, D, funcvalA, lambda, dimX, dimY, dimZ); - }} - re_old = re; - /*printf("%f %i %i \n", re, ll, count); */ - - /*storing old values*/ - copyIm(D, D_old, dimX, dimY, dimZ); - copyIm(P1, P1_old, dimX, dimY, dimZ); - copyIm(P2, P2_old, dimX, dimY, dimZ); - copyIm(P3, P3_old, dimX, dimY, dimZ); - tk = tkp1; - - if (ll == (iter-1)) Obj_func_CALC3D(A, D, funcvalA, lambda, dimX, dimY, dimZ); - } - printf("FGP-TV iterations stopped at iteration %i with the function value %f \n", ll, funcvalA[0]); - } -} diff --git a/main_func/regularizers_CPU/LLT_model.c b/main_func/regularizers_CPU/LLT_model.c deleted file mode 100644 index 0b07b47..0000000 --- a/main_func/regularizers_CPU/LLT_model.c +++ /dev/null @@ -1,169 +0,0 @@ -/* -This work is part of the Core Imaging Library developed by -Visual Analytics and Imaging System Group of the Science Technology -Facilities Council, STFC - -Copyright 2017 Daniil Kazantsev -Copyright 2017 Srikanth Nagella, Edoardo Pasca - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at -http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -#include "mex.h" -#include "matrix.h" -#include "LLT_model_core.h" - -/* C-OMP implementation of Lysaker, Lundervold and Tai (LLT) model of higher order regularization penalty -* -* Input Parameters: -* 1. U0 - original noise image/volume -* 2. lambda - regularization parameter -* 3. tau - time-step for explicit scheme -* 4. iter - iterations number -* 5. epsil - tolerance constant (to terminate earlier) -* 6. switcher - default is 0, switch to (1) to restrictive smoothing in Z dimension (in test) -* -* Output: -* Filtered/regularized image -* -* Example: -* figure; -* Im = double(imread('lena_gray_256.tif'))/255; % loading image -* u0 = Im + .03*randn(size(Im)); % adding noise -* [Den] = LLT_model(single(u0), 10, 0.1, 1); -* -* -* to compile with OMP support: mex LLT_model.c CFLAGS="\$CFLAGS -fopenmp -Wall -std=c99" LDFLAGS="\$LDFLAGS -fopenmp" -* References: Lysaker, Lundervold and Tai (LLT) 2003, IEEE -* -* 28.11.16/Harwell -*/ - -void mexFunction( - int nlhs, mxArray *plhs[], - int nrhs, const mxArray *prhs[]) - -{ - int number_of_dims, iter, dimX, dimY, dimZ, ll, j, count, switcher; - const int *dim_array; - float *U0, *U=NULL, *U_old=NULL, *D1=NULL, *D2=NULL, *D3=NULL, lambda, tau, re, re1, epsil, re_old; - unsigned short *Map=NULL; - - number_of_dims = mxGetNumberOfDimensions(prhs[0]); - dim_array = mxGetDimensions(prhs[0]); - - /*Handling Matlab input data*/ - U0 = (float *) mxGetData(prhs[0]); /*origanal noise image/volume*/ - if (mxGetClassID(prhs[0]) != mxSINGLE_CLASS) {mexErrMsgTxt("The input in single precision is required"); } - lambda = (float) mxGetScalar(prhs[1]); /*regularization parameter*/ - tau = (float) mxGetScalar(prhs[2]); /* time-step */ - iter = (int) mxGetScalar(prhs[3]); /*iterations number*/ - epsil = (float) mxGetScalar(prhs[4]); /* tolerance constant */ - switcher = (int) mxGetScalar(prhs[5]); /*switch on (1) restrictive smoothing in Z dimension*/ - - /*Handling Matlab output data*/ - dimX = dim_array[0]; dimY = dim_array[1]; dimZ = 1; - - if (number_of_dims == 2) { - /*2D case*/ - U = (float*)mxGetPr(plhs[0] = mxCreateNumericArray(2, dim_array, mxSINGLE_CLASS, mxREAL)); - U_old = (float*)mxGetPr(mxCreateNumericArray(2, dim_array, mxSINGLE_CLASS, mxREAL)); - D1 = (float*)mxGetPr(mxCreateNumericArray(2, dim_array, mxSINGLE_CLASS, mxREAL)); - D2 = (float*)mxGetPr(mxCreateNumericArray(2, dim_array, mxSINGLE_CLASS, mxREAL)); - } - else if (number_of_dims == 3) { - /*3D case*/ - dimZ = dim_array[2]; - U = (float*)mxGetPr(plhs[0] = mxCreateNumericArray(3, dim_array, mxSINGLE_CLASS, mxREAL)); - U_old = (float*)mxGetPr(mxCreateNumericArray(3, dim_array, mxSINGLE_CLASS, mxREAL)); - D1 = (float*)mxGetPr(mxCreateNumericArray(3, dim_array, mxSINGLE_CLASS, mxREAL)); - D2 = (float*)mxGetPr(mxCreateNumericArray(3, dim_array, mxSINGLE_CLASS, mxREAL)); - D3 = (float*)mxGetPr(mxCreateNumericArray(3, dim_array, mxSINGLE_CLASS, mxREAL)); - if (switcher != 0) { - Map = (unsigned short*)mxGetPr(plhs[1] = mxCreateNumericArray(3, dim_array, mxUINT16_CLASS, mxREAL)); - } - } - else {mexErrMsgTxt("The input data should be 2D or 3D");} - - /*Copy U0 to U*/ - copyIm(U0, U, dimX, dimY, dimZ); - - count = 1; - re_old = 0.0f; - if (number_of_dims == 2) { - for(ll = 0; ll < iter; ll++) { - - copyIm(U, U_old, dimX, dimY, dimZ); - - /*estimate inner derrivatives */ - der2D(U, D1, D2, dimX, dimY, dimZ); - /* calculate div^2 and update */ - div_upd2D(U0, U, D1, D2, dimX, dimY, dimZ, lambda, tau); - - /* calculate norm to terminate earlier */ - re = 0.0f; re1 = 0.0f; - for(j=0; j<dimX*dimY*dimZ; j++) - { - re += pow(U_old[j] - U[j],2); - re1 += pow(U_old[j],2); - } - re = sqrt(re)/sqrt(re1); - if (re < epsil) count++; - if (count > 4) break; - - /* check that the residual norm is decreasing */ - if (ll > 2) { - if (re > re_old) break; - } - re_old = re; - - } /*end of iterations*/ - printf("HO iterations stopped at iteration: %i\n", ll); - } - /*3D version*/ - if (number_of_dims == 3) { - - if (switcher == 1) { - /* apply restrictive smoothing */ - calcMap(U, Map, dimX, dimY, dimZ); - /*clear outliers */ - cleanMap(Map, dimX, dimY, dimZ); - } - for(ll = 0; ll < iter; ll++) { - - copyIm(U, U_old, dimX, dimY, dimZ); - - /*estimate inner derrivatives */ - der3D(U, D1, D2, D3, dimX, dimY, dimZ); - /* calculate div^2 and update */ - div_upd3D(U0, U, D1, D2, D3, Map, switcher, dimX, dimY, dimZ, lambda, tau); - - /* calculate norm to terminate earlier */ - re = 0.0f; re1 = 0.0f; - for(j=0; j<dimX*dimY*dimZ; j++) - { - re += pow(U_old[j] - U[j],2); - re1 += pow(U_old[j],2); - } - re = sqrt(re)/sqrt(re1); - if (re < epsil) count++; - if (count > 4) break; - - /* check that the residual norm is decreasing */ - if (ll > 2) { - if (re > re_old) break; - } - re_old = re; - - } /*end of iterations*/ - printf("HO iterations stopped at iteration: %i\n", ll); - } -} diff --git a/main_func/regularizers_CPU/SplitBregman_TV.c b/main_func/regularizers_CPU/SplitBregman_TV.c deleted file mode 100644 index 38f6a9d..0000000 --- a/main_func/regularizers_CPU/SplitBregman_TV.c +++ /dev/null @@ -1,179 +0,0 @@ -/* -This work is part of the Core Imaging Library developed by -Visual Analytics and Imaging System Group of the Science Technology -Facilities Council, STFC - -Copyright 2017 Daniil Kazantsev -Copyright 2017 Srikanth Nagella, Edoardo Pasca - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at -http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -#include "mex.h" -#include <matrix.h> -#include "SplitBregman_TV_core.h" - -/* C-OMP implementation of Split Bregman - TV denoising-regularization model (2D/3D) - * - * Input Parameters: - * 1. Noisy image/volume - * 2. lambda - regularization parameter - * 3. Number of iterations [OPTIONAL parameter] - * 4. eplsilon - tolerance constant [OPTIONAL parameter] - * 5. TV-type: 'iso' or 'l1' [OPTIONAL parameter] - * - * Output: - * Filtered/regularized image - * - * Example: - * figure; - * Im = double(imread('lena_gray_256.tif'))/255; % loading image - * u0 = Im + .05*randn(size(Im)); u0(u0 < 0) = 0; - * u = SplitBregman_TV(single(u0), 10, 30, 1e-04); - * - * to compile with OMP support: mex SplitBregman_TV.c CFLAGS="\$CFLAGS -fopenmp -Wall -std=c99" LDFLAGS="\$LDFLAGS -fopenmp" - * References: - * The Split Bregman Method for L1 Regularized Problems, by Tom Goldstein and Stanley Osher. - * D. Kazantsev, 2016* - */ - - -void mexFunction( - int nlhs, mxArray *plhs[], - int nrhs, const mxArray *prhs[]) - -{ - int number_of_dims, iter, dimX, dimY, dimZ, ll, j, count, methTV; - const int *dim_array; - float *A, *U=NULL, *U_old=NULL, *Dx=NULL, *Dy=NULL, *Dz=NULL, *Bx=NULL, *By=NULL, *Bz=NULL, lambda, mu, epsil, re, re1, re_old; - - number_of_dims = mxGetNumberOfDimensions(prhs[0]); - dim_array = mxGetDimensions(prhs[0]); - - /*Handling Matlab input data*/ - if ((nrhs < 2) || (nrhs > 5)) mexErrMsgTxt("At least 2 parameters is required: Image(2D/3D), Regularization parameter. The full list of parameters: Image(2D/3D), Regularization parameter, iterations number, tolerance, penalty type ('iso' or 'l1')"); - - /*Handling Matlab input data*/ - A = (float *) mxGetData(prhs[0]); /*noisy image (2D/3D) */ - mu = (float) mxGetScalar(prhs[1]); /* regularization parameter */ - iter = 35; /* default iterations number */ - epsil = 0.0001; /* default tolerance constant */ - methTV = 0; /* default isotropic TV penalty */ - if ((nrhs == 3) || (nrhs == 4) || (nrhs == 5)) iter = (int) mxGetScalar(prhs[2]); /* iterations number */ - if ((nrhs == 4) || (nrhs == 5)) epsil = (float) mxGetScalar(prhs[3]); /* tolerance constant */ - if (nrhs == 5) { - char *penalty_type; - penalty_type = mxArrayToString(prhs[4]); /* choosing TV penalty: 'iso' or 'l1', 'iso' is the default */ - if ((strcmp(penalty_type, "l1") != 0) && (strcmp(penalty_type, "iso") != 0)) mexErrMsgTxt("Choose TV type: 'iso' or 'l1',"); - if (strcmp(penalty_type, "l1") == 0) methTV = 1; /* enable 'l1' penalty */ - mxFree(penalty_type); - } - if (mxGetClassID(prhs[0]) != mxSINGLE_CLASS) {mexErrMsgTxt("The input image must be in a single precision"); } - - lambda = 2.0f*mu; - count = 1; - re_old = 0.0f; - /*Handling Matlab output data*/ - dimY = dim_array[0]; dimX = dim_array[1]; dimZ = dim_array[2]; - - if (number_of_dims == 2) { - dimZ = 1; /*2D case*/ - U = (float*)mxGetPr(plhs[0] = mxCreateNumericArray(2, dim_array, mxSINGLE_CLASS, mxREAL)); - U_old = (float*)mxGetPr(mxCreateNumericArray(2, dim_array, mxSINGLE_CLASS, mxREAL)); - Dx = (float*)mxGetPr(mxCreateNumericArray(2, dim_array, mxSINGLE_CLASS, mxREAL)); - Dy = (float*)mxGetPr(mxCreateNumericArray(2, dim_array, mxSINGLE_CLASS, mxREAL)); - Bx = (float*)mxGetPr(mxCreateNumericArray(2, dim_array, mxSINGLE_CLASS, mxREAL)); - By = (float*)mxGetPr(mxCreateNumericArray(2, dim_array, mxSINGLE_CLASS, mxREAL)); - - copyIm(A, U, dimX, dimY, dimZ); /*initialize */ - - /* begin outer SB iterations */ - for(ll=0; ll<iter; ll++) { - - /*storing old values*/ - copyIm(U, U_old, dimX, dimY, dimZ); - - /*GS iteration */ - gauss_seidel2D(U, A, Dx, Dy, Bx, By, dimX, dimY, lambda, mu); - - if (methTV == 1) updDxDy_shrinkAniso2D(U, Dx, Dy, Bx, By, dimX, dimY, lambda); - else updDxDy_shrinkIso2D(U, Dx, Dy, Bx, By, dimX, dimY, lambda); - - updBxBy2D(U, Dx, Dy, Bx, By, dimX, dimY); - - /* calculate norm to terminate earlier */ - re = 0.0f; re1 = 0.0f; - for(j=0; j<dimX*dimY*dimZ; j++) - { - re += pow(U_old[j] - U[j],2); - re1 += pow(U_old[j],2); - } - re = sqrt(re)/sqrt(re1); - if (re < epsil) count++; - if (count > 4) break; - - /* check that the residual norm is decreasing */ - if (ll > 2) { - if (re > re_old) break; - } - re_old = re; - /*printf("%f %i %i \n", re, ll, count); */ - - /*copyIm(U_old, U, dimX, dimY, dimZ); */ - } - printf("SB iterations stopped at iteration: %i\n", ll); - } - if (number_of_dims == 3) { - U = (float*)mxGetPr(plhs[0] = mxCreateNumericArray(3, dim_array, mxSINGLE_CLASS, mxREAL)); - U_old = (float*)mxGetPr(mxCreateNumericArray(3, dim_array, mxSINGLE_CLASS, mxREAL)); - Dx = (float*)mxGetPr(mxCreateNumericArray(3, dim_array, mxSINGLE_CLASS, mxREAL)); - Dy = (float*)mxGetPr(mxCreateNumericArray(3, dim_array, mxSINGLE_CLASS, mxREAL)); - Dz = (float*)mxGetPr(mxCreateNumericArray(3, dim_array, mxSINGLE_CLASS, mxREAL)); - Bx = (float*)mxGetPr(mxCreateNumericArray(3, dim_array, mxSINGLE_CLASS, mxREAL)); - By = (float*)mxGetPr(mxCreateNumericArray(3, dim_array, mxSINGLE_CLASS, mxREAL)); - Bz = (float*)mxGetPr(mxCreateNumericArray(3, dim_array, mxSINGLE_CLASS, mxREAL)); - - copyIm(A, U, dimX, dimY, dimZ); /*initialize */ - - /* begin outer SB iterations */ - for(ll=0; ll<iter; ll++) { - - /*storing old values*/ - copyIm(U, U_old, dimX, dimY, dimZ); - - /*GS iteration */ - gauss_seidel3D(U, A, Dx, Dy, Dz, Bx, By, Bz, dimX, dimY, dimZ, lambda, mu); - - if (methTV == 1) updDxDyDz_shrinkAniso3D(U, Dx, Dy, Dz, Bx, By, Bz, dimX, dimY, dimZ, lambda); - else updDxDyDz_shrinkIso3D(U, Dx, Dy, Dz, Bx, By, Bz, dimX, dimY, dimZ, lambda); - - updBxByBz3D(U, Dx, Dy, Dz, Bx, By, Bz, dimX, dimY, dimZ); - - /* calculate norm to terminate earlier */ - re = 0.0f; re1 = 0.0f; - for(j=0; j<dimX*dimY*dimZ; j++) - { - re += pow(U[j] - U_old[j],2); - re1 += pow(U[j],2); - } - re = sqrt(re)/sqrt(re1); - if (re < epsil) count++; - if (count > 4) break; - - /* check that the residual norm is decreasing */ - if (ll > 2) { - if (re > re_old) break; } - /*printf("%f %i %i \n", re, ll, count); */ - re_old = re; - } - printf("SB iterations stopped at iteration: %i\n", ll); - } -}
\ No newline at end of file diff --git a/main_func/regularizers_CPU/TGV_PD.c b/main_func/regularizers_CPU/TGV_PD.c deleted file mode 100644 index c9cb440..0000000 --- a/main_func/regularizers_CPU/TGV_PD.c +++ /dev/null @@ -1,144 +0,0 @@ -/* -This work is part of the Core Imaging Library developed by -Visual Analytics and Imaging System Group of the Science Technology -Facilities Council, STFC - -Copyright 2017 Daniil Kazantsev -Copyright 2017 Srikanth Nagella, Edoardo Pasca - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at -http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -#include "TGV_PD_core.h" -#include "mex.h" - -/* C-OMP implementation of Primal-Dual denoising method for - * Total Generilized Variation (TGV)-L2 model (2D case only) - * - * Input Parameters: - * 1. Noisy image/volume (2D) - * 2. lambda - regularization parameter - * 3. parameter to control first-order term (alpha1) - * 4. parameter to control the second-order term (alpha0) - * 5. Number of CP iterations - * - * Output: - * Filtered/regularized image - * - * Example: - * figure; - * Im = double(imread('lena_gray_256.tif'))/255; % loading image - * u0 = Im + .03*randn(size(Im)); % adding noise - * tic; u = TGV_PD(single(u0), 0.02, 1.3, 1, 550); toc; - * - * to compile with OMP support: mex TGV_PD.c TGV_PD_core.c CFLAGS="\$CFLAGS -fopenmp -Wall -std=c99" LDFLAGS="\$LDFLAGS -fopenmp" - * References: - * K. Bredies "Total Generalized Variation" - * - * 28.11.16/Harwell - */ - -void mexFunction( - int nlhs, mxArray *plhs[], - int nrhs, const mxArray *prhs[]) - -{ - int number_of_dims, iter, dimX, dimY, dimZ, ll; - const int *dim_array; - float *A, *U, *U_old, *P1, *P2, *Q1, *Q2, *Q3, *V1, *V1_old, *V2, *V2_old, lambda, L2, tau, sigma, alpha1, alpha0; - - number_of_dims = mxGetNumberOfDimensions(prhs[0]); - dim_array = mxGetDimensions(prhs[0]); - - /*Handling Matlab input data*/ - A = (float *) mxGetData(prhs[0]); /*origanal noise image/volume*/ - if (mxGetClassID(prhs[0]) != mxSINGLE_CLASS) {mexErrMsgTxt("The input in single precision is required"); } - lambda = (float) mxGetScalar(prhs[1]); /*regularization parameter*/ - alpha1 = (float) mxGetScalar(prhs[2]); /*first-order term*/ - alpha0 = (float) mxGetScalar(prhs[3]); /*second-order term*/ - iter = (int) mxGetScalar(prhs[4]); /*iterations number*/ - if(nrhs != 5) mexErrMsgTxt("Five input parameters is reqired: Image(2D/3D), Regularization parameter, alpha1, alpha0, Iterations"); - - /*Handling Matlab output data*/ - dimX = dim_array[0]; dimY = dim_array[1]; - - if (number_of_dims == 2) { - /*2D case*/ - dimZ = 1; - U = (float*)mxGetPr(plhs[0] = mxCreateNumericArray(2, dim_array, mxSINGLE_CLASS, mxREAL)); - - /*dual variables*/ - P1 = (float*)mxGetPr(mxCreateNumericArray(2, dim_array, mxSINGLE_CLASS, mxREAL)); - P2 = (float*)mxGetPr(mxCreateNumericArray(2, dim_array, mxSINGLE_CLASS, mxREAL)); - - Q1 = (float*)mxGetPr(mxCreateNumericArray(2, dim_array, mxSINGLE_CLASS, mxREAL)); - Q2 = (float*)mxGetPr(mxCreateNumericArray(2, dim_array, mxSINGLE_CLASS, mxREAL)); - Q3 = (float*)mxGetPr(mxCreateNumericArray(2, dim_array, mxSINGLE_CLASS, mxREAL)); - - U_old = (float*)mxGetPr(mxCreateNumericArray(2, dim_array, mxSINGLE_CLASS, mxREAL)); - - V1 = (float*)mxGetPr(mxCreateNumericArray(2, dim_array, mxSINGLE_CLASS, mxREAL)); - V1_old = (float*)mxGetPr(mxCreateNumericArray(2, dim_array, mxSINGLE_CLASS, mxREAL)); - V2 = (float*)mxGetPr(mxCreateNumericArray(2, dim_array, mxSINGLE_CLASS, mxREAL)); - V2_old = (float*)mxGetPr(mxCreateNumericArray(2, dim_array, mxSINGLE_CLASS, mxREAL)); - - - /*printf("%i \n", i);*/ - L2 = 12.0f; /*Lipshitz constant*/ - tau = 1.0/pow(L2,0.5); - sigma = 1.0/pow(L2,0.5); - - /*Copy A to U*/ - copyIm(A, U, dimX, dimY, dimZ); - - /* Here primal-dual iterations begin for 2D */ - for(ll = 0; ll < iter; ll++) { - - /* Calculate Dual Variable P */ - DualP_2D(U, V1, V2, P1, P2, dimX, dimY, dimZ, sigma); - - /*Projection onto convex set for P*/ - ProjP_2D(P1, P2, dimX, dimY, dimZ, alpha1); - - /* Calculate Dual Variable Q */ - DualQ_2D(V1, V2, Q1, Q2, Q3, dimX, dimY, dimZ, sigma); - - /*Projection onto convex set for Q*/ - ProjQ_2D(Q1, Q2, Q3, dimX, dimY, dimZ, alpha0); - - /*saving U into U_old*/ - copyIm(U, U_old, dimX, dimY, dimZ); - - /*adjoint operation -> divergence and projection of P*/ - DivProjP_2D(U, A, P1, P2, dimX, dimY, dimZ, lambda, tau); - - /*get updated solution U*/ - newU(U, U_old, dimX, dimY, dimZ); - - /*saving V into V_old*/ - copyIm(V1, V1_old, dimX, dimY, dimZ); - copyIm(V2, V2_old, dimX, dimY, dimZ); - - /* upd V*/ - UpdV_2D(V1, V2, P1, P2, Q1, Q2, Q3, dimX, dimY, dimZ, tau); - - /*get new V*/ - newU(V1, V1_old, dimX, dimY, dimZ); - newU(V2, V2_old, dimX, dimY, dimZ); - } /*end of iterations*/ - } - else if (number_of_dims == 3) { - mexErrMsgTxt("The input data should be a 2D array"); - /*3D case*/ - } - else {mexErrMsgTxt("The input data should be a 2D array");} - -} diff --git a/main_func/studentst.m b/main_func/studentst.m deleted file mode 100644 index 93e0a0a..0000000 --- a/main_func/studentst.m +++ /dev/null @@ -1,47 +0,0 @@ -function [f,g,h,s,k] = studentst(r,k,s)
-% Students T penalty with 'auto-tuning'
-%
-% use:
-% [f,g,h,{k,{s}}] = studentst(r) - automatically fits s and k
-% [f,g,h,{k,{s}}] = studentst(r,k) - automatically fits s
-% [f,g,h,{k,{s}}] = studentst(r,k,s) - use given s and k
-%
-% input:
-% r - residual as column vector
-% s - scale (optional)
-% k - degrees of freedom (optional)
-%
-% output:
-% f - misfit (scalar)
-% g - gradient (column vector)
-% h - positive approximation of the Hessian (column vector, Hessian is a diagonal matrix)
-% s,k - scale and degrees of freedom
-%
-% Tristan van Leeuwen, 2012.
-% tleeuwen@eos.ubc.ca
-
-% fit both s and k
-if nargin == 1
- opts = optimset('maxFunEvals',1e2);
- tmp = fminsearch(@(x)st(r,x(1),x(2)),[1;2],opts);
- s = tmp(1);
- k = tmp(2);
-end
-
-
-if nargin == 2
- opts = optimset('maxFunEvals',1e2);
- tmp = fminsearch(@(x)st(r,x,k),[1],opts);
- s = tmp(1);
-end
-
-% evaulate penalty
-[f,g,h] = st(r,s,k);
-
-
-function [f,g,h] = st(r,s,k)
-n = length(r);
-c = -n*(gammaln((k+1)/2) - gammaln(k/2) - .5*log(pi*s*k));
-f = c + .5*(k+1)*sum(log(1 + conj(r).*r/(s*k)));
-g = (k+1)*r./(s*k + conj(r).*r);
-h = (k+1)./(s*k + conj(r).*r);
diff --git a/src/Python/conda-recipe/meta.yaml b/src/Python/conda-recipe/meta.yaml index 7068e9d..9ef9156 100644 --- a/src/Python/conda-recipe/meta.yaml +++ b/src/Python/conda-recipe/meta.yaml @@ -14,8 +14,8 @@ requirements: - python - numpy - setuptools - - boost ==1.64 - - boost-cpp ==1.64 + - boost ==1.65 + - boost-cpp ==1.65 - cython run: |