The ASTRA Toolbox

The ASTRA Toolbox is a MATLAB and Python toolbox of high-performance GPU primitives for 2D and 3D tomography.

We support 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, CGLS.

The basic forward and backward projection operations are GPU-accelerated, and directly callable from MATLAB and Python to enable building new algorithms.

The source code of the ASTRA Toolbox is available on GitHub.

Downloads

Main downloads:

For compiling on Windows we only provide Visual Studio 2008 and 2012 project files. We have also packaged a set of external libraries and headers for all the build dependencies:

References

If you use the ASTRA Toolbox for your research, we would appreciate it if you would refer to the following paper:

  • W. van Aarle, W. J. Palenstijn, J. De Beenhouwer, T. Altantzis, S. Bals, K. J. Batenburg, and J. Sijbers, “The ASTRA Toolbox: A platform for advanced algorithm development in electron tomography”, Ultramicroscopy (2015), http://dx.doi.org/10.1016/j.ultramic.2015.05.002

Additionally, if you use parallel beam GPU code, we would appreciate it if you would refer to the following paper:

  • W. J. Palenstijn, K J. Batenburg, and J. Sijbers, “Performance improvements for iterative electron tomography reconstruction using graphics processing units (GPUs)”, Journal of Structural Biology, vol. 176, issue 2, pp. 250-253, 2011, http://dx.doi.org/10.1016/j.jsb.2011.07.017

License

The ASTRA Toolbox is open source under the GPLv3 license.

Contact

email: astra@uantwerpen.be website: https://astra-toolbox.readthedocs.org

Copyright: 2010-2015, iMinds-Vision Lab, University of Antwerp 2014-2015, http://visielab.uantwerpen.be/ and CWI, Amsterdam http://www.cwi.nl/

Contents

News and version history

News

  • 2015-12-23: New version 1.7.1beta released. This is a small bugfix release after v1.7beta. ASTRA version 1.7beta contains a few large experimental new features, which is why we have given it the beta tag. If it does not work properly for you, all files for astra-1.6 are also still available for download: astra-1.6 downloads. New features:
    • Experimental MPI distributed computing support in Python. This is only available for Linux+Python, as a separate source download (astra-1.7.1beta_MPI.tar. bz2), or the mpi branch on github.
    • Experimental support in Python for FP and BP of objects composited from multiple 3d data objects, at possibly different resolutions. This also removes some restrictions on data size for 3D GPU FP and BP.
    • Reduced restrictions on volume geometries: The volume no longer has to be centered, and voxels still have to be cubes, but no longer 1x1x1.
  • 2015-05-29: New version 1.6 released. The Python interface developed by Daniel Pelt, and the Matlab Spot toolbox operator wrapping ASTRA developed by Folkert Bleichrodt are now integrated into the main ASTRA Toolbox source tree.
  • 2015-01-17: From 25 to 27 March, 2015, iMinds-Vision Lab organizes the second ASTRA Toolbox training session. For more info, please contact Wim Van Aarle: wim.vanaarle@uantwerpen.be.
  • 2014-02-25: From 9 to 11 April 2014, the iMinds-Vision Lab organizes a training session entitled “Unleashing the ASTRA Tomography Toolbox”.
  • 2013-07-12: Folkert Bleichrodt from CWI has contributed a wrapper around the ASTRA Toolbox for the Spot toolbox.
  • 2013-07-02: New version 1.3 released with some bug fixes and including a version of the DART algorithm by Wim van Aarle from the Vision Lab at the University of Antwerp.
  • 2013-04-24: Daniël M. Pelt from CWI has released a Python interface for the ASTRA Toolbox.
  • 2012-08-20: ASTRA Toolbox, developed by iMinds-Vision Lab of the University of Antwerp, launched!

Version history

  • 1.7.1beta (2015-12-23)
    • NB: This release has a beta tag as it contains two new big experimental features.
    • fix crash with certain 2D CUDA FP calls
  • 1.7beta (2015-12-04)
    • NB: This release has a beta tag as it contains two new big experimental features.
    • experimental MPI distributed computing support in Python
    • experimental support in Python for FP and BP of objects composited from multiple 3d data objects, at possibly different resolutions. This also removes some restrictions on data size for 3D GPU FP and BP.
    • support for Python algorithm plugins
    • removed restrictions on volume geometries:
      • The volume no longer has to be centered.
      • Voxels still have to be cubes, but no longer 1x1x1.
    • build fixes for newer platforms
    • various consistency and bug fixes
  • 1.6 (2015-05-29)
    • integrate and improve python interface
    • integrate opSpot-based opTomo operator
    • build fixes for newer platforms
    • various consistency and bug fixes
  • 1.5 (2015-01-30)
    • add support for fan beam FBP
    • remove limits on number of angles in GPU code (They are still limited by available memory, however)
    • update the included version of the DART algorithm
    • build fixes for newer platforms
    • various consistency and bug fixes
  • 1.4 (2014-04-07)
    • various consistency and bug fixes
    • add global astra_set_gpu_index
  • 1.3 (2013-07-02)
    • various consistency and bug fixes
    • add a version of the DART algorithm (written by Wim van Aarle)
  • 1.2 (2013-03-01)
    • various consistency and bug fixes
  • 1.1 (2012-10-24)
    • add support for matlab single arrays in mex interface
  • 1.0 (2012-08-22)
    • first public release

Downloads

Below is the latest version. For older versions, see the links in the sidebar.

For compiling on Windows we only provide Visual Studio 2008 and 2012 project files. We have also packaged a set of external libraries and headers for all the build dependencies:

ASTRA v1.7.1beta

For compiling on Windows we only provide Visual Studio 2008 and 2012 project files. We have also packaged a set of external libraries and headers for all the build dependencies:

ASTRA v1.7beta

For compiling on Windows we only provide Visual Studio 2008 and 2012 project files. We have also packaged a set of external libraries and headers for all the build dependencies:

ASTRA v1.6

For compiling on Windows we only provide Visual Studio 2008 and 2012 project files. We have also packaged a set of external libraries and headers for all the build dependencies:

ASTRA v1.5

For compiling on Windows we only provide Visual Studio 2008 project files. We have also packaged a set of external libraries and headers for all the build dependencies:

ASTRA v1.4

For compiling on Windows we only provide Visual Studio 2008 project files. We have also packaged a set of external libraries and headers for all the build dependencies:

ASTRA v1.3

For compiling on Windows we only provide Visual Studio 2008 project files. We have also packaged a set of external libraries and headers for all the build dependencies:

Documentation

Installation instructions

Windows, binary

Add the mex and tools subdirectories to your MATLAB path and/or the Python module to your Python path.

Linux, from source

Requirements: g++, boost, CUDA (driver+toolkit), Matlab and/or Python (2.7 or 3.x)

cd build/linux
./autogen.sh   # when building a git version
./configure --with-cuda=/usr/local/cuda \
            --with-matlab=/usr/local/MATLAB/R2012a \
            --with-python
            --prefix=/usr/local/astra
make
make install

Add /usr/local/astra/lib to your LD_LIBRARY_PATH. Add /usr/local/astra/matlab and its subdirectories (tools, mex) to your matlab path. Add /usr/local/astra/python to your PYTHONPATH.

NB: Each matlab version only supports a specific range of g++ versions. Despite this, if you have a newer g++ and if you get errors related to missing GLIBCXX_3.4.xx symbols, it is often possible to work around this requirement by deleting the version of libstdc++ supplied by matlab in MATLAB_PATH/bin/glnx86 or MATLAB_PATH/bin/glnxa64 (at your own risk).

Linux, using conda for python

Requirements: conda python environment

There are packages available for the ASTRA Toolbox in the astra-toolbox channel for the conda package manager. To use these, run the following inside a conda environment.

conda install -c astra-toolbox astra-toolbox
Windows, from source using Visual Studio 2008

Requirements: Visual Studio 2008, boost, CUDA (driver+toolkit), matlab. Note that a .zip with all required (and precompiled) boost files is available from our website.

Set the environment variable MATLAB_ROOT to your matlab install location. Open astra_vc08.sln in Visual Studio. Select the appropriate solution configuration. (typically Release_CUDA|win32 or Release_CUDA|x64) Build the solution. Install by copying AstraCuda32.dll or AstraCuda64.dll from bin/ and all .mexw32 or .mexw64 files from bin/Release_CUDA or bin/Debug_CUDA and the entire matlab/tools directory to a directory to be added to your matlab path.

Linux, building conda packages

To build your own conda packages for the ASTRA toolbox, perform the following steps inside the conda environment:

cd python/conda/libastra
CUDA_ROOT=/path/to/cuda conda-build ./ # Build C++ library
cd ../
CUDA_ROOT=/path/to/cuda conda-build ./ # Build Python interface

The final step includes a test to check whether the build was successful. To be able to perform this test, conda should be able to find the ASTRA C++ library package of the second step. One way of accomplishing this is to temporarily add the conda build directory as a custom channel. To do this, the following steps can be used:

cd python/conda/libastra
CUDA_ROOT=/path/to/cuda conda-build ./ # Build C++ library
cd ../
CUDA_ROOT=/path/to/cuda conda-build \
    -c file://[/path/to/conda_env]/conda-bld/ \
    -c defaults --override-channels ./ # Build Python interface

Toolbox concepts

Geometry

Most of the operations supported by the ASTRA Toolbox require you to specify what the geometry of the (real or virtual) experimental setup you have used or want to simulate is.

This has two parts: a volume geometry, and a projection geometry. The volume geometry specifies where in 2D or 3D space the sample or phantom is located. It takes the form of a 2D rectangle or 3D box, and is usually centered around the origin.

The projection geometry specifies the location and trajectory of the ray source and detector. The available types of projection geometries are 2D parallel beam, 2D fan beam, 3D parallel beam and 3D cone beam.

Data

Toolbox objects are stored in memory separate from Matlab, and have to be explicitly transferred from/to Matlab matrices.

They come in four varieties: 2D/3D volume data, and 2D/3D projection data.

Data objects are manipulated with the astra_mex_data2d/astra.data2d and astra_mex_data3d/astra.data3d commands. The usage of these commands is illustrated in the available sample scripts.

Algorithms

To operate on data objects, the ASTRA Toolbox defines a number of algorithms. These include the basic forward and backward projection operations, and also various reconstruction algorithms.

To create algorithm objects, use the astra_mex_algorithm/astra.algorithm command. The usage of this command is illustrated in the available sample scripts.

2D Geometries

Volume Geometries

Create a 2D volume geometry:

vol_geom = astra_create_vol_geom(rows_and_cols);
vol_geom = astra_create_vol_geom([rows cols]);
vol_geom = astra_create_vol_geom(rows, cols);
vol_geom = astra_create_vol_geom(rows, cols, min_x, max_x, min_y, max_y);

In the first form, the volume contains an equal number of rows and columns. In the first, second and third forms, volume pixels are squares with sides of unit length, and the volume is centered around the origin. In the fourth, longer form, the extents of the volume can be specified arbitrarily. The long form corresponding to the default short form is:

vol_geom = astra_create_vol_geom(y, x, -x/2, x/2, -y/2, y/2);

Note: For usage with GPU code, the volume must be centered around the origin and pixels must be square. This is not always explicitly checked in all functions, so not following these requirements may have unpredictable results.

Projection Geometries

parallel

Create a 2D parallel beam geometry:

proj_geom = astra_create_proj_geom('parallel', det_width, det_count, angles);
  • det_spacing: distance between the centers of two adjacent detector pixels
  • det_count: number of detector pixels in a single projection
  • angles: projection angles in radians

fanflat

Create a 2D flat fan beam geometry:

proj_geom = astra_create_proj_geom('fanflat', det_width, det_count, angles, source_origin, origin_det);
  • det_width: distance between the centers of two adjacent detector pixels
  • det_count: number of detector pixels in a single projection
  • angles: projection angles in radians
  • source_origin: distance between the source and the center of rotation
  • origin_det: distance between the center of rotation and the detector array

fanflat_vec

Create a 2D flat fan beam geometry specified by 2D vectors:

proj_geom = astra_create_proj_geom('fanflat_vec', det_count, vectors);
  • det_count: number of detectors in a single projection
  • vectors: a matrix containing the actual geometry. Each row of vectors corresponds to a single projection, and consists of: ( srcX, srcY, dX, dY, uX, uY )
  • src : the ray source
  • d : the center of the detector
  • u : the vector between the centers of detector pixels 0 and 1

To illustrate, this is a matlab script to convert a single projection in a projection geometry of type “fanflat” into such a 6-element row:

% source
vectors(i,1) = sin(proj_geom.ProjectionAngles(i)) * proj_geom.DistanceOriginSource;
vectors(i,2) = -cos(proj_geom.ProjectionAngles(i)) * proj_geom.DistanceOriginSource;

% center of detector
vectors(i,3) = -sin(proj_geom.ProjectionAngles(i)) * proj_geom.DistanceOriginDetector;
vectors(i,4) = cos(proj_geom.ProjectionAngles(i)) * proj_geom.DistanceOriginDetector;

% vector from detector pixel 0 to 1
vectors(i,5) = cos(proj_geom.ProjectionAngles(i)) * proj_geom.DetectorWidth;
vectors(i,6) = sin(proj_geom.ProjectionAngles(i)) * proj_geom.DetectorWidth;

This conversion is also available as a function in the toolbox:

proj_geom_vec = astra_geom_2vec(proj_geom);

sparse_matrix

Create a 2D projection geometry defined by its system matrix:

proj_geom = astra_create_proj_geom('sparse_matrix', det_width, det_count, angles, matrix_id);
  • det_width: unused, but has to be present (for compatibility reasons)
  • det_count: number of detectors in a single projection
  • angles: a vector, the length of which is the number of projections. The contents are unused.
  • matrix_id: a astra_mex_matrix ID of a sparse matrix of the right dimensions.

The matrix is an ID returned by

matrix_id = astra_mex_matrix('create', matlab_sparse_matrix);

The sparse matrix must be of size (det_count * numel(angles), x*y), where (x,y) is the size of the volume geometry to be used.

The rows of the sparse matrix are ordered by projection: The first row of the matrix corresponds to the first detector pixel of the first projection, and the second row of the matrix corresponds to the second detector pixel of the first projection.

The columns of the sparse matrix are ordered by row: The first column of the matrix corresponds to pixel (1,1) and the second column to pixel (1,2) in the volume.

3D Geometries

In all 3D geometries, the coordinate system is defined around the reconstruction volume. The center of the reconstruction volume is the origin, and the sides of the voxels in the volume have length 1.

All dimensions in the projection geometries are relative to this unit length.

Volume geometries
vol_geom = astra_create_vol_geom(y,x,z);

Create a 3D volume geometry.

Projection geometries

parallel3d

proj_geom = astra_create_proj_geom('parallel3d', det_spacing_x, det_spacing_y, det_row_count, det_col_count, angles);

Create a 3D parallel beam geometry.

  • det_spacing_x: distance between the centers of two horizontally adjacent detector pixels
  • det_spacing_y: distance between the centers of two vertically adjacent detector pixels
  • det_row_count: number of detector rows in a single projection
  • det_col_count: number of detector columns in a single projection
  • angles: projection angles in radians

cone

proj_geom = astra_create_proj_geom('cone',  det_spacing_x, det_spacing_y, det_row_count, det_col_count, angles, source_origin, origin_det);

Create a 3D cone beam geometry.

  • det_spacing_x: distance between the centers of two horizontally adjacent detector pixels
  • det_spacing_y: distance between the centers of two vertically adjacent detector pixels
  • det_row_count: number of detector rows in a single projection
  • det_col_count: number of detector columns in a single projection
  • angles: projection angles in radians
  • source_origin: distance between the source and the center of rotation
  • origin_det: distance between the center of rotation and the detector array

parallel3d_vec

proj_geom = astra_create_proj_geom('parallel3d_vec',  det_row_count, det_col_count, vectors);

Create a 3D parallel beam geometry specified by 3D vectors.

  • det_row_count: number of detector rows in a single projection
  • det_col_count: number of detector columns in a single projection
  • vectors: a matrix containing the actual geometry.

Each row of vectors corresponds to a single projection, and consists of:

( rayX, rayY, rayZ, dX, dY, dZ, uX, uY, uZ, vX, vY, vZ )
  • ray : the ray direction
  • d : the center of the detector
  • u : the vector from detector pixel (0,0) to (0,1)
  • v : the vector from detector pixel (0,0) to (1,0)

To illustrate, this is a matlab script to convert a single projection in a projection geometry of type “parallel3d” into such a 12-element row:

% ray direction
vectors(i,1) = sin(proj_geom.ProjectionAngles(i));
vectors(i,2) = -cos(proj_geom.ProjectionAngles(i));
vectors(i,3) = 0;

% center of detector
vectors(i,4) = 0;
vectors(i,5) = 0;
vectors(i,6) = 0;

% vector from detector pixel (0,0) to (0,1)
vectors(i,7) = cos(proj_geom.ProjectionAngles(i)) * proj_geom.DetectorSpacingX;
vectors(i,8) = sin(proj_geom.ProjectionAngles(i)) * proj_geom.DetectorSpacingX;
vectors(i,9) = 0;

% vector from detector pixel (0,0) to (1,0)
vectors(i,10) = 0;
vectors(i,11) = 0;
vectors(i,12) = proj_geom.DetectorSpacingY;

This conversion is also available as a function in the toolbox:

proj_geom_vec = astra_geom_2vec(proj_geom);

cone_vec

proj_geom = astra_create_proj_geom('cone_vec',  det_row_count, det_col_count, vectors);

Create a 3D cone beam geometry specified by 3D vectors.

  • det_row_count: number of detector rows in a single projection
  • det_col_count: number of detector columns in a single projection
  • vectors: a matrix containing the actual geometry.

Each row of vectors corresponds to a single projection, and consists of:

( srcX, srcY, srcZ, dX, dY, dZ, uX, uY, uZ, vX, vY, vZ )
  • src : the ray source
  • d : the center of the detector
  • u : the vector from detector pixel (0,0) to (0,1)
  • v : the vector from detector pixel (0,0) to (1,0)

To illustrate, this is a matlab script to convert a single projection in a projection geometry of type “cone” into such a 12-element row:

% source
vectors(i,1) = sin(proj_geom.ProjectionAngles(i)) * proj_geom.DistanceOriginSource;
vectors(i,2) = -cos(proj_geom.ProjectionAngles(i)) * proj_geom.DistanceOriginSource;
vectors(i,3) = 0;

% center of detector
vectors(i,4) = -sin(proj_geom.ProjectionAngles(i)) * proj_geom.DistanceOriginDetector;
vectors(i,5) = cos(proj_geom.ProjectionAngles(i)) * proj_geom.DistanceOriginDetector;
vectors(i,6) = 0;

% vector from detector pixel (0,0) to (0,1)
vectors(i,7) = cos(proj_geom.ProjectionAngles(i)) * proj_geom.DetectorSpacingX;
vectors(i,8) = sin(proj_geom.ProjectionAngles(i)) * proj_geom.DetectorSpacingX;
vectors(i,9) = 0;

% vector from detector pixel (0,0) to (1,0)
vectors(i,10) = 0;
vectors(i,11) = 0;
vectors(i,12) = proj_geom.DetectorSpacingY;

2D Projectors

Projectors determine the (implicit) weight matrix of the geometries. All CPU reconstruction algorithms require a projector.

Each projector is only suitable for specific projection geometries.

Creation
id = astra_create_projector(...);

Create a projector object. Projectors determine the (implicit) weight matrix of the geometries. All CPU reconstruction algorithms require a projector.

This script is a wrapper around astra_mex_projector(‘create’, ...) with a more convenient interface. See below for specifics.

The allocated object must be freed after use with a call to

astra_mex_projector('delete', id)
Parallel beam

The projectors in this section can be used with the parallel projection geometry.

line

proj_id = astra_create_projector('line', proj_geom, vol_geom);

The weight of a ray/pixel pair is given by the length of the intersection of the pixel and the ray, considered as a zero-thickness line.

strip

proj_id = astra_create_projector('strip', proj_geom, vol_geom);

The weight of a ray/pixel pair is given by the area of the intersection of the pixel and the ray, considered as a strip with the same width as a detector pixel.

linear

proj_id = astra_create_projector('linear', proj_geom, vol_geom);

A ray is traced through successive columns or rows (depending on which are most orthogonal to the ray). The contribution of this column/row to this ray is then given by linearly interpolating between the two nearest volume pixels of the intersection of the ray and the column/row.

This is also known as the Joseph kernel, or a slice-interpolated kernel.

Fan beam

line_fanflat

proj_id = astra_create_projector('line_fanflat', proj_geom, vol_geom);

The weight of a ray/pixel pair is given by the length of the intersection of the pixel and the ray, considered as a zero-thickness line. This projector can be used with the fanflat and fanflat_vec geometries.

strip_fanflat

proj_id = astra_create_projector('strip_fanflat', proj_geom, vol_geom);

The weight of a ray/pixel pair is given by the area of the intersection of the pixel and the ray. The ray is considered as a 2D cone from the source to the full width of the detector pixel. The projector can only be used with the fanflat geometry.

NB: This mathematical model does not properly take into account the fan beam magnification effect.

Miscellaneous

sparse_matrix

proj_id = astra_create_projector('sparse_matrix', proj_geom, vol_geom);

This projector uses a sparse matrix projection geometry. See the documentation for that geometry for details.

cuda

proj_id = astra_create_projector('cuda', proj_geom, vol_geom);

This projector does not directly specify a weight matrix, but instead is intended to let algorithms use GPU/CUDA code. It can be used with parallel, fanflat and fanflat_vec projection geometries.

NB: This functionality has not yet been implemented everywhere. This projector is currently only usable in astra_create_sino and astra_create_backprojection.

astra_mex_projector

astra_mex_projector is used to manage projector objects.

It is a wrapper around the MEX file astra_mex_projector_c.

astra_mex_projector contains the following commands.

  • create
  • matrix
  • volume_geometry
  • projection_geometry
  • is_cuda
  • delete
  • clear
  • info

create

id = astra_mex_projector('create', cfg);

Create a projector from a config object. This is called internally by the script [[astra_create_projector]], which is the recommended way to create most projectors.

matrix

matrix_id = astra_mex_projector('matrix', projector_id);

Create an explicit sparse matrix for the weight matrix encoded by this projector.

This is only implemented for 2D CPU projectors.

The returned matrix_id can be further manipulated with [astra_mex_matrix]. In particular, it can be retrieved as a Matlab sparse matrix with

S = astra_mex_matrix('get', matrix_id);

It has to be freed after use with

astra_mex_matrix('delete', matrix_id);

NB: Such a matrix can be very large for large geometries.

volume_geometry

vol_geom = astra_mex_projector('volume_geometry', id);

Get the volume geometry attached to the given projector object.

NB: This is not fully implemented yet and the return value may not accurately represent the geometry.

projection_geometry

proj_geom = astra_mex_projector('projection_geometry', id);

Get the projection geometry attached to the given projector object.

NB: This is not fully implemented yet and the return value may not accurately represent the geometry.

is_cuda

c = astra_mex_projector('is_cuda', id);

Return if the the projector is a CUDA projector.

delete

astra_mex_projector('delete', id)
astra_mex_projector('delete', id1, id2, ...)

Free a single or multiple projector(s).

clear

astra_mex_projector('clear')

Free all projectors.

info

astra_mex_projector('info')

Print basic information about all allocated projector objects.

2D Data Objects

astra_mex_data2d

astra_mex_data2d is used to manage 2D data objects. It is a wrapper around the MEX file astra_mex_data2d_c.

2D data objects come in two varieties: volume data and projection data (sinograms).

astra_mex_data2d contains the following commands.

  • create
  • get
  • get_single
  • set / store
  • get_geometry
  • change_geometry
  • delete
  • clear
  • info

create

id = astra_mex_data2d('create', '-vol', vol_geom);
id = astra_mex_data2d('create', '-vol', vol_geom, initializer);

This creates an initialized 2D volume data object for the geometry vol_geom.

Initializer may be:

  • a scalar: the object is initialized with this constant value.
  • a matrix: the object is initialized with the contents of this matrix. The matrix must be of size (y,x) as defined in the volume geometry. It must be of class single, double or logical.

If an initializer is not present, the volume is initialized to zero.

id = astra_mex_data2d('create', '-sino', proj_geom);
id = astra_mex_data2d('create', '-sino', proj_geom, initializer);

This creates an initialized 2D projection data object for the geometry proj_geom.

Initializer may be:

  • a scalar: the object is initialized with this constant value.
  • a matrix: the object is initialized with the contents of this matrix. The matrix must be of size (angles,u), where u is the number of detector pixels as defined in the projection geometry. It must be of class single, double or logical.

If an initializer is not present, the volume is initialized to zero.

get

A = astra_mex_data2d('get', id);

This fetches the data object as a 2D matrix of class double.

get_single

A = astra_mex_data2d('get_single', id);

This fetches the data object as a 2D matrix of class single.

set / store

astra_mex_data2d('set', id, A)
astra_mex_data2d('store', id, A)

This stores the matrix A in the data object. The dimensions of A must be the same as when used as an initializer in astra_mex_data2d(‘create’).

Set and store are synonyms.

get_geometry

geom = astra_mex_data2d('get_geometry', id);

This gets the (volume or projection) geometry attached to the object.

NB: This is not fully implemented yet and the return value may not accurately represent the geometry.

change_geometry

astra_mex_data2d('change_geometry', id, geom);

This changes the (volume or projection) geometry attached to the object. It may not change the actual dimensions of the data object. This can be used to change the pixel dimensions or projection angles, for example.

delete

astra_mex_data2d('delete', id);

Free the memory of a data object.

clear

astra_mex_data2d('clear');

Free all data objects.

info

astra_mex_data2d('info')

Print basic information about all allocated data objects.

3D Data Objects

astra_mex_data3d

astra_mex_data3d is used to manage 3D data objects. It is a wrapper around the MEX file astra_mex_data3d_c.

3D data objects come in two varieties: volume data and projection data.

astra_mex_data3d has the following commands.

  • create
  • get
  • get_single
  • set / store
  • dimensions
  • delete
  • clear
  • info
  • link

create

id = astra_mex_data3d('create', '-vol', vol_geom);
id = astra_mex_data3d('create', '-vol', vol_geom, initializer);

This creates an initialized 3D volume data object for the geometry vol_geom.

Initializer may be:

  • a scalar: the object is initialized with this constant value.
  • a matrix: the object is initialized with the contents of this matrix. The matrix must be of size (x,y,z) as defined in the volume geometry. It must be of class single, double or logical.

If an initializer is not present, the volume is initialized to zero.

id = astra_mex_data3d('create', '-proj3d', proj_geom);
id = astra_mex_data3d('create', '-proj3d', proj_geom, initializer);

This creates an initialized 3D projection data object for the geometry proj_geom.

Initializer may be:

  • a scalar: the object is initialized with this constant value.
  • a matrix: the object is initialized with the contents of this matrix. The matrix must be of size (u,angles,v), where u is the number of columns of the detector and v the number of rows as defined in the projection geometry. It must be of class single, double or logical.

If an initializer is not present, the volume is initialized to zero.

get

A = astra_mex_data3d('get', id);

This fetches the data object as a 3D matrix of class double.

get_single

A = astra_mex_data3d('get_single', id);

This fetches the data object as a 3D matrix of class single.

set / store

astra_mex_data3d('set', id, A);
astra_mex_data3d('store', id, A);

This stores the matrix A in the data object. The dimensions of A must be the same as when used as an initializer in astra_mex_data3d(‘create’).

Set and store are synonyms.

dimensions

s = astra_mex_data3d('dimensions', id);

Get the dimensions of a data object.

delete

astra_mex_data3d('delete', id);

Free the memory of a data object.

clear

astra_mex_data3d('clear');

Free all data objects.

info

astra_mex_data3d('info')

Print basic information about all allocated data objects.

link

id = astra_mex_data3d_c('link', '-vol', vol_geom, array, readonly, Z);
id = astra_mex_data3d_c('link', '-proj3d', proj_geom, array, readonly, Z);

NB: This must be called on astra_mex_data3d_c, and does not work properly when using the wrapper astra_mex_data3d.

This creates a data object that directly uses a matlab array as storage instead of allocating its own memory. The array must be of the same dimensions as those required for initializers in astra_mex_data3d(‘create’). Additionally, it must be of class ‘single’.

The optional argument ‘readonly’ (default: false), controls the exact behaviour of this operation. See the two sections below for details.

The optional argument ‘Z’ (default: 0) allows creating a data object that is smaller in the third dimension than the Matlab array. The data object will be mapped to slices starting at slice Z. NB: Z is zero-based, unlike matlab array indexing.

Read-only link mode:

The data object becomes an additional reference to the array, effectively behaving the same as a Matlab assignment ‘internal_data = A;’ (if ‘A’ is passed as the ‘array’ argument). If the array A is changed inside Matlab, a copy will be made and the changes to A will not be visible to this data object.

The data object’s read-only state is not enforced by the astra toolbox. Using it as output for algorithms is allowed, but the exact effects depend on Matlab’s internal reference counting mechanics.

Read-write link mode:

The passed array is ‘unshared’ and the data object obtains a second reference to this array. There is no direct Matlab script equivalent to this, but effectively the data object and the passed array will share memory. Any changes to the data object from inside the toolbox will be visible in Matlab.

If the passed array is modified in Matlab, this link is broken (by matlab’s reference counting mechanism), and the changes will not be visible to the astra data object.

Algorithms

2D CPU Algorithms
FP

This is a CPU implementation of a simple forward projection algorithm for 2D data sets. It takes a projector and a volume as input, and returns the projection data.

Supported geometries: parallel, fanflat, fanflat_vec, matrix.

Configuration options
name type description
cfg.ProjectorId required The astra_mex_projector ID of the projector.
cfg.ProjectionDataId required The astra_mex_data2d ID of the projection data. The content of this data is overwritten.
cfg.VolumeDataId required The astra_mex_data2d ID of the reconstruction data.
cfg.option.SinogramMaskId optional If specified, the astra_mex_data2d ID of a projection-data-sized volume to be used as a mask.
cfg.option.VolumeMaskId optional If specified, the astra_mex_data2d ID of a volume-data-sized volume to be used as a mask.
Example
%% create geometries and projector
proj_geom = astra_create_proj_geom('parallel', 1.0, 256, linspace2(0,pi,180));
vol_geom = astra_create_vol_geom(256,256);
proj_id = astra_create_projector('linear', proj_geom, vol_geom);

%% store volume
V = phantom(256);
volume_id = astra_mex_data2d('create', '-vol', vol_geom, V);

%% create forward projection
sinogram_id = astra_mex_data2d('create', '-sino', proj_geom, 0);
cfg = astra_struct('FP');
cfg.ProjectorId = proj_id;
cfg.ProjectionDataId = sinogram_id;
cfg.VolumeDataId = volume_id;
fp_id = astra_mex_algorithm('create', cfg);
astra_mex_algorithm('run', fp_id);
sinogram = astra_mex_data2d('get', sinogram_id);
imshow(sinogram, []);

%% garbage disposal
astra_mex_data2d('delete', sinogram_id, volume_id);
astra_mex_projector('delete', proj_id);
astra_mex_algorithm('delete', fp_id);

This functionality can also be found in the astra function:

[sinogram_id, sinogram] = astra_create_sino(V, proj_id);
[sinogram_id, sinogram] = astra_create_sino(V_id, proj_id);
BP

This is a CPU implementation of a simple backprojection algorithm for 2D data sets. It takes a projector and projection data as input, and returns the backprojection of this data.

Supported geometries: parallel, fanflat, fanflat_vec, matrix.

Configuration options
name type description
cfg.ProjectorId required The astra_mex_projector ID of the projector.
cfg.ProjectionDataId required The astra_mex_data2d ID of the projection data
cfg.ReconstructionDataId required The astra_mex_data2d ID of the reconstruction data. The content of this data is overwritten.
cfg.option.SinogramMaskId optional If specified, the astra_mex_data2d ID of a projection-data-sized volume to be used as a mask.
cfg.option.ReconstructionMaskId optional If specified, the astra_mex_data2d ID of a volume-data-sized volume to be used as a mask.
FBP

This is a CPU implementation of the Filtered Backprojection (FBP) algorithm for 2D data sets. It takes a projector, projection data and an initial reconstruction as input, and returns the reconstruction.

Supported geometries: parallel.

Configuration options
name type description
cfg.ProjectorId required The astra_mex_projector ID of the projector.
cfg.ProjectionDataId required The astra_mex_data2d ID of the projection data
cfg.ReconstructionDataId required The astra_mex_data2d ID of the reconstruction data. The content of this data is overwritten.
Example
%% create phantom
V_exact = phantom(256);

%% create geometries and projector
proj_geom = astra_create_proj_geom('parallel', 1.0, 256, linspace2(0,pi,180));
vol_geom = astra_create_vol_geom(256,256);
proj_id = astra_create_projector('linear', proj_geom, vol_geom);

%% create forward projection
[sinogram_id, sinogram] = astra_create_sino(V_exact, proj_id);

%% reconstruct
recon_id = astra_mex_data2d('create', '-vol', vol_geom, 0);
cfg = astra_struct('FBP');
cfg.ProjectorId = proj_id;
cfg.ProjectionDataId = sinogram_id;
cfg.ReconstructionDataId = recon_id;
fbp_id = astra_mex_algorithm('create', cfg);
astra_mex_algorithm('run', fbp_id);
V = astra_mex_data2d('get', recon_id);
imshow(V, []);

%% garbage disposal
astra_mex_data2d('delete', sinogram_id, recon_id);
astra_mex_projector('delete', proj_id);
astra_mex_algorithm('delete', fbp_id);
SIRT

This is a CPU implementation of the Simultaneous Iterative Reconstruction Technique (SIRT) for 2D data sets. It takes projection data and an initial reconstruction as input, and returns the reconstruction after a specified number of SIRT iterations.

Supported geometries: parallel, fanflat, fanflat_vec, matrix.

Configuration options
name type description
cfg.ProjectorId required The astra_mex_projector ID of the projector.
cfg.ProjectionDataId required The astra_mex_data2d ID of the projection data
cfg.ReconstructionDataId required The astra_mex_data2d ID of the reconstruction data. The content of this when starting SIRT is used as the initial reconstruction.
cfg.option.SinogramMaskId optional If specified, the astra_mex_data2d ID of a projection-data-sized volume to be used as a mask.
cfg.option.ReconstructionMaskId optional If specified, the astra_mex_data2d ID of a volume-data-sized volume to be used as a mask.
cfg.option.MinConstraint optional If specified, all values below MinConstraint will be set to MinConstraint. This can, for example, be used to enforce non-negative reconstructions.
cfg.option.MaxConstraint optional If specified, all values above MaxConstraint will be set to MaxConstraint.
Example
%% create phantom
V_exact = phantom(256);

%% create geometries and projector
proj_geom = astra_create_proj_geom('parallel', 1.0, 256, linspace2(0,pi,180));
vol_geom = astra_create_vol_geom(256,256);
proj_id = astra_create_projector('linear', proj_geom, vol_geom);

%% create forward projection
[sinogram_id, sinogram] = astra_create_sino(V_exact, proj_id);

%% reconstruct
recon_id = astra_mex_data2d('create', '-vol', vol_geom, 0);
cfg = astra_struct('SIRT');
cfg.ProjectorId = proj_id;
cfg.ProjectionDataId = sinogram_id;
cfg.ReconstructionDataId = recon_id;
cfg.option.MinConstraint = 0;
cfg.option.MaxConstraint = 255;
sirt_id = astra_mex_algorithm('create', cfg);
astra_mex_algorithm('iterate', sirt_id, 100);
V = astra_mex_data2d('get', recon_id);
imshow(V, []);

%% garbage disposal
astra_mex_data2d('delete', sinogram_id, recon_id);
astra_mex_projector('delete', proj_id);
astra_mex_algorithm('delete', sirt_id);
SART

This is a CPU implementation of the Simultaneous Algebraic Reconstruction Technique (SART) for 2D data sets. It takes projection data and an initial reconstruction as input, and returns the reconstruction after a specified number of SART iterations. Each iteration of SART consists of an FP and BP of one single projection direction. The order of the projections can be specified.

Supported geometries: parallel, fanflat, fanflat_vec, matrix.

Configuration options
name type description
cfg.ProjectorId required The astra_mex_projector ID of the projector.
cfg.ProjectionDataId required The astra_mex_data2d ID of the projection data
cfg.ReconstructionDataId required The astra_mex_data2d ID of the reconstruction data. The content of this when starting SART is used as the initial reconstruction.
cfg.option.SinogramMaskId optional If specified, the astra_mex_data2d ID of a projection-data-sized volume to be used as a mask.
cfg.option.ReconstructionMaskId optional If specified, the astra_mex_data2d ID of a volume-data-sized volume to be used as a mask.
cfg.option.MinConstraint optional If specified, all values below MinConstraint will be set to MinConstraint. This can, for example, be used to enforce non-negative reconstructions.
cfg.option.MaxConstraint optional If specified, all values above MaxConstraint will be set to MaxConstraint.
cfg.option.ProjectionOrder optional This specifies the order in which the projections are used. Possible values are: ‘random’ (default), ‘sequential’, and ‘custom’. If ‘custom’ is specified, the option.ProjectionOrderList is required.
cfg.option.ProjectionOrderList optional Required if option.ProjectionOrder = ‘custom’, ignored otherwise. A matlab vector containing the custom order in which the projections are used.
Example
%% create phantom
V_exact = phantom(256);

%% create geometries and projector
proj_geom = astra_create_proj_geom('parallel', 1.0, 256, linspace2(0,pi,180));
vol_geom = astra_create_vol_geom(256,256);
proj_id = astra_create_projector('linear', proj_geom, vol_geom);

%% create forward projection
[sinogram_id, sinogram] = astra_create_sino(V_exact, proj_id);

%% reconstruct
recon_id = astra_mex_data2d('create', '-vol', vol_geom, 0);
cfg = astra_struct('SART');
cfg.ProjectorId = proj_id;
cfg.ProjectionDataId = sinogram_id;
cfg.ReconstructionDataId = recon_id;
cfg.option.ProjectionOrder = 'custom';
cfg.option.ProjectionOrderList = [0:5:175 1:5:176 2:5:177 3:5:178 4:5:179];
sart_id = astra_mex_algorithm('create', cfg);
astra_mex_algorithm('iterate', sart_id, 10*180);
V = astra_mex_data2d('get', recon_id);
imshow(V, []);

%% garbage disposal
astra_mex_data2d('delete', sinogram_id, recon_id);
astra_mex_projector('delete', proj_id);
astra_mex_algorithm('delete', sart_id);

Further examples regarding the different projection orders can be found in example_sart_order.m .

ART

This is a CPU implementation of the Iterative Reconstruction Technique (ART) for 2D data sets. It takes projection data and an initial reconstruction as input, and returns the reconstruction after a specified number of ART iterations. Each iteration of ART consists of an FP and BP of one single projection ray. The order of the rays can be specified.

Supported geometries: parallel, fanflat, fanflat_vec, matrix.

Configuration options
name type description
cfg.ProjectorId required The astra_mex_projector ID of the projector.
cfg.ProjectionDataId required The astra_mex_data2d ID of the projection data
cfg.ReconstructionDataId required The astra_mex_data2d ID of the reconstruction data. The content of this when starting ART is used as the initial reconstruction.
cfg.option.SinogramMaskId optional If specified, the astra_mex_data2d ID of a projection-data-sized volume to be used as a mask.
cfg.option.ReconstructionMaskId optional If specified, the astra_mex_data2d ID of a volume-data-sized volume to be used as a mask.
cfg.option.MinConstraint optional If specified, all values below MinConstraint will be set to MinConstraint. This can, for example, be used to enforce non-negative reconstructions.
cfg.option.MaxConstraint optional If specified, all values above MaxConstraint will be set to MaxConstraint.
cfg.option.RayOrder optional This specifies the order in which the projections are used. Possible values are: ‘sequential’ (default) and ‘custom’. If ‘custom’ is specified, the option.RayOrderList is required.
cfg.option.RayOrderList optional Required if option.RayOrder = ‘custom’, ignored otherwise. A matlab vector containing the custom order in which the projections are used.
Example
%% create phantom
V_exact = phantom(256);

%% create geometries and projector
proj_geom = astra_create_proj_geom('parallel', 1.0, 256, linspace2(0,pi,180));
vol_geom = astra_create_vol_geom(256,256);
proj_id = astra_create_projector('linear', proj_geom, vol_geom);

%% create forward projection
[sinogram_id, sinogram] = astra_create_sino(V_exact, proj_id);

%% reconstruct

[p,q] = meshgrid(0:179, 0:255);
rayOrderList = [p(:) q(:)];
rayOrderList = rayOrderList(randperm(numel(p)),:);

recon_id = astra_mex_data2d('create', '-vol', vol_geom, 0);
cfg = astra_struct('ART');
cfg.ProjectorId = proj_id;
cfg.ProjectionDataId = sinogram_id;
cfg.ReconstructionDataId = recon_id;
cfg.option.RayOrder = 'custom';
cfg.option.RayOrderList = rayOrderList;
art_id = astra_mex_algorithm('create', cfg);
astra_mex_algorithm('iterate', art_id, 3*numel(p));
V = astra_mex_data2d('get', recon_id);
imshow(V, []);

%% garbage disposal
astra_mex_data2d('delete', sinogram_id, recon_id);
astra_mex_projector('delete', proj_id);
astra_mex_algorithm('delete', art_id);

Further examples regarding the different projection orders can be found in example_art_order.m .

CGLS

This is a CPU implementation of the Conjugate Gradient Least Squares (CGLS) algorithm for 2D data sets. It takes projection data and an initial reconstruction as input, and returns the reconstruction after a specified number of CGLS iterations.

The internal state of the CGLS algorithm is NOT reset between astra_mex_algorithm(‘iterate’) calls. Updating the contents of the projection data and reconstruction data astra_mex_data2d objects between astra_mex_algorithm(‘iterate’) calls will produce undefined behaviour.

Supported geometries: parallel, fanflat, fanflat_vec, matrix.

Configuration options
name type description
cfg.ProjectorId required The astra_mex_projector ID of the projector.
cfg.ProjectionDataId required The astra_mex_data2d ID of the projection data
cfg.ReconstructionDataId required The astra_mex_data2d ID of the reconstruction data. The content of this when starting CGLS is used as the initial reconstruction.
cfg.option.SinogramMaskId optional If specified, the astra_mex_data2d ID of a projection-data-sized volume to be used as a mask.
cfg.option.ReconstructionMaskId optional If specified, the astra_mex_data2d ID of a volume-data-sized volume to be used as a mask.
Example
%% create phantom
V_exact = phantom(256);

%% create geometries and projector
proj_geom = astra_create_proj_geom('parallel', 1.0, 256, linspace2(0,pi,180));
vol_geom = astra_create_vol_geom(256,256);
proj_id = astra_create_projector('linear', proj_geom, vol_geom);

%% create forward projection
[sinogram_id, sinogram] = astra_create_sino(V_exact, proj_id);

%% reconstruct
recon_id = astra_mex_data2d('create', '-vol', vol_geom, 0);
cfg = astra_struct('CGLS');
cfg.ProjectorId = proj_id;
cfg.ProjectionDataId = sinogram_id;
cfg.ReconstructionDataId = recon_id;
cgls_id = astra_mex_algorithm('create', cfg);
astra_mex_algorithm('iterate', cgls_id, 100);
V = astra_mex_data2d('get', recon_id);
imshow(V, []);

%% garbage disposal
astra_mex_data2d('delete', sinogram_id, recon_id);
astra_mex_projector('delete', proj_id);
astra_mex_algorithm('delete', cgls_id);
2D GPU Algorithms
FP_CUDA

This is a GPU implementation of a simple forward projection algorithm for 2D data sets. It takes a volume as input, and returns the projection data.

Supported geometries: parallel, fanflat, fanflat_vec.

Configuration options
name type description
cfg.ProjectionDataId required The astra_mex_data2d ID of the projection data. The forward projection is added to this data.
cfg.VolumeDataId required The astra_mex_data2d ID of the reconstruction data.
cfg.option.DetectorSuperSampling optional Specifies the amount of detector supersampling, i.e., how many rays are cast per detector.
cfg.option.GPUindex optional Specifies which GPU to use. Default = 0.
Example
%% create geometries
proj_geom = astra_create_proj_geom('parallel', 1.0, 256, linspace2(0,pi,180));
vol_geom = astra_create_vol_geom(256,256);

%% store volume
V = phantom(256);
volume_id = astra_mex_data2d('create', '-vol', vol_geom, V);

%% create forward projection
sinogram_id = astra_mex_data2d('create', '-sino', proj_geom, 0);
cfg = astra_struct('FP_CUDA');
cfg.ProjectionDataId = sinogram_id;
cfg.VolumeDataId = volume_id;
fp_id = astra_mex_algorithm('create', cfg);
astra_mex_algorithm('run', fp_id);
sinogram = astra_mex_data2d('get', sinogram_id);
imshow(sinogram, []);

%% garbage disposal
astra_mex_data2d('delete', sinogram_id, volume_id);
astra_mex_algorithm('delete', fp_id);

This functionality can also be found in the astra function:

[sinogram_id, sinogram] = astra_create_sino_cuda(V, proj_geom, vol_geom);
[sinogram_id, sinogram] = astra_create_sino_cuda(V_id, proj_geom, vol_geom);
BP_CUDA

This is a GPU implementation of a simple backprojection algorithm for 2D data sets. It takes projection data as input, and returns the backprojection of this data.

Supported geometries: parallel, fanflat, fanflat_vec.

Configuration options
name type description
cfg.ProjectionDataId required The astra_mex_data2d ID of the projection data
cfg.ReconstructionDataId required The astra_mex_data2d ID for the backprojection data.
cfg.option.GPUindex optional Specifies which GPU to use. Default = 0.
cfg.option.PixelSuperSampling optional Specifiec the amount of pixel supersampling, i.e., how many (one dimension) subpixels are generated from a single parent pixel.
FBP_CUDA

This is a CPU implementation of the Filtered Backprojection (FBP) algorithm for 2D data sets. It takes projection data as input, and returns the reconstruction.

Supported geometries: parallel, fanflat

Configuration options
name type description
cfg.ProjectorId required The astra_mex_projector ID of the projector.
cfg.ProjectionDataId required The astra_mex_data2d ID of the projection data
cfg.ReconstructionDataId required The astra_mex_data2d ID of the reconstruction data. The content of this is overwritten.
cfg.FilterType optional Type of projection filter. Options: ‘ram-lak’ (default), ‘shepp-logan’, ‘cosine’, ‘hamming’, ‘hann’, ‘none’, ‘tukey’, ‘lanczos’, ‘triangular’, ‘gaussian’, ‘barlett-hann’, ‘blackman’, ‘nuttall’, ‘blackman-harris’, ‘blackman-nuttall’, ‘flat-top’, ‘kaiser’, ‘parzen’, ‘projection’, ‘sinogram’, ‘rprojection’, ‘rsinogram’.
cfg.FilterSinogramId optional Only for some FilterTypes.
cfg.FilterParameter optional Only for some FilterTypes.
cfg.FilterD optional Only for some FilterTypes.
cfg.option.GPUindex optional Specifies which GPU to use. Default = 0.
cfg.option.PixelSuperSampling optional Specifies the amount of pixel supersampling, i.e., how many (one dimension) subpixels are generated from a single parent pixel.
cfg.option.ShortScan optional Only for use with the fanflat geometry. If enabled, do Parker weighting to support non-360-degree data. This needs an angle range of at least 180 degrees plus twice the fan angle. Defaults to no.
Example
%% create phantom
V_exact = phantom(256);

%% create geometries
proj_geom = astra_create_proj_geom('parallel', 1.0, 256, linspace2(0,pi,180));
vol_geom = astra_create_vol_geom(256,256);

%% create forward projection
[sinogram_id, sinogram] = astra_create_sino_cuda(V_exact, proj_geom, vol_geom);

%% reconstruct
recon_id = astra_mex_data2d('create', '-vol', vol_geom, 0);
cfg = astra_struct('FBP_CUDA');
cfg.ProjectionDataId = sinogram_id;
cfg.ReconstructionDataId = recon_id;
fbp_id = astra_mex_algorithm('create', cfg);
astra_mex_algorithm('run', fbp_id);
V = astra_mex_data2d('get', recon_id);
imshow(V, []);

%% garbage disposal
astra_mex_data2d('delete', sinogram_id, recon_id);
astra_mex_algorithm('delete', fbp_id);
SIRT_CUDA

This is a GPU implementation of the Simultaneous Iterative Reconstruction Technique (SIRT) for 2D data sets. It takes projection data and an initial reconstruction as input, and returns the reconstruction after a specified number of SIRT iterations.

Supported geometries: parallel, fanflat, fanflat_vec.

Configuration options
name type description
cfg.ProjectionDataId required The astra_mex_data2d ID of the projection data
cfg.ReconstructionDataId required The astra_mex_data2d ID of the reconstruction data. The content of this when starting SIRT is used as the initial reconstruction.
cfg.option.SinogramMaskId optional If specified, the astra_mex_data2d ID of a projection-data-sized volume to be used as a mask.
cfg.option.ReconstructionMaskId optional If specified, the astra_mex_data2d ID of a volume-data-sized volume to be used as a mask.
cfg.option.MinConstraint optional If specified, all values below MinConstraint will be set to MinConstraint. This can, for example, be used to enforce non-negative reconstructions.
cfg.option.MaxConstraint optional If specified, all values above MaxConstraint will be set to MaxConstraint.
cfg.option.GPUindex optional Specifies which GPU to use. Default = 0.
cfg.option.DetectorSuperSampling optional Specifies the amount of detector supersampling, i.e. how many rays are cast per detector.
cfg.option.PixelSuperSampling optional Specifiec the amount of pixel supersampling, i.e. how many (one dimension) subpixels are generated from a single parent pixel.
Example
%% create phantom
V_exact = phantom(256);

%% create geometries
proj_geom = astra_create_proj_geom('parallel', 1.0, 256, linspace2(0,pi,180));
vol_geom = astra_create_vol_geom(256,256);

%% create forward projection
[sinogram_id, sinogram] = astra_create_sino_cuda(V_exact, proj_geom, vol_geom);

%% reconstruct
recon_id = astra_mex_data2d('create', '-vol', vol_geom, 0);
cfg = astra_struct('SIRT_CUDA');
cfg.ProjectionDataId = sinogram_id;
cfg.ReconstructionDataId = recon_id;
cfg.option.MinConstraint = 0;
cfg.option.MaxConstraint = 255;
sirt_id = astra_mex_algorithm('create', cfg);
astra_mex_algorithm('iterate', sirt_id, 100);
V = astra_mex_data2d('get', recon_id);
imshow(V, []);

%% garbage disposal
astra_mex_data2d('delete', sinogram_id, recon_id);
astra_mex_algorithm('delete', sirt_id);
Extra features

SIRT_CUDA supports astra_mex_algorithm(‘get_res_norm’) to get the 2-norm of the difference between the projection data and the projection of the reconstruction. (The square root of the sum of squares of differences.)

SART_CUDA

This is a GPU implementation of the Simultaneous Algebraic Reconstruction Technique (SART) for 2D data sets. It takes projection data and an initial reconstruction as input, and returns the reconstruction after a specified number of SART iterations. Each iteration of SART consists of an FP and BP of one single projection direction. The order of the projections can be specified.

Supported geometries: parallel, fanflat, fanflat_vec.

Configuration options
name type description
cfg.ProjectorId required The astra_mex_projector ID of the projector.
cfg.ProjectionDataId required The astra_mex_data2d ID of the projection data
cfg.ReconstructionDataId required The astra_mex_data2d ID of the reconstruction data. The content of this when starting SART is used as the initial reconstruction.
cfg.option.SinogramMaskId optional If specified, the astra_mex_data2d ID of a projection-data-sized volume to be used as a mask.
cfg.option.ReconstructionMaskId optional If specified, the astra_mex_data2d ID of a volume-data-sized volume to be used as a mask.
cfg.option.MinConstraint optional If specified, all values below MinConstraint will be set to MinConstraint. This can, for example, be used to enforce non-negative reconstructions.
cfg.option.MaxConstraint optional If specified, all values above MaxConstraint will be set to MaxConstraint.
cfg.option.ProjectionOrder optional This specifies the order in which the projections are used. Possible values are: ‘random’ (default), ‘sequential’, and ‘custom’. If ‘custom’ is specified, the option.ProjectionOrderList is required.
cfg.option.ProjectionOrderList optional Required if option.ProjectionOrder = ‘custom’, ignored otherwise. A matlab vector containing the custom order in which the projections are used.
cfg.option.GPUindex optional Specifies which GPU to use. Default = 0.
cfg.option.DetectorSuperSampling optional Specifies the amount of detector supersampling, i.e. how many rays are cast per detector.
cfg.option.PixelSuperSampling optional Specifiec the amount of pixel supersampling, i.e. how many (one dimension) subpixels are generated from a single parent pixel.
Example
%% create phantom
V_exact = phantom(256);

%% create geometries
proj_geom = astra_create_proj_geom('parallel', 1.0, 256, linspace2(0,pi,180));
vol_geom = astra_create_vol_geom(256,256);

%% create forward projection
[sinogram_id, sinogram] = astra_create_sino_cuda(V_exact, proj_geom, vol_geom);

%% reconstruct
recon_id = astra_mex_data2d('create', '-vol', vol_geom, 0);
cfg = astra_struct('SART_CUDA');
cfg.ProjectionDataId = sinogram_id;
cfg.ReconstructionDataId = recon_id;
cfg.option.ProjectionOrder = 'custom';
cfg.option.ProjectionOrderList = [0:5:175 1:5:176 2:5:177 3:5:178 4:5:179];
sart_id = astra_mex_algorithm('create', cfg);
astra_mex_algorithm('iterate', sart_id, 10*180);
V = astra_mex_data2d('get', recon_id);
imshow(V, []);

%% garbage disposal
astra_mex_data2d('delete', sinogram_id, recon_id);
astra_mex_algorithm('delete', sart_id);
CGLS_CUDA

This is a GPU implementation of the Conjugate Gradient Least Squares (CGLS) algorithm for 2D data sets. It takes projection data and an initial reconstruction as input, and returns the reconstruction after a specified number of SIRT iterations.

The internal state of the CGLS algorithm is reset every time astra_mex_algorithm(‘iterate’) is called. This implies that running CGLS for N iterations and then running it for another N iterations may yield different results from running it 2N iterations at once.

Supported geometries: parallel, fanflat, fanflat_vec.

Configuration options
name type description
cfg.ProjectionDataId required The astra_mex_data2d ID of the projection data
cfg.ReconstructionDataId required The astra_mex_data2d ID of the reconstruction data. The content of this when starting CGLS is used as the initial reconstruction.
cfg.option.SinogramMaskId optional If specified, the astra_mex_data2d ID of a projection-data-sized volume to be used as a mask.
cfg.option.ReconstructionMaskId optional If specified, the astra_mex_data2d ID of a volume-data-sized volume to be used as a mask.
cfg.option.GPUindex optional Specifies which GPU to use. Default = 0.
cfg.option.DetectorSuperSampling optional For the forward projection, DetectorSuperSampling rays will be used. This should only be used if your detector pixels are larger than the voxels in the reconstruction volume. Defaults to 1.
cfg.option.PixelSuperSampling optional For the backward projection, PixelSuperSampling^2 rays will be used. This should only be used if your voxels in the reconstruction volume are larger than the detector pixels. Defaults to 1.
Example
%% create phantom
V_exact = phantom(256);

%% create geometries
proj_geom = astra_create_proj_geom('parallel', 1.0, 256, linspace2(0,pi,180));
vol_geom = astra_create_vol_geom(256,256);

%% create forward projection
[sinogram_id, sinogram] = astra_create_sino_cuda(V_exact, proj_geom, vol_geom);

%% reconstruct
recon_id = astra_mex_data2d('create', '-vol', vol_geom, 0);
cfg = astra_struct('CGLS_CUDA');
cfg.ProjectionDataId = sinogram_id;
cfg.ReconstructionDataId = recon_id;
cgls_id = astra_mex_algorithm('create', cfg);
astra_mex_algorithm('iterate', cgls_id, 100);
V = astra_mex_data2d('get', recon_id);
imshow(V, []);

%% garbage disposal
astra_mex_data2d('delete', sinogram_id, recon_id);
astra_mex_algorithm('delete', cgls_id);
EM_CUDA
3D GPU Algorithms
FP3D_CUDA
BP3D_CUDA
FDK_CUDA

This is a GPU implementation of the FDK algorithm for 3D circular cone beam data sets.

It takes projection data as input, and returns the reconstruction.

Supported geometries: only cone. (cone_vec is not supported.)

Configuration options
name type description
cfg.ProjectionDataId required The astra_mex_data3d ID of the projection data
cfg.ReconstructionDataId required The astra_mex_data3d ID of the reconstruction data.
cfg.option.ShortScan optional If enabled, do Parker weighting to support non-360-degree data. This needs an angle range of at least 180 degrees plus twice the cone angle. (default: false)
cfg.option.GPUindex optional The index (zero-based) of the GPU to use. (default: 0)
cfg.option.VoxelSuperSampling optional For the backward projection, VoxelSuperSampling^3 rays will be used. This should only be used if your voxels in the reconstruction volume are larger than the detector pixels. (default: 1)
SIRT3D_CUDA

This is a GPU implementation of the SIRT algorithm for 3D data sets. It takes projection data and an initial reconstruction as input, and returns the reconstruction after a specified number of SIRT iterations.

Supported geometries: all 3D geometries.

Configuration options
name type description
cfg.ProjectionDataId required The astra_mex_data3d ID of the projection data
cfg.ReconstructionDataId required The astra_mex_data3d ID of the reconstruction data. The content of this when starting SIRT3D_CUDA is used as the initial reconstruction.
cfg.option.SinogramMaskId optional If specified, the astra_mex_data3d ID of a projection-data-sized volume to be used as a mask. It should only have values 0.0 and 1.0. See the section on [Masks] for details.
cfg.option.ReconstructionMaskId optional If specified, the astra_mex_data3d ID of a volume-data-sized volume to be used as a mask. It should only have values 0.0 and 1.0. See the section on [Masks] for details.
cfg.option.MinConstraint optional If specified, all values below MinConstraint will be set to MinConstraint. This can be used to enforce non-negative reconstructions, for example.
cfg.option.MaxConstraint optional If specified, all values above MaxConstraint will be set to MaxConstraint.
cfg.option.GPUindex optional The index (zero-based) of the GPU to use. (default: 0)
cfg.option.DetectorSuperSampling optional For the forward projection, DetectorSuperSampling^2 rays will be used. This should only be used if your detector pixels are larger than the voxels in the reconstruction volume. (default: 1)
cfg.option.VoxelSuperSampling optional For the backward projection, VoxelSuperSampling^3 rays will be used. This should only be used if your voxels in the reconstruction volume are larger than the detector pixels. (default: 1)
Extra features

SIRT3D_CUDA supports astra_mex_algorithm(‘get_res_norm’) to get the 2-norm of the difference between the projection data and the projection of the reconstruction. (The square root of the sum of squares of differences.)

CGLS3D_CUDA

This is a GPU implementation of the CGLS algorithm for 3D data sets. It takes projection data and an initial reconstruction as input, and returns the reconstruction after a specified number of CGLS iterations.

The internal state of the CGLS algorithm is reset every time astra_mex_algorithm(‘iterate’) is called. This implies that running CGLS for N iterations and then running it for another N iterations may yield different results from running it 2N iterations at once.

Supported geometries: all 3D geometries.

Configuration options
name type description
cfg.ProjectionDataId required The astra_mex_data3d ID of the projection data
cfg.ReconstructionDataId required The astra_mex_data3d ID of the reconstruction data. The content of this when starting SIRT3D_CUDA is used as the initial reconstruction.
cfg.option.ReconstructionMaskId optional If specified, the astra_mex_data3d ID of a volume-data-sized volume to be used as a mask. It should only have values 0.0 and 1.0. See the section on [Masks] for details.
cfg.option.GPUindex optional The index (zero-based) of the GPU to use. (default: 0)
cfg.option.DetectorSuperSampling optional For the forward projection, DetectorSuperSampling^2 rays will be used. This should only be used if your detector pixels are larger than the voxels in the reconstruction volume. (default: 1)
cfg.option.VoxelSuperSampling optional For the backward projection, VoxelSuperSampling^3 rays will be used. This should only be used if your voxels in the reconstruction volume are larger than the detector pixels. (default: 1)
Extra features

CGLS3D_CUDA supports astra_mex_algorithm(‘get_res_norm’) to get the 2-norm of the difference between the projection data and the projection of the reconstruction. (The square root of the sum of squares of differences.)

ASTRA utility scripts

astra_create_sino
id = astra_create_sino(data, projector_id);
[id, sinogram] = astra_create_sino(data, projector_id);

Compute a sinogram from a 2D volume using the given projector. See the documentation for astra_create_projector for details on projectors. The projector_id may be for either a CPU or a GPU/CUDA projector.

The input may either be an astra_mex_data2d id for a volume data object of the right volume geometry, or a matrix directly containing the object data. In the latter case, it must be of size (height,width) as defined in the volume geometry. It must be of class single, double or logical.

In its one output argument form, astra_create_sino returns a newly allocated astra_mex_data2d id containing the sinogram.

In its two output argument form, astra_create_sino additionally returns the sinogram itself.

astra_create_backprojection
id = astra_create_backprojection(data, projector_id);
[id, volume] = astra_create_backprojection(data, projector_id);

Compute a backprojection of a 2D sinogram using the given projector. See the documentation for astra_create_projector for details on projectors. The projector_id may be for either a CPU or a GPU/CUDA projector.

The input may either be an astra_mex_data2d id for a projection data object of the right projection geometry, or a matrix directly containing the sinogram. In the latter case, it must be of size (#angles, #detector pixels) as defined in the projection geometry. It must be of class single, double or logical.

In its one output argument form, astra_create_backprojection returns a newly allocated astra_mex_data2d id containing the volume.

In its two output argument form, astra_create_backprojection additionally returns the volume data itself.

astra_create_sino_cuda
id = astra_create_sino(data, proj_geom, vol_geom);
[id, sinogram] = astra_create_sino(data, proj_geom, vol_geom);

Compute a sinogram from a 2D volume and the given geometry, using a GPU.

The input may either be an astra_mex_data2d id for a volume data object of the right volume geometry, or a matrix directly containing the object data. In the latter case, it must be of size (height,width) as defined in the volume geometry. It must be of class single, double or logical.

In its one output argument form, astra_create_sino_cuda returns a newly allocated astra_mex_data2d id containing the sinogram.

In its two output argument form, astra_create_sino_cuda additionally returns the sinogram itself.

astra_create_backprojection_cuda
volume = astra_create_backprojection_cuda(data, proj_geom, vol_geom);

Compute a backprojection of a 2D sinogram and the given geometry, using a GPU.

The input may either be an astra_mex_data2d id for a projection data object of the right projection geometry, or a matrix directly containing the sinogram. In the latter case, it must be of size (#angles, #detector pixels) as defined in the projection geometry. It must be of class single, double or logical.

astra_create_backprojection returns the volume data in a matrix.

Note: as a historical accident, this function has a different return argument signature than the other astra_create_backprojection* functions.

astra_create_sino3d_cuda
id = astra_create_sino3d_cuda(data, proj_geom, vol_geom); [id, projdata] = astra_create_sino3d_cuda(data, proj_geom, vol_geom);

Compute projection data from a 3D volume and the given geometry, using a GPU.

The input may either be an astra_mex_data3d id for a volume data object of the right volume geometry, or a matrix directly containing the object data. In the latter case, it must be of size (x,y,z) as defined in the volume geometry. It must be of class single, double or logical.

In its one output argument form, astra_create_sino3d_cuda returns a newly allocated astra_mex_data3d id containing the projection data.

In its two output argument form, astra_create_sino3d_cuda additionally returns the projection data itself.

astra_create_backprojection3d_cuda
id = astra_create_backprojection3d_cuda(data, proj_geom, vol_geom);
[id, volume] = astra_create_backprojection(data, proj_geom, vol_geom);

Compute a backprojection of 3D projection data and the given geometry, using a GPU.

The input may either be an astra_mex_data3d id for a projection data object of the right projection geometry, or a matrix directly containing the projection data. In the latter case, it must be of size (u,#angles,v), where u is the number of columns of the detector and v the number of rows as defined in the projection geometry. It must be of class single, double or logical.

In its one output argument form, astra_create_backprojection3d_cuda returns a newly allocated astra_mex_data3d id containing the volume.

In its two output argument form, astra_create_backprojection3d_cuda additionally returns the volume data itself.

astra_geom_2vec
proj_geom_vec = astra_geom_2vec(proj_geom);

Convert a projection geometry of type fanflat, cone, or parallel3d into an equivalent geometry of type fanflat_vec, cone_vec, or parallel3d_vec, respectively.

astra_geom_size
s = astra_geom_size(geom);
s = astra_geom_size(geom, dim);

Get the size of Matlab arrays for data objects with a given geometry. All geometries (2D, 3D, volume, projection) are supported.

The size returned is the size needed for arrays passed to the astra_mex_data2d/3d ‘create’, ‘set’/’store’ and ‘link’ functions, as well as the size of arrays returned by astra_mex_data2d/3d ‘get’/’get_single’.

Miscellaneous

Masks

Various reconstruction algorithms support projection data and reconstruction volume masks. These behave as follows.

The projection data elements corresponding to locations with SinogramMask value 0.0 will be ignored during the reconstruction. Similarly, the reconstruction data elements corresponding to locations with ReconstructionMask value 0.0 will be ignored during the reconstruction, and their values will be preserved. (Mostly, see note on constraints below.)

The algorithm will behave as if the rows and columns corresponding to the masked voxels and projection data elements have been removed from the projection matrix entirely. In other words, it will iteratively try to match the projection of the non-masked voxels to the non-masked projection data elements.

NB: MinConstraint/MaxConstraint will affect even masked voxels.

astra_struct
cfg = astra_struct('NAME');

This is the basic script to create a configuration struct for many astra objects. The returned struct is usually filled with more options after creating it, and then passed to astra functions such as

id = astra_mex_algorithm('create', cfg);
id = astra_mex_projector('create', cfg);

The most common usage is for creating algorithm configuration structs. See the pages on [2D CPU Algorithms], [2D GPU Algorithms], [3D GPU Algorithms] for available algorithms, and the pages for the individual algorithms for the options they support.

astra_mex_matrix

astra_mex_matrix is used to manage sparse matrices. These can be created by the ASTRA toolbox itself to obtain explicit weight matrices (see [astra_mex_projector]), or you can create them yourself for use with the sparse_matrix projection geometry.

It is a wrapper around the MEX file astra_mex_matrix_c.

astra_mex_matrix contains the following commands:

  • create
  • get
  • get_size
  • store
  • delete
  • clear
  • info

create

id = astra_mex_matrix('create', S);

Create an ASTRA sparse matrix object from a Matlab sparse matrix. get

S = astra_mex_matrix('get', id);

Return an ASTRA sparse matrix object as a Matlab sparse matrix.

get_size

s = astra_mex_matrix('get_size', id);

Get the size (rows,columns) of the sparse matrix object.

store

astra_mex_matrix('store', id, S)

Store a new Matlab sparse matrix in an ASTRA sparse matrix object.

NB: This does not re-allocate memory: the number of rows and non-zero entries may not be larger than they were when the object was first created.

delete

astra_mex_matrix('delete', id)

Free a single sparse matrix.

clear

astra_mex_matrix('clear')

Free all sparse matrices.

info

astra_mex_matrix('info')

Print basic information about all allocated sparse matrix objects.

Python API reference

2D data objects: the data2d module

astra.data2d.change_geometry(i, geom)[source]

Change the geometry of a 2D object.

Parameters:
  • i (int) – ID of object.
  • geom (dict) – new geometry.
astra.data2d.clear()[source]

Clear all 2D data objects.

astra.data2d.create(datatype, geometry, data=None)[source]

Create a 2D object.

Parameters:
  • datatype (string) – Data object type, ‘-vol’ or ‘-sino’.
  • geometry (dict) – Volume or projection geometry.
  • data (float or numpy.ndarray) – Data to fill the constructed object with, either a scalar or array.
Returns:

int – the ID of the constructed object.

astra.data2d.delete(ids)[source]

Delete a 2D object.

Parameters:ids (int or list) – ID or list of ID’s to delete.
astra.data2d.get(i)[source]

Get a 2D object.

Parameters:i (int) – ID of object to get.
Returns:numpy.ndarray – The object data.
astra.data2d.get_geometry(i)[source]

Get the geometry of a 2D object.

Parameters:i (int) – ID of object.
Returns:dict – The geometry of object with ID i.
astra.data2d.get_shared(i)[source]

Get a 2D object with memory shared between the ASTRA toolbox and numpy array.

Parameters:i (int) – ID of object to get.
Returns:numpy.ndarray – The object data.
astra.data2d.get_single(i)[source]

Get a 2D object in single precision.

Parameters:i (int) – ID of object to get.
Returns:numpy.ndarray – The object data.
astra.data2d.info()[source]

Print info on 2D objects in memory.

Link a 2D numpy array with the toolbox.

Parameters:
  • datatype (string) – Data object type, ‘-vol’ or ‘-sino’.
  • geometry (dict) – Volume or projection geometry.
  • data (numpy.ndarray) – Numpy array to link
Returns:

int – the ID of the constructed object.

astra.data2d.store(i, data)[source]

Fill existing 2D object with data.

Parameters:
  • i (int) – ID of object to fill.
  • data (float or numpy.ndarray) – Data to fill the object with, either a scalar or array.

3D data objects: the data3d module

astra.data3d.change_geometry(i, geometry)[source]

Change the geometry of a 3D object.

Parameters:
  • i (int) – ID of object.
  • geometry (dict) – Volume or projection geometry.
astra.data3d.clear()[source]

Clear all 3D data objects.

astra.data3d.create(datatype, geometry, data=None)[source]

Create a 3D object.

Parameters:
  • datatype (string) – Data object type, ‘-vol’ or ‘-sino’.
  • geometry (dict) – Volume or projection geometry.
  • data (float or numpy.ndarray) – Data to fill the constructed object with, either a scalar or array.
Returns:

int – the ID of the constructed object.

astra.data3d.delete(ids)[source]

Delete a 2D object.

Parameters:ids (int or list) – ID or list of ID’s to delete.
astra.data3d.dimensions(i)[source]

Get dimensions of a 3D object.

Parameters:i (int) – ID of object.
Returns:tuple – dimensions of object with ID i.
astra.data3d.get(i)[source]

Get a 3D object.

Parameters:i (int) – ID of object to get.
Returns:numpy.ndarray – The object data.
astra.data3d.get_geometry(i)[source]

Get the geometry of a 3D object.

Parameters:i (int) – ID of object.
Returns:dict – The geometry of object with ID i.
astra.data3d.get_shared(i)[source]

Get a 3D object with memory shared between the ASTRA toolbox and numpy array.

Parameters:i (int) – ID of object to get.
Returns:numpy.ndarray – The object data.
astra.data3d.get_single(i)[source]

Get a 3D object in single precision.

Parameters:i (int) – ID of object to get.
Returns:numpy.ndarray – The object data.
astra.data3d.info()[source]

Print info on 3D objects in memory.

Link a 3D numpy array with the toolbox.

Parameters:
  • datatype (string) – Data object type, ‘-vol’ or ‘-sino’.
  • geometry (dict) – Volume or projection geometry.
  • data (numpy.ndarray) – Numpy array to link
Returns:

int – the ID of the constructed object.

astra.data3d.store(i, data)[source]

Fill existing 3D object with data.

Parameters:
  • i (int) – ID of object to fill.
  • data (float or numpy.ndarray) – Data to fill the object with, either a scalar or array.

Projector object: the projector module

astra.projector.clear()[source]

Clear all projector objects.

astra.projector.create(config)[source]

Create projector object.

Parameters:config (dict) – Projector options.
Returns:int – the ID of the constructed object.
astra.projector.delete(ids)[source]

Delete a projector object.

Parameters:ids (int or list) – ID or list of ID’s to delete.
astra.projector.info()[source]

Print info on projector objects in memory.

astra.projector.is_cuda(i)[source]

Check whether a projector is a CUDA projector.

Parameters:i (int) – ID of projector.
Returns:bool – True if the projector is a CUDA projector.
astra.projector.matrix(i)[source]

Get sparse matrix of a projector.

Parameters:i (int) – ID of projector.
Returns:int – ID of sparse matrix.
astra.projector.projection_geometry(i)[source]

Get projection geometry of a projector.

Parameters:i (int) – ID of projector.
Returns:dict – projection geometry
astra.projector.splat(i, row, col)[source]
astra.projector.volume_geometry(i)[source]

Get volume geometry of a projector.

Parameters:i (int) – ID of projector.
Returns:dict – volume geometry
astra.projector.weights_projection(i, projection_index)[source]
astra.projector.weights_single_ray(i, projection_index, detector_index)[source]

Algorithms: the algorithm module

astra.algorithm.clear()[source]

Clear all matrix objects.

astra.algorithm.create(config)[source]

Create algorithm object.

Parameters:config (dict) – Algorithm options.
Returns:int – the ID of the constructed object.
astra.algorithm.delete(ids)[source]

Delete a matrix object.

Parameters:ids (int or list) – ID or list of ID’s to delete.
astra.algorithm.get_res_norm(i)[source]

Get residual norm of algorithm.

Parameters:i (int) – ID of object.
Returns:float – The residual norm.
astra.algorithm.info()[source]

Print info on matrix objects in memory.

astra.algorithm.run(i, iterations=1)[source]

Run an algorithm.

Parameters:
  • i (int) – ID of object.
  • iterations (int) – Number of iterations to run.

Sparse matrices: the matrix module

astra.matrix.clear()[source]

Clear all matrix objects.

astra.matrix.create(data)[source]

Create matrix object with data.

Parameters:data (scipy.sparse.csr_matrix) – Data to fill the created object with.
Returns:int – the ID of the constructed object.
astra.matrix.delete(ids)[source]

Delete a matrix object.

Parameters:ids (int or list) – ID or list of ID’s to delete.
astra.matrix.get(i)[source]

Get a matrix object.

Parameters:i (int) – ID of object to get.
Returns:scipy.sparse.csr_matrix – The object data.
astra.matrix.get_size(i)[source]

Get matrix dimensions.

Parameters:i (int) – ID of object.
Returns:tuple – matrix dimensions.
astra.matrix.info()[source]

Print info on matrix objects in memory.

astra.matrix.store(i, data)[source]

Fill existing matrix object with data.

Parameters:
  • i (int) – ID of object to fill.
  • data (scipy.sparse.csr_matrix) – Data to fill the object with.

Creation of objects: the creators module

astra.creators.astra_dict(intype)[source]

Creates a dict to use with the ASTRA Toolbox.

Parameters:intype (string) – Type of the ASTRA object.
Returns:dict – An ASTRA dict of type intype.
astra.creators.create_backprojection(data, proj_id, returnData=True)[source]

Create a backprojection of a sinogram (2D).

Parameters:
  • data (numpy.ndarray or int) – Sinogram data or ID.
  • proj_id (int) – ID of the projector to use.
  • returnData (bool) – If False, only return the ID of the backprojection.
Returns:

int or (int, numpy.ndarray) – If returnData=False, returns the ID of the backprojection. Otherwise, returns a tuple containing the ID of the backprojection and the backprojection itself, in that order.

astra.creators.create_backprojection3d_gpu(data, proj_geom, vol_geom, returnData=True)[source]

Create a backprojection of a sinogram (3D) using CUDA.

Parameters:
  • data (numpy.ndarray or int) – Sinogram data or ID.
  • proj_geom (dict) – Projection geometry.
  • vol_geom (dict) – Volume geometry.
  • returnData (bool) – If False, only return the ID of the backprojection.
Returns:

int or (int, numpy.ndarray) – If returnData=False, returns the ID of the backprojection. Otherwise, returns a tuple containing the ID of the backprojection and the backprojection itself, in that order.

astra.creators.create_proj_geom(intype, *args)[source]

Create a projection geometry.

This method can be called in a number of ways:

create_proj_geom('parallel', detector_spacing, det_count, angles):

Parameters:
  • detector_spacing (float) – Distance between two adjacent detector pixels.
  • det_count (int) – Number of detector pixels.
  • angles (numpy.ndarray) – Array of angles in radians.
Returns:

A parallel projection geometry.

create_proj_geom('fanflat', det_width, det_count, angles, source_origin, origin_det):

Parameters:
  • det_width (float) – Size of a detector pixel.
  • det_count (int) – Number of detector pixels.
  • angles (numpy.ndarray) – Array of angles in radians.
  • source_origin – Position of the source.
  • origin_det – Position of the detector
Returns:

A fan-beam projection geometry.

create_proj_geom('fanflat_vec', det_count, V):

Parameters:
  • det_count (int) – Number of detector pixels.
  • V (numpy.ndarray) – Vector array.
Returns:

A fan-beam projection geometry.

create_proj_geom('parallel3d', detector_spacing_x, detector_spacing_y, det_row_count, det_col_count, angles):

Parameters:
  • detector_spacing_* (float) – Distance between two adjacent detector pixels.
  • det_row_count (int) – Number of detector pixel rows.
  • det_col_count (int) – Number of detector pixel columns.
  • angles (numpy.ndarray) – Array of angles in radians.
Returns:

A parallel projection geometry.

create_proj_geom('cone', detector_spacing_x, detector_spacing_y, det_row_count, det_col_count, angles, source_origin, origin_det):

Parameters:
  • detector_spacing_* (float) – Distance between two adjacent detector pixels.
  • det_row_count (int) – Number of detector pixel rows.
  • det_col_count (int) – Number of detector pixel columns.
  • angles (numpy.ndarray) – Array of angles in radians.
  • source_origin (float) – Distance between point source and origin.
  • origin_det (float) – Distance between the detector and origin.
Returns:

A cone-beam projection geometry.

create_proj_geom('cone_vec', det_row_count, det_col_count, V):

Parameters:
  • det_row_count (int) – Number of detector pixel rows.
  • det_col_count (int) – Number of detector pixel columns.
  • V (numpy.ndarray) – Vector array.
Returns:

A cone-beam projection geometry.

create_proj_geom('parallel3d_vec', det_row_count, det_col_count, V):

Parameters:
  • det_row_count (int) – Number of detector pixel rows.
  • det_col_count (int) – Number of detector pixel columns.
  • V (numpy.ndarray) – Vector array.
Returns:

A parallel projection geometry.

create_proj_geom('sparse_matrix', det_width, det_count, angles, matrix_id):

Parameters:
  • det_width (float) – Size of a detector pixel.
  • det_count (int) – Number of detector pixels.
  • angles (numpy.ndarray) – Array of angles in radians.
  • matrix_id (int) – ID of the sparse matrix.
Returns:

A projection geometry based on a sparse matrix.

astra.creators.create_projector(proj_type, proj_geom, vol_geom)[source]

Create a 2D projector.

Parameters:
  • proj_type (string) – Projector type, such as 'line', 'linear', ...
  • proj_geom (dict) – Projection geometry.
  • vol_geom (dict) – Volume geometry.
Returns:

int – The ID of the projector.

astra.creators.create_reconstruction(rec_type, proj_id, sinogram, iterations=1, use_mask='no', mask=array([], dtype=float64), use_minc='no', minc=0, use_maxc='no', maxc=255, returnData=True, filterType=None, filterData=None)[source]

Create a reconstruction of a sinogram (2D).

Parameters:
  • rec_type (string) – Name of the reconstruction algorithm.
  • proj_id (int) – ID of the projector to use.
  • sinogram (numpy.ndarray or int) – Sinogram data or ID.
  • iterations (int) – Number of iterations to run.
  • use_mask ('yes' or 'no') – Whether to use a mask.
  • mask (numpy.ndarray or int) – Mask data or ID
  • use_minc ('yes' or 'no') – Whether to force a minimum value on the reconstruction pixels.
  • minc (float) – Minimum value to use.
  • use_maxc ('yes' or 'no') – Whether to force a maximum value on the reconstruction pixels.
  • maxc (float) – Maximum value to use.
  • returnData (bool) – If False, only return the ID of the reconstruction.
  • filterType (string) – Which type of filter to use for filter-based methods.
  • filterData (numpy.ndarray) – Optional filter data for filter-based methods.
Returns:

int or (int, numpy.ndarray) – If returnData=False, returns the ID of the reconstruction. Otherwise, returns a tuple containing the ID of the reconstruction and reconstruction itself, in that order.

astra.creators.create_sino(data, proj_id, returnData=True, gpuIndex=None)[source]

Create a forward projection of an image (2D).

Parameters:
  • data (numpy.ndarray or int) – Image data or ID.
  • proj_id (int) – ID of the projector to use.
  • returnData (bool) – If False, only return the ID of the forward projection.
  • gpuIndex (int) – Optional GPU index.
Returns:

int or (int, numpy.ndarray)

If returnData=False, returns the ID of the forward projection. Otherwise, returns a tuple containing the ID of the forward projection and the forward projection itself, in that order.

astra.creators.create_sino3d_gpu(data, proj_geom, vol_geom, returnData=True, gpuIndex=None)[source]

Create a forward projection of an image (3D).

Parameters:
  • data (numpy.ndarray or int) – Image data or ID.
  • proj_geom (dict) – Projection geometry.
  • vol_geom (dict) – Volume geometry.
  • returnData (bool) – If False, only return the ID of the forward projection.
  • gpuIndex (int) – Optional GPU index.
Returns:

int or (int, numpy.ndarray) – If returnData=False, returns the ID of the forward projection. Otherwise, returns a tuple containing the ID of the forward projection and the forward projection itself, in that order.

astra.creators.create_vol_geom(*varargin)[source]

Create a volume geometry structure.

This method can be called in a number of ways:

create_vol_geom(N):
returns:A 2D volume geometry of size \(N \times N\).
create_vol_geom((Y, X)):
returns:A 2D volume geometry of size \(Y \times X\).
create_vol_geom(Y, X):
returns:A 2D volume geometry of size \(Y \times X\).
create_vol_geom(Y, X, minx, maxx, miny, maxy):
returns:A 2D volume geometry of size \(Y \times X\), windowed as \(minx \leq x \leq maxx\) and \(miny \leq y \leq maxy\).
create_vol_geom((Y, X, Z)):
returns:A 3D volume geometry of size \(Y \times X \times Z\).
create_vol_geom(Y, X, Z):
returns:A 3D volume geometry of size \(Y \times X \times Z\).
create_vol_geom(Y, X, Z, minx, maxx, miny, maxy, minz, maxz):
returns:A 3D volume geometry of size \(Y \times X \times Z\), windowed as \(minx \leq x \leq maxx\) and \(miny \leq y \leq maxy\) and \(minz \leq z \leq maxz\) .

Additional functions: the functions module

Additional functions for PyAstraToolbox.

astra.functions.add_noise_to_sino(sinogram_in, I0, seed=None)[source]

Adds Poisson noise to a sinogram.

Parameters:
  • sinogram_in (numpy.ndarray) – Sinogram to add noise to.
  • I0 (float) – Background intensity. Lower values lead to higher noise.
Returns:

numpy.ndarray – the sinogram with added noise.

astra.functions.clear()[source]

Clears all used memory of the ASTRA Toolbox.

Note

This is irreversible.

astra.functions.data_op(op, data, scalar, gpu_core, mask=None)[source]

Perform data operation on data.

Parameters:
  • op – Operation to perform.
  • data – Data to perform operation on.
  • scalar – Scalar argument to data operation.
  • gpu_core – GPU core to perform operation on.
  • mask – Optional mask.
astra.functions.geom_2vec(proj_geom)[source]

Returns a vector-based projection geometry from a basic projection geometry.

Parameters:proj_geom (dict) – Projection geometry to convert
astra.functions.geom_size(geom, dim=None)[source]

Returns the size of a volume or sinogram, based on the projection or volume geometry.

Parameters:
  • geom – Geometry to calculate size from
  • dim (int) – Optional axis index to return
astra.functions.move_vol_geom(geom, pos, is_relative=False)[source]

Moves center of volume geometry to new position.

Parameters:
  • geom (dict) – Input volume geometry
  • pos (tuple) – Tuple (x,y[,z]) for new position, with the center of the image at (0,0[,0])
  • is_relative (bool) – Whether new position is relative to the old position
Returns:

dict – Volume geometry with the new center

OpTomo class: the optomo module

class astra.optomo.OpTomo(proj_id)[source]

Bases: scipy.sparse.linalg.interface.LinearOperator

Object that imitates a projection matrix with a given projector.

This object can do forward projection by using the * operator:

W = astra.OpTomo(proj_id)
fp = W*image
bp = W.T*sinogram

It can also be used in minimization methods of the scipy.sparse.linalg module:

W = astra.OpTomo(proj_id)
output = scipy.sparse.linalg.lsqr(W,sinogram)
Parameters:proj_id (int) – ID to a projector.
reconstruct(method, s, iterations=1, extraOptions={})[source]

Reconstruct an object.

Parameters:
  • method (string) – Method to use for reconstruction.
  • s (numpy.ndarray) – The projection data.
  • iterations (int) – Number of iterations to use.
  • extraOptions (dict) – Extra options to use during reconstruction (i.e. for cfg[‘option’]).
rmatvec(s)[source]

Implements the transpose operator.

Parameters:s (numpy.ndarray) – The projection data.
class astra.optomo.OpTomoTranspose(parent)[source]

Bases: scipy.sparse.linalg.interface.LinearOperator

This object provides the transpose operation (.T) of the OpTomo object.

Do not use directly, since it can be accessed as member .T of an OpTomo object.

rmatvec(v)[source]

Plugins: the plugin module

class astra.plugin.ReconstructionAlgorithm2D[source]

Bases: astra.plugin.base

astra_init(cfg)[source]
class astra.plugin.ReconstructionAlgorithm3D[source]

Bases: astra.plugin.base

astra_init(cfg)[source]
class astra.plugin.base[source]

Bases: object

astra_init(cfg)[source]
astra.plugin.get_help(name)[source]

Get help for registered plugin.

Parameters:name (str) – Plugin name to get help for
Returns:str – Help string (docstring).
astra.plugin.get_registered()[source]

Get dictionary of registered plugins.

Returns:dict – Registered plugins.
astra.plugin.register(className)[source]

Register plugin with ASTRA.

Parameters:className (str or class) – Class name or class object to register

MATLAB compatibility interface: the matlab module

This module implements a MATLAB-like interface to the ASTRA Toolbox.

Note that all functions are called with a string as the first argument, specifying the operation to perform. This un-pythonic way is used to make transitioning from MATLAB code to Python code easier, as the MATLAB interface uses the same type of method calling.

After an initial import astra, these functions can be accessed in the astra.m module.

astra.matlab.algorithm(command, *args)[source]

MATLAB-like interface to the astra.algorithm module

For example:

astra.m.algorithm('run',i,1000) – Run an algorithm with 1000 iterations.

astra.matlab.astra(command, *args)[source]

MATLAB-like interface to the astra.astra module

For example:

astra.m.astra('use_cuda') – Check if CUDA is enabled.

astra.matlab.data2d(command, *args)[source]

MATLAB-like interface to the astra.data2d module

For example:

astra.m.data2d('create',type,geometry,data) – Create a 2D object.

astra.matlab.data3d(command, *args)[source]

MATLAB-like interface to the astra.data3d module

For example:

astra.m.data3d('get',i) – Get 3D object data.

astra.matlab.matrix(command, *args)[source]

MATLAB-like interface to the astra.matrix module

For example:

astra.m.matrix('delete',i) – Delete a matrix.

astra.matlab.projector(command, *args)[source]

MATLAB-like interface to the astra.projector module

For example:

astra.m.projector('volume_geometry',i) – Get volume geometry.

Additional ASTRA methods: the astra module

astra.astra.credits()[source]

Print credits of the ASTRA Toolbox.

astra.astra.set_gpu_index(idx)[source]

Set default GPU index to use.

Parameters:idx (int) – GPU index
astra.astra.use_cuda()[source]

Test if CUDA is enabled.

Returns:boolTrue if CUDA is enabled.
astra.astra.version(printToScreen=False)[source]

Check version of the ASTRA Toolbox.

Parameters:printToScreen (bool) – If True, print version string. If False, return version integer.
Returns:string or int – The version string or integer.

Indices and tables