Skip to content

kbredies/gratopy

Repository files navigation

Gratopy

DOI Documentation Status Gratopy Tests

The gratopy (Graz accelerated tomographic projections for Python) toolbox is a Python3 software package for the efficient and high-quality computation of Radon transforms, fanbeam transforms as well as the associated backprojections. The included operators are based on pixel-driven projection methods which were shown to possess favorable approximation properties. The toolbox offers a powerful parallel OpenCL/GPU implementation which admits high execution speed and allows for seamless integration into PyOpenCL. Gratopy can efficiently be combined with other PyOpenCL code and is well-suited for the development of iterative tomographic reconstruction approaches, in particular, for those involving optimization algorithms.

Highlights

  • Easy-to-use tomographic projection toolbox.
  • High-quality 2D projection operators.
  • Fast projection due to custom OpenCL/GPU implementation.
  • Seamless integration into PyOpenCL.
  • Basic iterative reconstruction schemes included (Landweber, CG, total variation).
  • Comprehensive documentation, tests and example code.

The fanbeam projection of a walnut and gratopy’s Landweber and total variation reconstructions (from left to right).

Installation

The toolbox can easily be installed using pip:

pip install gratopy

Alternatively, a release or snapshot archive file can directly be downloaded and unpacked. Calling

pip install .

inside the main folder then installs the toolbox. Gratopy supports setuptools for installation such that

python setup.py install

has the same effect. For more details we refer to the documentation.

As a further alternative, if no dedicated installation is needed for the toolbox, the code can simply be downloaded and the contents of the gratopy directory can be imported as a module. Please make sure to have the following Python modules installed, most of which should be standard.

Requirements

Note that in particular, correctly installing and configuring PyOpenCL might take some time, as dependent on the used platform/GPU, suitable drivers must be installed. We refer to PyOpenCL's documentation.

Getting started

We refer to the extensive documentation, in particular to the getting started guide, as well as to the test files for the Radon transform and fanbeam transform. The following rudimentary example is also included in the documentation.

# initial import
import numpy as np
import pyopencl as cl
import matplotlib.pyplot as plt

import gratopy

# discretization parameters
number_angles = 60
number_detectors = 300
Nx = 300
# Alternatively to number_angles one could give as angle input
# angles = np.linspace(0, np.pi, number_angles+1)[:-1]

# create pyopencl context
ctx = cl.create_some_context()
queue = cl.CommandQueue(ctx)

# create phantom as test image (a pyopencl.array.Array of dimensions (Nx, Nx))
phantom = gratopy.phantom(queue,Nx)

# create suitable projectionsettings
PS = gratopy.ProjectionSettings(queue, gratopy.RADON, phantom.shape,
                                number_angles, number_detectors)

# compute forward projection and backprojection of created sinogram
# results are pyopencl arrays
sino = gratopy.forwardprojection(phantom, PS)
backproj = gratopy.backprojection(sino, PS)

# plot results
plt.figure()
plt.title("Generated Phantom")
plt.imshow(phantom.get(), cmap="gray")

plt.figure()
plt.title("Sinogram")
plt.imshow(sino.get(), cmap="gray")

plt.figure()
plt.title("Backprojection")
plt.imshow(backproj.get(), cmap="gray")
plt.show()

Authors

All authors are affiliated with the Institute of Mathematics and Scientific Computing at the University of Graz.

Publications

If you find this tool useful, please cite the following associated publication.

Acknowledgements

The development of this software was supported by the following projects:

  • Regularization Graphs for Variational Imaging, funded by the Austrian Science Fund (FWF), grant P-29192,

  • International Research Training Group IGDK 1754 Optimization and Numerical Analysis for Partial Differential Equations with Nonsmooth Structures, funded by the German Research Council (DFG) and the Austrian Science Fund (FWF), grant W-1244.

The walnut data set included in this toolbox is licensed under CC BY 4.0 and available on Zenodo:

  • Keijo Hämäläinen, Lauri Harhanen, Aki Kallonen, Antti Kujanpää, Esa Niemi and Samuli Siltanen. (2015). Tomographic X-ray data of a walnut (Version 1.0.0) [Data set]. Zenodo. https://doi.org/10.5281/zenodo.1254206

The phantom creation code is based on Phantominator, copyright by its contributors and licensed under GPLv3. See https://github.com/mckib2/phantominator.

License

This project is licensed under the GPLv3 license - see LICENSE for details.