All Projects → m-pilia → disptools

m-pilia / disptools

Licence: MIT License
Generate displacement fields with known volume changes

Programming Languages

c
50402 projects - #5 most used programming language
python
139335 projects - #7 most used programming language
Cuda
1817 projects
CMake
9771 projects
C++
36643 projects - #6 most used programming language
Makefile
30231 projects
HTML
75241 projects

Projects that are alternatives of or similar to disptools

rbcuda
CUDA bindings for Ruby
Stars: ✭ 57 (+235.29%)
Mutual labels:  cuda
SoliditySHA3Miner
All-in-one mixed multi-GPU (nVidia, AMD, Intel) & CPU miner solves proof of work to mine supported EIP918 tokens in a single instance (with API).
Stars: ✭ 28 (+64.71%)
Mutual labels:  cuda
warp
continuous energy monte carlo neutron transport in general geometries on GPUs
Stars: ✭ 27 (+58.82%)
Mutual labels:  cuda
monolish
monolish: MONOlithic LInear equation Solvers for Highly-parallel architecture
Stars: ✭ 166 (+876.47%)
Mutual labels:  cuda
Arch-Data-Science
Archlinux PKGBUILDs for Data Science, Machine Learning, Deep Learning, NLP and Computer Vision
Stars: ✭ 92 (+441.18%)
Mutual labels:  cuda
Jampack
Experimental parallel compression algorithm
Stars: ✭ 21 (+23.53%)
Mutual labels:  cuda
JetScan
JetScan : GPU accelerated portable RGB-D reconstruction system
Stars: ✭ 77 (+352.94%)
Mutual labels:  cuda
MatX
An efficient C++17 GPU numerical computing library with Python-like syntax
Stars: ✭ 418 (+2358.82%)
Mutual labels:  cuda
ClothTOP
GPU-accelerated Cloth TOP node for TouchDesigner using the NVIDIA Flex physics solver.
Stars: ✭ 33 (+94.12%)
Mutual labels:  cuda
PbfVs
Implementation of Macklin, Miles, and Matthias Müller. "Position based fluids.". Visual Studio 2015 + CUDA 8.0
Stars: ✭ 100 (+488.24%)
Mutual labels:  cuda
FLAMEGPU2
FLAME GPU 2 is a GPU accelerated agent based modelling framework for C++ and Python
Stars: ✭ 25 (+47.06%)
Mutual labels:  cuda
Fat-Clouds
GPU Fluid Simulation with Volumetric Rendering
Stars: ✭ 81 (+376.47%)
Mutual labels:  cuda
LaneandYolovehicle-DetectionLinux
Lane depertaure and Yolo objection detection C++ Linux
Stars: ✭ 16 (-5.88%)
Mutual labels:  cuda
pyRender
Lightweight Cuda Renderer with Python Wrapper.
Stars: ✭ 49 (+188.24%)
Mutual labels:  cuda
cresset
Template repository to build PyTorch projects from source on any version of PyTorch/CUDA/cuDNN.
Stars: ✭ 573 (+3270.59%)
Mutual labels:  cuda
rust-inline-cuda-tutorial
Let's jump into CUDA development with Rust
Stars: ✭ 17 (+0%)
Mutual labels:  cuda
cuda-toolkit
GitHub Action to install CUDA
Stars: ✭ 34 (+100%)
Mutual labels:  cuda
mini-nbody
A simple gravitational N-body simulation in less than 100 lines of C code, with CUDA optimizations.
Stars: ✭ 73 (+329.41%)
Mutual labels:  cuda
dynamic-occupancy-grid-map
Implementation of A Random Finite Set Approach for Dynamic Occupancy Grid Maps with Real-Time Application
Stars: ✭ 89 (+423.53%)
Mutual labels:  cuda
bazel.cmake
bazel.cmake mimics the behavior of bazel to simplify the usability of CMake
Stars: ✭ 38 (+123.53%)
Mutual labels:  cuda

disptools

Generate displacement fields with known volume changes

GitHub release PyPI Wheels License Appveyor GitHub Actions codecov Downloads

This library provides utilities to generate and manipulate displacement fields with known volume changes. It implements three search-based algorithms for the generation of deformation fields, along with a small collection of utility functions, and provides optional GPU acceleration through a CUDA implementation.

The three algorithms implemented are referred as:

  • gradient: a gradient descent method (default).
  • greedy: a greedy search method proposed in [1].
  • matching: a volume matching method proposed in [2] and [3]. The implementation comes from the PREDICT atrophysim tool.

The library is built on top of SimpleITK, in order to provide a simple yet powerful set of functionalities for image analysis. Images stored as numpy arrays can be easily converted from and to SimpleITK and ITK image objects.

Documentation

The complete documentation for this package is available on https://martinopilia.com/disptools.

Quick example

import SimpleITK as sitk
import disptools.displacements as dsp
import disptools.drawing as drw

# Create an example Jacobian map
# A spherical ROI with a Jacobian of 1.1 (expansion)
jacobian = drw.create_sphere(10, 40, fg_val=1.1, bg_val=1.0)

# Create a binary mask for the ROI
mask = drw.create_sphere(10, 40) > 0

# Generate the displacement
displacement = dsp.displacement(jacobian, mask=mask)

# Check the correctness of the result within the ROI
error = jacobian - dsp.jacobian(displacement)
error = sitk.Mask(error, mask)

A 3D rendering of the resulting displacement field with ParaView, and a visualisation of the the error on the Jacobian within the ROI:

displacement error

Architecture

The project is structured in three layers:

  • a pure standard C99 library (whose headers are in src/headers), with no external dependencies, implementing the core algorithms for the generation of deformation fields. It is a standalone library that can be directly included in a C or C++ project. It is paired with an optional CUDA library, whose headers are in cuda/headers, that depends on src/headers and provides a GPGPU implementation of the key routines.
  • a Python C extension package _disptools (whose source is in the file python_c_extension/_disptools.c), providing a bare Python wrapper to the aforementioned library, using the NumPy C API to pass arrays. This can be directly included in a Python project with no dependencies other than NumPy.
  • a Python package (disptools), that wraps the _disptools package providing file IO (through SimpleITK) and implementing high-level features (such as the multi-resolution framework) and auxiliary utilities and functions.
    • disptools.displacements: module providing the main functions for the generation and manipulation of displacement fields.
    • disptools.drawing: collection of utilities to create test images.
    • disptools.io: collection of utilities to read and write to file.
    • disptools.measure: collection of utilities to measure some image features.
    • disptools.simulatrophy: routines to interface with the Simul@atrophy tool.
    • disptools.predict: routines to interface with the PREDICT tool.

Install

This package is available on PyPI both as source distribution and as a Windows pre-compiled binary wheel. You can install it with pip:

 python3 -m pip install disptools

As always, it is recommended to use the package inside a virtual environment.

Build from source

Requirements

Requirements are specified by the requirements.txt file and can be installed with pip.

python3 -m pip install -r requirements.txt

The library is a cross-platform Python 3.5+ package, with a compiled C extension. The Python dependencies are:

Build dependencies are a standard C compiler (tested with gcc 8.2 on Linux, mingw-w64 7.2 and MSVC 19 on Windows 10), CMake, the numpy and the setuptools packages. scikit-build may be required to build the other Python dependencies.

Some optional dependencies are required only for a limited set of features, and the package should build and run without them:

Build options

The following environment variables affect the setup.py:

  • DISPTOOLS_OPT=ON: enable non-portable optimisations.
  • DISPTOOLS_DEBUG=ON: disable optimisations, compile with debug symbols.
  • DISPTOOLS_CUDA_SUPPORT=ON: enable CUDA support.

Windows (Visual Studio) and Linux

Install the dependencies with your favourite package manager. For example, with pip:

python3 -m pip install -r requirements.txt

The package provides a setuptools based install script. To install the library, run from the project root folder

python3 setup.py install

which should build the C extension and install the Python package.

Windows (MinGW)

  1. First, be sure that mingw, CMake and Python are installed and their executables are in your PATH.

  2. Ensure that gcc is working correctly:

> gcc --version
gcc (x86_64-posix-seh-rev1, Built by MinGW-W64 project) 7.2.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  1. Ensure that distutils correctly recognises your version of Visual Studio (even when using mingw). Open the file C:\Users\yourname\AppData\Local\Programs\Python\Python3x\Lib\distutils\cygwinccompiler.py (the exact location may vary according to your setup) and check that your version of Visual Studio is present in the function get_msvcr(); if not, adjust it according to the following:
def get_msvcr():
    """Include the appropriate MSVC runtime library if Python was built
    with MSVC 7.0 or later.
    """
    msc_pos = sys.version.find('MSC v.')
    if msc_pos != -1:
        msc_ver = sys.version[msc_pos+6:msc_pos+10]
        if msc_ver == '1300':
            # MSVC 7.0
            return ['msvcr70']
        elif msc_ver == '1310':
            # MSVC 7.1
            return ['msvcr71']
        elif msc_ver == '1400':
            # VS2005 / MSVC 8.0
            return ['msvcr80']
        elif msc_ver == '1500':
            # VS2008 / MSVC 9.0
            return ['msvcr90']
        elif msc_ver == '1600':
            # VS2010 / MSVC 10.0
            return ['msvcr100']
        elif msc_ver == '1700':
            # Visual Studio 2012 / Visual C++ 11.0
            return ['msvcr110']
        elif msc_ver == '1800':
            # Visual Studio 2013 / Visual C++ 12.0
            return ['msvcr120']
        elif msc_ver == '1900':
            # Visual Studio 2015 / Visual C++ 14.0
            # "msvcr140.dll no longer exists" http://blogs.msdn.com/b/vcblog/archive/2014/06/03/visual-studio-14-ctp.aspx
            return ['vcruntime140']
        else:
            raise ValueError("Unknown MS Compiler version %s " % msc_ver)
  1. Ensure that the library vcruntime140.dll is present in your library path. Otherwise, download it and place it in C:\Users\yourname\AppData\Local\Programs\Python\Python3x\libs (the exact path may vary according to your setup).

  2. Clone the sources of this package with git, or download and extract them as a zip archive. Move to the root folder of the sources (C:\Users\yourname\disptools in this example), specify the right compiler, and launch the setup script to build and install the package.

> cd C:\Users\yourname\disptools
> python setup.py setopt --command=build --option=compiler --set-value=mingw32
> python -m pip install -r requirements.txt
> python setup.py install

References

  • [1] van Eede, M. C., Scholz, J., Chakravarty, M. M., Henkelman, R. M., and Lerch, J. P. Mapping registration sensitivity in MR mouse brain images. Neuroimage 82 (2013), 226–236.
  • [2] Karaçali, B., and Davatzikos, C. Estimating topology preserving and smooth displacement fields. IEEE Transactions on Medical Imaging 23, 7 (2004), 868–880.
  • [3] Karaçali, B., and Davatzikos, C. Simulation of tissue atrophy using a topology preserving transformation model. IEEE transactions on medical imaging 25, 5 (2006), 649–652.

License

The software is distributed under the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].