Do Not Ignore the ASTRA Toolbox!

ASTRA logoASTRA logo.

If you are into computed tomography (CT) from the perspective of algorithm development, or if you want to do the reconstruction yourself instead of using a standard software package (e.g., the one that was included with your scanner), you cannot ignore the ASTRA Tomography Toolbox. Well, I am confident you can, if you put your mind to it, but you shouldn’t. This toolbox was developed by the ASTRA research group (“All Scale Tomographic Reconstruction Antwerp”) of the Vision Lab of the University of Antwerp.
Full disclosure: I work at the Vision Lab as a postdoc. However, this article is not sponsored or endorsed by the Vision Lab, it is purely my own opinion.

Quoting from the official description:

It supports 2D parallel and fan beam geometries, and 3D parallel and cone beam. All of them have highly flexible source/detector positioning. A large number of 2D and 3D algorithms are available, including FBP, SIRT, SART, and CGLS. The basic forward and backward projection operations are GPU-accelerated, and directly callable from MATLAB to enable building new algorithms.

During my own PhD research, I have used the ASTRA Toolbox for algorithm development. Because the Toolbox provides GPU implementations of basic components such as projectors, I could use GPU processing already during the experimental stage, allowing me to use real-world (i.e., large) datasets during testing. This is not obvious, since it is often only when an algorithm is complete that a GPU version is written, restricting initial testing to the aptly named academic examples.

MATLAB Wrapper

First of all, to put your mind at rest if you are not a hardcore programmer, the ASTRA Toolbox comes with a user-friendly MATLAB wrapper. All functionality of the Toolbox is available from MATLAB. Since MATLAB is the main way to use the Toolbox, I’ll leave you in the good hands of the official documentation for that, and add an example of my own below that uses the contributed Python wrapper.

Python Wrapper

If you are more of a Python person, there is also a contributed Python wrapper, PyASTRAToolbox.

As an example, I’ve written a Python script that recreates the example with the two white squares on the Wikipedia page on the Radon transform (and additionally also reconstructs the sinogram). The example shows that you can do a lot with only a few lines of code. To keep things brief, there are not a lot of comments, but there are more detailed examples for each part of this script in the PyASTRAToolbox itself.

import numpy as np
from scipy import misc
import astra
# Create phantom.
phantom = np.zeros((128, 128))
phantom[32 : 64, 32 : 64] = np.ones((32, 32))
phantom[64 : 96, 64 : 96] = np.ones((32, 32))
misc.imsave('phantom.png', phantom)
# Create geometries and projector.
vol_geom = astra.create_vol_geom(128, 128)
angles = np.linspace(0, np.pi, 180, endpoint=False)
proj_geom = astra.create_proj_geom('parallel', 1., 128, angles)
projector_id = astra.create_projector('linear', proj_geom, vol_geom)
# Create sinogram.
sinogram_id, sinogram = astra.create_sino(phantom, projector_id)
misc.imsave('sinogram.png', sinogram)
# Create reconstruction.
reconstruction_id = astra.data2d.create('-vol', vol_geom)
cfg = astra.astra_dict('SIRT')
cfg['ReconstructionDataId'] = reconstruction_id
cfg['ProjectionDataId'] = sinogram_id
cfg['ProjectorId'] = projector_id
cfg['option'] = {}
cfg['option']['MinConstraint'] = 0.  # Force solution to be nonnegative.
algorithm_id = astra.algorithm.create(cfg), 100)  # 100 iterations.
reconstruction = astra.data2d.get(reconstruction_id)
misc.imsave('reconstruction.png', reconstruction)
# Cleanup.

The output of this script is shown below. On the left is the phantom with the two white squares. In the middle is the sinogram, which contains a (2D) projection in each horizontal line. From this sinogram, the reconstruction on the right was created through the algebraic algorithm SIRT.

Phantom (left), sinogram (middle), and reconstruction (right)Phantom (left), sinogram (middle), and reconstruction (right)

For more information on tomography itself, have a look at my series of articles on that subject.

[update] This post was selected for Writing Clinic at DailyBlogTips! As a result, I was able to make several improvements to the text. Thanks again, Ali!

Submitted by Tom Roelandts on 22 February 2014


I'm pretty new to using a lot of external libraries in python. My question is, I've downloaded the files for PyASTRA, but I only see install instructions for windows and linux. Do you know if it's possible to install them and use them on an OS X machine?

I’m sorry to have to inform you that OS X is not supported at this time… On a separate note, you don’t have to download the Python interface separately anymore, since it is included in the main ASTRA Toolbox since version 1.6.

I have some 2D X-ray images of an aluminium model. I want to get the cross sectional CT image of that model. Is it possible using this software? If possible then how?

If your data is suitable for CT reconstruction, i.e., if you have a sufficient number of images that were taken with a CT scanner, or at least with a fixed source and detector and a rotating stage, then this should be relatively easy. I would like to point you to the examples that are included with the ASTRA Toolbox. Also note that your images must be preprocessed to make them true projections, as I explain in my series of articles on tomography. If your data consists of only a few images, or was taken with unknown source and detector positions, then it will be much more difficult or even impossible.

Thank you for your answer. I have all the information about detector positions and also all the X-ray images as well. But the problem is i got confused about ASTRA toolbox. Inside the toolbox all the examples used a single phantom and than rotate it to different directions. But my question is, how i can use all the available projections for CT reconstruction. I mean i want to use a series of images rather than using a single image and rotate is to different directions. Really waiting for your response.

The examples in the Toolbox often start from a phantom to create a dataset. Of course, you already have a dataset, and only need the second part of the example. It might also be confusing that the examples are often in 2D, where the “X-ray images” are then 1D, and grouped in a so-called sinogram. You could create a sinogram like that from your data by taking a single row from each of them, but it’s probably easier to immediately create a 3D reconstruction. Another tip is that, if your dataset was recorded using a typical source and a flat-panel detector, you’ll probably need to use a cone-beam geometry (and not a parallel-beam one).

Hi, great toolbox!!
I was wondering if it is possible to perform 3D conebeam reconstructions without GPU. I've only found the functions for GPU. Thanks in advance!

Thanks! It is indeed not possible to perform 3D cone beam reconstructions without a GPU, because there are no CPU versions of the 3D algorithms in the Toolbox. And, of course, for cone beam you cannot run a 2D algorithm on a slice-by-slice basis like you can do for parallel beam…

Ok, thanks a lot for the answer Tom!

Add new comment