Skip to main content

Gratopy - Graz accelerated tomographic projections for Python

Project description

Gratopy

DOI Documentation Status Gratopy test suite

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 uses uv as its project and dependency management tool, which allows setting up a dedicated development environment by running

uv sync

For more details we refer to the documentation.

Requirements

Most notably, gratopy is built using PyOpenCL, which might require additional care in order to correctly install and configure it: depending on the used platform and GPU, suitable drivers must be installed. We refer to PyOpenCL's documentation for detailed instructions.

The full list of requirements can be found in pyproject.toml.

Getting started

We refer to the extensive documentation, in particular to the getting started guide, the new operator syntax page, 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()

Experimental operator syntax

Gratopy also provides an experimental operator-based API for Radon transforms via gratopy.operator.Radon. This interface supports operator algebra such as adjoints and compositions, for example R.T * R, and can also be paired with custom OpenCL kernels for experimentation. As this interface is still experimental, backward-incompatible changes may still occur without a full deprecation cycle.

import numpy as np
import pyopencl as cl
import gratopy

ctx = cl.create_some_context(interactive=False)
queue = cl.CommandQueue(ctx)

img = np.zeros((128, 128), dtype=np.float32)
R = gratopy.operator.Radon(image_domain=128, angles=180)

sino = R.apply_to(img, queue=queue)
backproj = R.T.apply_to(sino)

Authors

All authors are affiliated with the Department 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gratopy-0.2.0a1.tar.gz (1.5 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gratopy-0.2.0a1-py3-none-any.whl (80.4 kB view details)

Uploaded Python 3

File details

Details for the file gratopy-0.2.0a1.tar.gz.

File metadata

  • Download URL: gratopy-0.2.0a1.tar.gz
  • Upload date:
  • Size: 1.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.7

File hashes

Hashes for gratopy-0.2.0a1.tar.gz
Algorithm Hash digest
SHA256 117c882b9dddf29cf6418c472cb285a9257199f41d636482db7c008f3d6f8429
MD5 2b8b10e01ebfb0583bb7fa93282f8aeb
BLAKE2b-256 c441c4456f186ef1203d032ff62537f6b8c64b200a224ab43d07a428b3f4338b

See more details on using hashes here.

File details

Details for the file gratopy-0.2.0a1-py3-none-any.whl.

File metadata

  • Download URL: gratopy-0.2.0a1-py3-none-any.whl
  • Upload date:
  • Size: 80.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.7

File hashes

Hashes for gratopy-0.2.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 9543b222742b1074f74f88c9ca948c101739ab8ae41dd73547d201847b84d828
MD5 95d216c56fbd5582bc9ef0d220e35828
BLAKE2b-256 79c8cd411b12d94857fe080bf0aae85bfa9d9d3a820ad673f46814481436415c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page