Code Monkey home page Code Monkey logo

tomographicimaging / ccpi-regularisation-toolkit Goto Github PK

View Code? Open in Web Editor NEW
45.0 8.0 24.0 108.48 MB

The set of CPU/GPU optimised regularisation modules for iterative image reconstruction and other image processing tasks

License: Apache License 2.0

MATLAB 1.86% C 36.05% C++ 5.92% Cuda 30.27% CMake 2.46% Python 14.10% Shell 0.37% Batchfile 0.10% Cython 8.86%
regularization regularisation inverse-problems denoising reconstruction gpu image-reconstruction tomography iterative-reconstruction

ccpi-regularisation-toolkit's Introduction

CCPi-Regularisation Toolkit (Software X paper)

CI status conda version conda date conda platforms conda downloads License

Iterative image reconstruction (IIR) methods frequently require regularisation to ensure convergence and make inverse problem well-posed. The CCPi-Regularisation Toolkit (CCPi-RGL) toolkit provides a set of 2D/3D regularisation strategies to guarantee a better performance of IIR methods (higher SNR and resolution). The regularisation modules for scalar and vectorial datasets are based on the proximal operator framework and can be used with proximal splitting algorithms, such as PDHG, Douglas-Rachford, ADMM, FISTA and others. While the main target for CCPi-RGL is tomographic image reconstruction, the toolkit can be used for image denoising problems. The core modules are written in C-OMP and CUDA languages and wrappers for Matlab and Python are provided. With CuPy dependency installed for Python, one can use regularisers directly without the need for explicit compilation. We recommend this option as the simplest to start with if you've got a GPU. This software can also be used by running in parallel across multiple GPU devices on a PC or a cluster compute node.

Prerequisites

  • Python (3.7+) and/or MATLAB
  • C compilers
  • nvcc (CUDA SDK) compilers
    • CuPy for the GPU-enabled methods

Package modules

Single-channel (scalar)

  1. Rudin-Osher-Fatemi (ROF) Total Variation (explicit PDE minimisation scheme) 2D/3D CPU/GPU + CuPy1
  2. Fast-Gradient-Projection (FGP) Total Variation 2D/3D CPU/GPU2
  3. Split-Bregman (SB) Total Variation 2D/3D CPU/GPU3
  4. Primal-Dual (PD) Total Variation 2D/3D CPU/GPU + CuPy4
  5. Total Generalised Variation (TGV) model for higher-order regularisation 2D/3D CPU/GPU54
  6. Linear and nonlinear diffusion (explicit PDE minimisation scheme) 2D/3D CPU/GPU6
  7. Anisotropic Fourth-Order Diffusion (explicit PDE minimisation) 2D/3D CPU/GPU7
  8. A joint ROF-LLT (Lysaker-Lundervold-Tai) model for higher-order regularisation 2D/3D CPU/GPU89
  9. Nonlocal Total Variation regularisation (GS fixed point iteration) 2D CPU/GPU10

Multi-channel (vectorial)

  1. Fast-Gradient-Projection (FGP) Directional Total Variation 2D/3D CPU/GPU11122
  2. Total Nuclear Variation (TNV) penalty 2D+channels CPU13

Installation

The package comes as a CMake project and additional wrappers for Python and Matlab. Please see more detailed Installation information.

Python binaries

To install precompiled binaries, you need conda and install from the ccpi channel using :

conda install ccpi-regulariser -c ccpi -c conda-forge

Python (GPU-CuPy)

One can also use some of the GPU modules with the provided CuPy interfaces. The functions in ccpi-regularisation-cupy package work with CuPy arrays as an input and return a CuPy array for output.

conda install -c httomo ccpi-regularisation-cupy

Once installed please see Demos. Please note that not all modules are yet supported as this is an ongoing development. One can install both CuPy-driven and the ccpi-regulariser package in one environment, but please be aware that the functions carry the identical names.

References

Software (please cite if used)

Applications

License

License

Acknowledgments

CCPi-RGL software is a product of the CCPi group and STFC SCD software developers. Any relevant questions/comments can be e-mailed to Daniil Kazantsev.

Footnotes

  1. Rudin, L.I., Osher, S. and Fatemi, E., 1992. Nonlinear total variation based noise removal algorithms. Physica D: nonlinear phenomena, 60(1-4)

  2. Beck, A. and Teboulle, M., 2009. Fast gradient-based algorithms for constrained total variation image denoising and deblurring problems. IEEE Transactions on Image Processing, 18(11) 2

  3. Goldstein, T. and Osher, S., 2009. The split Bregman method for L1-regularized problems. SIAM journal on imaging sciences, 2(2)

  4. Chambolle, A. and Pock, T., 2010. A first-order primal-dual algorithm for convex problems with applications to imaging. Journal of mathematical imaging and vision 40(1) 2

  5. Bredies, K., Kunisch, K. and Pock, T., 2010. Total generalized variation. SIAM Journal on Imaging Sciences, 3(3)

  6. Black, M.J., Sapiro, G., Marimont, D.H. and Heeger, D., 1998. Robust anisotropic diffusion. IEEE Transactions on image processing, 7(3)

  7. Hajiaboli, M.R., 2011. An anisotropic fourth-order diffusion filter for image noise removal. International Journal of Computer Vision, 92(2)

  8. Lysaker, M., Lundervold, A. and Tai, X.C., 2003. Noise removal using fourth-order partial differential equation with applications to medical magnetic resonance images in space and time. IEEE Transactions on image processing, 12(12)

  9. Kazantsev, D., Guo, E., Phillion, A.B., Withers, P.J. and Lee, P.D., 2017. Model-based iterative reconstruction using higher-order regularization of dynamic synchrotron data. Measurement Science and Technology, 28(9)

  10. Abderrahim E., Lezoray O. and Bougleux S. 2008. Nonlocal discrete regularization on weighted graphs: a framework for image and manifold processing. IEEE Trans. Image Processing 17(7), pp. 1047-1060.

  11. Ehrhardt, M.J. and Betcke, M.M., 2016. Multicontrast MRI reconstruction with structure-guided total variation. SIAM Journal on Imaging Sciences, 9(3)

  12. Kazantsev, D., Jørgensen, J.S., Andersen, M., Lionheart, W.R., Lee, P.D. and Withers, P.J., 2018. Joint image reconstruction method with correlative multi-channel prior for X-ray spectral computed tomography. Inverse Problems, 34(6) Results can be reproduced using the following SOFTWARE

  13. Duran, J., Moeller, M., Sbert, C. and Cremers, D., 2016. Collaborative total variation: a general framework for vectorial TV models. SIAM Journal on Imaging Sciences, 9(1)

ccpi-regularisation-toolkit's People

Contributors

casperdcl avatar ccpi-admin avatar dkazanc avatar gfardell avatar paskino avatar tomaskulhanek avatar vais-ral avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ccpi-regularisation-toolkit's Issues

Changing the name of the package

We need to change the name of the package to RegularisationToolkit and add a short description, e.g. The collection of CPU/GPU optimised regularisation modules for iterative image reconstruction or other image processing tasks

One test failure with cuda 8.0

Fails with cuda 8.0, fine with 9.1:

----------------------------------------------------------------------
Traceback (most recent call last):
  File "/scratch/anaconda2/conda-bld/ccpi-regulariser_1542907757837/test_tmp/run_test.py", line 663, in test_FDGdTV_CPU_vs_GPU
    self.assertLessEqual(diff_im.sum(), 1)
AssertionError: 44.039284 not less than or equal to 1

----------------------------------------------------------------------
Ran 12 tests in 15.135s

FAILED (failures=1)```

Tests failure with Python 2.7 during conda-build

While running conda-build with Python 2.7 there is a following issue:

from ccpi.filters.regularisers import ROF_TV, FGP_TV, SB_TV, TGV, LLT_ROF, DIFF4th
ImportError: No module named ccpi.filters.regularisers
Tests failed for ccpi-regulariser-0.10.1-np114py27_0.tar.bz2 - moving package to /dls_sw/apps/savu/savu_future/miniconda/conda-bld/broken
WARNING:conda_build.build:Tests failed for ccpi-regulariser-0.10.1-np114py27_0.tar.bz2 - moving package to /dls_sw/apps/savu/savu_future/miniconda/conda-bld/broken
TESTS FAILED: ccpi-regulariser-0.10.1-np114py27_0.tar.bz2

As a workaround use --no-test to skip tests, i.e.:
conda build Wrappers/Python/conda-recipe --numpy 1.12 --python 2.7 --no-test

check this line in Diff4thHajiaboli_GPU

https://github.com/vais-ral/CCPi-FISTA_Reconstruction/blob/master/Wrappers/Matlab/mex_compile/regularizers_GPU/Diffus_HO/Diff4thHajiaboli_GPU.cpp#L75

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];
            }}  

what does the if? i or j are always less than M-1 or N-1. It seems to me that only when i==0 or j==0 the if returns False. Actually what happens to B in that case?

https://github.com/vais-ral/CCPi-FISTA_Reconstruction/blob/master/Wrappers/Matlab/mex_compile/regularizers_GPU/Diffus_HO/Diff4thHajiaboli_GPU.cpp#L56 initializes to 0?

rename fista_module.cpp

Rename fista_module.cpp to regularizer_module.cpp or similar, because that's what it is related to.

Create conda recipe

  • recipe for regularizers (win)
  • recipe for regularizers (linux)
  • recipe for Python package

PowerMethodNonsquare error

When running try_astra_projector.py and calling function f = Norm2sq(Aop,b,c=0.5), the error is the following:

File "/home/algol/Documents/DEV/CCPi-FISTA_Reconstruction/modular/funcs.py", line 35, in init
self.L = 2.0self.c(self.A.get_max_sing_val()**2)

File "/home/algol/Documents/DEV/CCPi-FISTA_Reconstruction/modular/ops.py", line 109, in get_max_sing_val
self.s1, sall, svec = PowerMethodNonsquare(self,10)

File "/home/algol/Documents/DEV/CCPi-FISTA_Reconstruction/modular/ops.py", line 124, in PowerMethodNonsquare
x1norm = np.sqrt((x1**2).sum())

TypeError: unsupported operand type(s) for ** or pow(): 'VolumeData' and 'int'

skip cuda tests if cuda driver is not compatible with cuda runtime version

Skip GPU tests when "code: 35, reason: CUDA driver version is insufficient for CUDA runtime version".
Currently tests fails on

Executing transaction: ...working... done
Error: /home/jenkins/workspace/CILsingle/CCPi-Regularisation-Toolkit/Core/regularisers_GPU/Diffus_4thO_GPU_core.cu:234, code: 35, reason: CUDA driver version is insufficient for CUDA runtime version
Tests failed for ccpi-regulariser-0.10.2-np111py36_0.tar.bz2 - moving package to /home/jenkins/conda-bld/broken
WARNING:conda_build.build:Tests failed for ccpi-regulariser-0.10.2-np111py36_0.tar.bz2 - moving package to /home/jenkins/conda-bld/broken
TESTS FAILED: ccpi-regulariser-0.10.2-np111py36_0.tar.bz2
Build step 'Execute shell' marked build as failure

CXXABI_1.3.9 not included in libstdc++.so.6 / Matlab GPU mex

After cmake build and running GPU modules in Matlab (Linux). The related issue. Can be fixed either linking to a newer libstdc++.so.6.0.24 or by setting the env variable:
export LD_PRELOAD=/home/user/anaconda3/lib/libstdc++.so.6.0.24
The latter worked in my case

FGP_TV returns NaN on Linux

running test_regularizers.py on linux FGP_TV does not return the same as the windows version. It returns NaN

Cmake build - ImportError: libcilreg.so:

After Cmake build Python can't find
ImportError: libcilreg.so: cannot open shared object file: No such file or directory
I do

cd install/python/
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:.

I run python from install/python/ and it still cannot find libcilreg.so.

cpu/gpy_regularizers.pyx merge into one Cython file?

In order to keep things in one place while Cythonizing, i.e. just have regularizers.pyx
Pros:

  1. Easy to manage interfaces to CPU/GPU functions and also do parameters check for both cores.
  2. A possibility of adding a 'CPU' / 'GPU' switch in order to have just one name for the regularizer,
    e.g. FGP_TV(blabla, 'GPU')
  3. More compact representation

Cons: A bit more challenging debugging

P.S. As a trial I can do it for ROF or FGP.

Adaptation FGP-TV for CPU and GPU to a new interface

FGP-TV CPU has been updated to make code more self-consistent where the main function is:
https://github.com/vais-ral/CCPi-FISTA_Reconstruction/blob/b9562bbfdf6ca2cc8775e242ae13cbfaeeb2479b/Core/regularizers_CPU/FGP_TV_core.c#L40

One needs to wrap it using Boost or what has been used recently for ROF-TV? Essentially I'm taking care most of memory allocation stuff inside the C-code so should be less work to set it up from outside.

FGP - CUDA version has been added with the same interface:
https://github.com/vais-ral/CCPi-FISTA_Reconstruction/blob/b9562bbfdf6ca2cc8775e242ae13cbfaeeb2479b/Core/regularizers_GPU/TV_FGP/FGP_TV_GPU_core.cu#L344

GPU MATLAB path

I found out that mex'ed GPU functions will not run until I run them from the folder where they're in first! Then I can go to another folders and run it from there, but until that Matlab says something like: Invalid MEX-file '/home/algol/Documents/MATLAB/rtmct/MultichannelRegularization/priors/FGP_TV/GPU/FGP_TV2D_GPU.mexa64': FGP_TV2D_GPU_kernel.o: cannot open shared object file: No such file or directory.

Oredered Subset: some lines are repeated in all the if-then-else clauses

CMake/Boost dependencies preclude build

Do we use Cython exclusively for building up CPU and GPU modules? If Yes, then we need to remove all Cmake and boost dependencies? Do we actually need CMakeLists.txt ?

@paskino please have a look at problems with compilation now.

Write wrapper for New regulariser based on ROF-model for 2D/3D #22

A new regulariser has been added into the master which includes C-OMP realisation of ROF-TV model
http://www.ipol.im/pub/art/2012/g-tvd/article_lr.pdf

This is the classical explicit scheme which is although slow has one of the lowest memory footprints among other TV regularisers. GPU implementation is also suitable for fairly large 3D volumes. It will follow at some point.

it worth to include it into regularisation compilation routine...

Python-ize the code

When moving things to Python it is better to look at DemoRD2.m where real data reconstruction is performed in full 3D.

Weird Distutils error with Cmake.

building with cmake, complains to the line

The error:

 File "/home/kjy41806/Documents/SOFT/CCPi-Regularisation-Toolkit/build/Wrappers/Python/setup-regularisers.py", line 71
    packages = {'ccpi', 'ccpi.filters'}
                      ^
SyntaxError: invalid syntax
make[2]: *** [Wrappers/Python/build/timestamp] Error 1
make[1]: *** [Wrappers/Python/CMakeFiles/PythonWrapper.dir/all] Error 

All seems in order to me...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.