GithubHelp home page GithubHelp logo

jackzhousz / tomosipo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ahendriksen/tomosipo

0.0 0.0 0.0 1.66 MB

A library for painless 3D tomographic reconstruction

Home Page: https://aahendriksen.gitlab.io/tomosipo/index.html

License: GNU General Public License v3.0

Shell 0.01% Python 18.13% Jupyter Notebook 81.87%

tomosipo's Introduction

img

Tomosipo

Anaconda-Server Badge Anaconda-Server Badge License: GPL v3

Tomosipo is a pythonic wrapper for the ASTRA-toolbox of high-performance GPU primitives for 3D tomography.

The aim of this library is to:

  • Expose a user-friendly API for high-performance 3D tomography, while allowing strict control over resource usage
    • The ts_algorithms library contains implementations of reconstruction algorithms using Tomosipo
  • Enable easy manipulation and visualization of 3D geometries
  • Provide easy integration with

The documentation can be found here. An introduction and demonstration of tomosipo was published in Optics Express.

  1. Installation
  2. Usage
    1. Create and visualize geometries
    2. Express algorithms succinctly
    3. More examples
  3. Authors and contributors

Citing tomosipo

If you use tomosipo in scientific publications, we would appreciate citations of our paper using the following Bibtex entry:

@Article{hendriksen-2021-tomos,
  author          = {Hendriksen, Allard and Schut, Dirk and Palenstijn, Willem
                  Jan and Viganò, Nicola and Kim, Jisoo and Pelt, Dani{\"e}l and
                  van Leeuwen, Tristan and Batenburg, K. Joost},
  title           = {Tomosipo: Fast, Flexible, and Convenient {3D} Tomography for
                  Complex Scanning Geometries in {Python}},
  journal         = {Optics Express},
  year            = 2021,
  doi             = {10.1364/oe.439909},
  url             = {https://doi.org/10.1364/oe.439909},
  issn            = {1094-4087},
  month           = {Oct},
  publisher       = {The Optical Society},
}

Installation

A minimal installation requires:

  • python >= 3.6
  • ASTRA-toolbox >= 2.0
  • CUDA

The requirements can be installed using the anaconda package manager. The following snippet creates a new conda environment named tomosipo (replace X.X by your CUDA version)

conda create -n tomosipo cudatoolkit=<X.X> tomosipo -c astra-toolbox -c aahendriksen -c defaults

An installation with Pytorch and ts_algorithms can be created with the following snippet

conda create -n tomosipo cudatoolkit=<X.X> tomosipo tqdm pytorch -c pytorch -c astra-toolbox -c aahendriksen -c defaults
conda activate tomosipo
pip install git+https://github.com/ahendriksen/ts_algorithms.git

More information about installation is provided in the documentation.

Usage

Simple examples:

Create and visualize geometries

You can follow along on Google Colab.

import astra
import numpy as np
import tomosipo as ts

# Create 'unit' cone geometry
pg = ts.cone(angles=20, size=np.sqrt(2), cone_angle=0.5)
print(pg)

# Create volume geometry of a unit cube on the origin
vg = ts.volume()
print(vg)

# Display an animation of the acquisition geometry
ts.svg(pg, vg)

Express algorithms succinctly

In the following example, we implement the simultaneous iterative reconstruction algorithm (SIRT) in a couple of lines. This examples demonstrates the use of the forward and backward projection.

First, the SIRT algorithm is implemented using numpy arrays, which reside in system RAM. Then, we move all data onto the GPU, and compute the same algorithm using PyTorch. This is faster, because no transfers between system RAM and GPU are necessary.

import astra
import numpy as np
import tomosipo as ts
from timeit import default_timer as timer

# Create 'unit' cone geometry, and a
pg = ts.cone(size=np.sqrt(2), cone_angle=1/2, angles=100, shape=(128, 192))
# Create volume geometry of a unit cube on the origin
vg = ts.volume(shape=128)
# Create projection operator
A = ts.operator(vg, pg)

# Create a phantom containing a small cube:
phantom = np.zeros(A.domain_shape)
phantom[20:50, 20:50, 20:50] = 1.0

# Prepare preconditioning matrices R and C
R = 1 / A(np.ones(A.domain_shape))
R = np.minimum(R, 1 / ts.epsilon)
C = 1 / A.T(np.ones(A.range_shape))
C = np.minimum(C, 1 / ts.epsilon)

# Reconstruct from sinogram y into x_rec in 100 iterations
y = A(phantom)
x_rec = np.zeros(A.domain_shape)
num_iters = 100

start = timer()
for i in range(num_iters):
    x_rec += C * A.T(R * (y - A(x_rec)))
print(f"SIRT finished in {timer() - start:0.2f} seconds")

# Perform the same computation on the GPU using PyTorch.
# First, import pytorch:
import torch

# Move all data to GPU:
dev = torch.device("cuda")
y = torch.from_numpy(y).to(dev)
R = torch.from_numpy(R).to(dev)
C = torch.from_numpy(C).to(dev)
x_rec = torch.zeros(A.domain_shape, device=dev)

# Perform algorithm
start = timer()
for i in range(num_iters):
    x_rec += C * A.T(R * (y - A(x_rec)))

# Convert reconstruction back to numpy array:
x_rec = x_rec.cpu().numpy()
print(f"SIRT finished in {timer() - start:0.2f} seconds using PyTorch")
SIRT finished in 2.07 seconds
SIRT finished in 0.94 seconds using PyTorch

A similar implementation of SIRT and succinct implementations of some other reconstruction algorithms are available in the ts_algorithms library.

More examples

Please checkout the examples and notebooks directory for more examples.

Authors and contributors

tomosipo is developed by the Computational Imaging group at CWI.

Current maintainer:

  • Dirk Schut

Original author:

  • Allard Hendriksen

We thank the following authors for their contribution

  • Johannes Leuschner - ODL integration

See also the list of contributors who participated in this project.

tomosipo's People

Contributors

ahendriksen avatar d1rk123 avatar jleuschn avatar schoonhovenrichard avatar

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.