LibAPR - The Adaptive Particle Representation Library
Library for producing and processing on the Adaptive Particle Representation (APR) (For article see: https://www.nature.com/articles/s41467-018-07390-9).
We now provide python wrappers in a separate repository PyLibAPR
In addition to providing wrappers for most of the LibAPR functionality, the Python library contains a number of new features that simplify the generation and handling of the APR. For example:
- Interactive APR conversion
- Interactive APR z-slice viewer
- Interactive APR raycast (maximum intensity projection) viewer
- Interactive lossy compression of particle intensities
Version 2.0 release notes
The library has changed significantly since release 1.1. There are changes to IO and iteration that are not compatible with the older version.
- New (additional) linear access data structure, explicitly storing coordinates in the sparse dimension, similar to Compressed Sparse Row.
- Block-based decomposition of the APR generation pipeline, allowing conversion of very large images.
- Expanded and improved functionality for image processing directly on the APR:
- APR filtering (spatial convolutions).
- APRNumerics module, including e.g. gradient computations and Richardson-Lucy deconvolution.
- CUDA GPU-accelerated convolutions and RL deconvolution (currently only supports dense 3x3x3 and 5x5x5 stencils)
- HDF5 1.8.20 or higher
- OpenMP > 3.0 (optional, but recommended)
- CMake 3.6 or higher
- LibTIFF 4.0 or higher
NB: This update to 2.0 introduces changes to IO and iteration that are not compatable with old versions.
If compiling with APR_DENOISE flag the package also requires:
The repository requires submodules, and needs to be cloned recursively:
git clone --recursive https://github.com/AdaptiveParticles/LibAPR.git
CMake build options
Several CMake options can be given to control the build. Use the
-D argument to set each
desired option. For example, to disable OpenMP, change the cmake calls below to
cmake -DAPR_USE_OPENMP=OFF ..
|APR_BUILD_SHARED_LIB||Build shared library||OFF|
|APR_BUILD_STATIC_LIB||Build static library||ON|
|APR_BUILD_EXAMPLES||Build executable examples||OFF|
|APR_TESTS||Build unit tests||OFF|
|APR_BENCHMARK||Build executable performance benchmarks||OFF|
|APR_USE_LIBTIFF||Enable LibTIFF (Required for tests and examples)||ON|
|APR_PREFER_EXTERNAL_GTEST||Use installed gtest instead of included sources||ON|
|APR_PREFER_EXTERNAL_BLOSC||Use installed blosc instead of included sources||ON|
|APR_USE_OPENMP||Enable multithreading via OpenMP||ON|
|APR_USE_CUDA||Enable CUDA (Under development - APR conversion pipeline is currently not working with CUDA enabled)||OFF|
Building on Linux
On Ubuntu, install the
libtiff5-dev packages (on other distributions, refer to the documentation there, the package names will be similar). OpenMP support is provided by the GCC compiler installed as part of the
For denoising support also requires:
In the directory of the cloned repository, run
mkdir build cd build cmake .. make
This will create the
libapr.so library in the
Building on OSX
If you want to compile with OpenMP support (Recommended), also install the
libomp package via homebrew as the clang version shipped by Apple currently does not support OpenMP.
In the directory of the cloned repository, run
mkdir build cd build cmake .. make
Building on Windows
On windows there are two working strategies we have tested. Either cheating and using WSL2 and linux above, or utilising a recent version clang-cl or clang directly as included in MSVC 2019 >16.8.6. Note for earlier versions OpenMP support did not work.
The easiest way to set up your windows environment we have found is using chocolatey + vcpkg.
First install chocolatey using powershell: https://chocolatey.org/install
Open an admin powershell (for chocolatey steps)
If not installed, install git and cmake:
choco install -y git choco install -y cmake.portable
install the required visual studio compiler tools and clang: (Note you can also do this via downloading 2019 community and selecting the correct packages)
choco install visualstudio2019buildtools --params "--add Microsoft.Component.MSBuild --add Microsoft.VisualStudio.Component.VC.Llvm.Clang --add Microsoft.VisualStudio.Component.VC.Llvm.ClangToolset --add Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Llvm.Clang --add Microsoft.VisualStudio.Component.Windows10SDK.19041 --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --add Microsoft.VisualStudio.ComponentGroup.UWP.VC.BuildTools" choco install -y llvm
Now install your dependencies using vcpkg, in an install directory (VCPKG_PATH) of your choice do the following:
git clone https://github.com/microsoft/vcpkg cd vcpkg ./bootstrap-vcpkg.bat ./vcpkg.exe install blosc:x64-windows gtest:x64-windows tiff:x64-windows hdf5:x64-windows szip:x64-windows
Now navigate to your cloned LibAPR directory (git clone --recursive https://github.com/AdaptiveParticles/LibAPR.git). You should have all dependencies set up to be able to build the library with clang-cl
-A x64 -T ClangCL and to search for dependencies from vcpkg at your vcpkg install location:
-DCMAKE_TOOLCHAIN_FILE="VCPKG_PATH/vcpkg/scripts/buildsystems/vcpkg.cmake" -DVCPKG_TARGET_TRIPLET=x64-windows .
Now for example to build the tests and examples (Please note you will need to update below with your own VCPKG_PATH from the steps above.
mkdir build cd build Cmake -A x64 -DCMAKE_TOOLCHAIN_FILE="VCPKG_PATH/vcpkg/scripts/buildsystems/vcpkg.cmake" -DVCPKG_TARGET_TRIPLET=x64-windows -T ClangCL -DAPR_BUILD_EXAMPLES=ON -DAPR_TESTS=ON .. cmake --build . --config Release
The above examples is also used in CI and can be executed in the cmake-build_windows.sh
We provide a working Dockerfile that installs the library within the image in a separate repository.
Note: not recently tested.
Please see: INSTALL_INSTRUCTIONS.md and https://github.com/AdaptiveParticles/APR_cpp_project_example for a minimal project using the APR.
Examples and Documentation
There are 12 basic examples, that show how to generate and compute with the APR. These can be built by adding -DAPR_BUILD_EXAMPLES=ON to the cmake command.
|Example||How to ...|
|Example_get_apr||create an APR from a TIFF and store as hdf5.|
|Example_get_apr_by_block||create an APR from a (potentially large) TIFF, by decomposing it into smaller blocks, and store as hdf5.|
|Example_apr_iterate||iterate over APR particles and their spatial properties.|
|Example_apr_tree||iterate over interior APR tree particles and their spatial properties.|
|Example_neighbour_access||access particle and face neighbours.|
|Example_compress_apr||additionally compress the intensities stored in an APR.|
|Example_random_access||perform random access operations on particles.|
|Example_ray_cast||perform a maximum intensity projection ray cast directly on the APR.|
|Example_reconstruct_image||reconstruct a pixel image from an APR.|
|Example_compute_gradient||compute the gradient magnitude of an APR.|
|Example_apr_filter||apply a filter (convolution) to an APR.|
|Example_apr_deconvolution||perform Richardson-Lucy deconvolution on an APR.|
All examples except
Example_get_apr_by_block require an already produced APR, such as those created by
For tutorial on how to use the examples, and explanation of data-structures see the library guide.
The testing framework can be turned on by adding -DAPR_TESTS=ON to the cmake command. All tests can then be run by executing
on the command line in your build folder. Please let us know by creating an issue, if any of these tests are failing on your machine.
Basic Java wrappers can be found at LibAPR-java-wrapper Not compatable with recent releases.
- Improved documentation and updated library guide.
- More examples of APR-based image processing and segmentation.
- CUDA GPU-accelerated APR generation and additional processing options.
- Time series support.
If anything is not working as you think it should, or would like it to, please get in touch with us!! Further, dont hesitate to contact us if you have a project or algorithm you would like to try using the APR for. We would be glad to help!
Citing this work
If you use this library in an academic context, please cite the following paper:
- Cheeseman, Günther, Gonciarz, Susik, Sbalzarini: Adaptive Particle Representation of Fluorescence Microscopy Images (Nature Communications, 2018) https://doi.org/10.1038/s41467-018-07390-9