Skip to content

Commit 74e87d7

Browse files
committed
Initial commit
1 parent 57dff27 commit 74e87d7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+6101
-0
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
build/
2+
dist/
3+
docSRC/_build/
4+
5+
*.c
6+
*.cpp
7+
*.so
8+
*.pyc

COPYING

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

INSTALL

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#-----------------------------------------------------------------------
2+
#Copyright 2013 Centrum Wiskunde & Informatica, Amsterdam
3+
#
4+
#Author: Daniel M. Pelt
5+
6+
#Website: http://dmpelt.github.io/pyastratoolbox/
7+
#
8+
#
9+
#This file is part of the Python interface to the
10+
#All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA Toolbox").
11+
#
12+
#The Python interface to the ASTRA Toolbox is free software: you can redistribute it and/or modify
13+
#it under the terms of the GNU General Public License as published by
14+
#the Free Software Foundation, either version 3 of the License, or
15+
#(at your option) any later version.
16+
#
17+
#The Python interface to the ASTRA Toolbox is distributed in the hope that it will be useful,
18+
#but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
#GNU General Public License for more details.
21+
#
22+
#You should have received a copy of the GNU General Public License
23+
#along with the Python interface to the ASTRA Toolbox. If not, see <http://www.gnu.org/licenses/>.
24+
#
25+
#-----------------------------------------------------------------------
26+
27+
To use the Python interface, you need the All Scale Tomographic Reconstruction Antwerp Toolbox:
28+
https://code.google.com/p/astra-toolbox/
29+
Please install the ASTRA toolbox first.
30+
31+
Other requirements: Cython (version >= 0.13), NumPy
32+
33+
Use install.sh to install the Python interface to the ASTRA toolbox.
34+
Only run install.sh as ./install.sh in the base directory of the interface code.
35+
You need write permission to the $PYTHON_PATH directory.
36+
We recommend using a Python virtualenv if root access is impossible.
37+
The Python interface to the ASTRA Toolbox uses Python version 2.
38+
39+
Usage: ./install.sh [-i astra_include_path] [-l astra_library_path] [-p python_executable_path] [-c cuda_path]
40+
41+
-i astra_include_path: specify path to astra header files (without trailing astra/) (Optional)
42+
-l astra_library_path: specify parent path of astra library file (Optional)
43+
-p python_executable_path: specify path to python executable (Optional)
44+
-c cuda_path: path to CUDA (Optional)
45+
-h: print this help (Optional)
46+
47+
Note that the paths only have to be specified if they are not already in your $LD_LIBRARY_PATH, etcetera.
48+
49+
When compiling with CUDA, the astra_include_path should be set to the 'include' directory of the ASTRA toolbox
50+
source.

LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
COPYING

MANIFEST

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# file GENERATED by distutils, do NOT edit
2+
COPYING
3+
INSTALL
4+
README
5+
builder.py
6+
install.sh
7+
astra/ASTRAProjector.py
8+
astra/PyAlgorithmFactory.pxd
9+
astra/PyAlgorithmManager.pxd
10+
astra/PyData2DManager.pxd
11+
astra/PyData3DManager.pxd
12+
astra/PyIncludes.pxd
13+
astra/PyMatrixManager.pxd
14+
astra/PyProjector2DFactory.pxd
15+
astra/PyProjector2DManager.pxd
16+
astra/PyXMLDocument.pxd
17+
astra/__init__.py
18+
astra/algorithm.py
19+
astra/algorithm_c.cpp
20+
astra/algorithm_c.pyx
21+
astra/astra.py
22+
astra/astra_c.cpp
23+
astra/astra_c.pyx
24+
astra/creators.py
25+
astra/data2d.py
26+
astra/data2d_c.cpp
27+
astra/data2d_c.pyx
28+
astra/data3d.py
29+
astra/data3d_c.cpp
30+
astra/data3d_c.pyx
31+
astra/extrautils.c
32+
astra/extrautils.pyx
33+
astra/functions.py
34+
astra/matlab.py
35+
astra/matrix.py
36+
astra/matrix_c.cpp
37+
astra/matrix_c.pyx
38+
astra/projector.py
39+
astra/projector_c.cpp
40+
astra/projector_c.pyx
41+
astra/utils.cpp
42+
astra/utils.pxd
43+
astra/utils.pyx
44+
doc/.buildinfo
45+
doc/ASTRAProjector.html
46+
doc/algorithm.html
47+
doc/creators.html
48+
doc/data2d.html
49+
doc/data3d.html
50+
doc/functions.html
51+
doc/genindex.html
52+
doc/index.html
53+
doc/matlab.html
54+
doc/matrix.html
55+
doc/objects.inv
56+
doc/projector.html
57+
doc/py-modindex.html
58+
doc/search.html
59+
doc/searchindex.js
60+
doc/_modules/index.html
61+
doc/_modules/astra/ASTRAProjector.html
62+
doc/_modules/astra/algorithm.html
63+
doc/_modules/astra/creators.html
64+
doc/_modules/astra/data2d.html
65+
doc/_modules/astra/data3d.html
66+
doc/_modules/astra/functions.html
67+
doc/_modules/astra/matlab.html
68+
doc/_modules/astra/matrix.html
69+
doc/_modules/astra/projector.html
70+
doc/_sources/ASTRAProjector.txt
71+
doc/_sources/algorithm.txt
72+
doc/_sources/creators.txt
73+
doc/_sources/data2d.txt
74+
doc/_sources/data3d.txt
75+
doc/_sources/functions.txt
76+
doc/_sources/index.txt
77+
doc/_sources/matlab.txt
78+
doc/_sources/matrix.txt
79+
doc/_sources/projector.txt
80+
doc/_static/ajax-loader.gif
81+
doc/_static/basic.css
82+
doc/_static/comment-bright.png
83+
doc/_static/comment-close.png
84+
doc/_static/comment.png
85+
doc/_static/default.css
86+
doc/_static/doctools.js
87+
doc/_static/down-pressed.png
88+
doc/_static/down.png
89+
doc/_static/file.png
90+
doc/_static/jquery.js
91+
doc/_static/minus.png
92+
doc/_static/plus.png
93+
doc/_static/pygments.css
94+
doc/_static/searchtools.js
95+
doc/_static/sidebar.js
96+
doc/_static/underscore.js
97+
doc/_static/up-pressed.png
98+
doc/_static/up.png
99+
doc/_static/websupport.js
100+
examples/phantom.mat
101+
examples/s001_sinogram_par2d.py
102+
examples/s002_data2d.py
103+
examples/s003_gpu_reconstruction.py
104+
examples/s004_cpu_reconstruction.py
105+
examples/s005_3d_geometry.py
106+
examples/s006_3d_data.py
107+
examples/s007_3d_reconstruction.py
108+
examples/s008_gpu_selection.py
109+
examples/s009_projection_matrix.py
110+
examples/s010_supersampling.py
111+
examples/s011_object_info.py
112+
examples/s012_masks.py
113+
examples/s013_constraints.py
114+
examples/s014_FBP.py
115+
examples/s015_fp_bp.py
116+
examples/s016_plots.py

MANIFEST.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
include INSTALL
2+
include COPYING
3+
include install.sh
4+
recursive-include examples *.py *.mat
5+
recursive-include astra *.pyx *.pxd
6+
recursive-include doc *
7+

README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
INSTALL

astra/ASTRAProjector.py

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
#-----------------------------------------------------------------------
2+
#Copyright 2013 Centrum Wiskunde & Informatica, Amsterdam
3+
#
4+
#Author: Daniel M. Pelt
5+
6+
#Website: http://dmpelt.github.io/pyastratoolbox/
7+
#
8+
#
9+
#This file is part of the Python interface to the
10+
#All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA Toolbox").
11+
#
12+
#The Python interface to the ASTRA Toolbox is free software: you can redistribute it and/or modify
13+
#it under the terms of the GNU General Public License as published by
14+
#the Free Software Foundation, either version 3 of the License, or
15+
#(at your option) any later version.
16+
#
17+
#The Python interface to the ASTRA Toolbox is distributed in the hope that it will be useful,
18+
#but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
#GNU General Public License for more details.
21+
#
22+
#You should have received a copy of the GNU General Public License
23+
#along with the Python interface to the ASTRA Toolbox. If not, see <http://www.gnu.org/licenses/>.
24+
#
25+
#-----------------------------------------------------------------------
26+
27+
28+
import creators as ac
29+
import math
30+
import data2d
31+
32+
33+
class ASTRAProjector2DTranspose():
34+
"""Implements the ``proj.T`` functionality.
35+
36+
Do not use directly, since it can be accessed as member ``.T`` of
37+
an :class:`ASTRAProjector2D` object.
38+
39+
"""
40+
def __init__(self, parentProj):
41+
self.parentProj = parentProj
42+
43+
def __mul__(self, data):
44+
return self.parentProj.backProject(data)
45+
46+
47+
class ASTRAProjector2D(object):
48+
"""Helps with various common ASTRA Toolbox 2D operations.
49+
50+
This class can perform several often used toolbox operations, such as:
51+
52+
* Forward projecting
53+
* Back projecting
54+
* Reconstructing
55+
56+
Note that this class has a some computational overhead, because it
57+
copies a lot of data. If you use many repeated operations, directly
58+
using the PyAstraToolbox methods directly is faster.
59+
60+
You can use this class as an abstracted weight matrix :math:`W`: multiplying an instance
61+
``proj`` of this class by an image results in a forward projection of the image, and multiplying
62+
``proj.T`` by a sinogram results in a backprojection of the sinogram::
63+
64+
proj = ASTRAProjector2D(...)
65+
fp = proj*image
66+
bp = proj.T*sinogram
67+
68+
:param proj_geom: The projection geometry.
69+
:type proj_geom: :class:`dict`
70+
:param vol_geom: The volume geometry.
71+
:type vol_geom: :class:`dict`
72+
:param proj_type: Projector type, such as ``'line'``, ``'linear'``, ...
73+
:type proj_type: :class:`string`
74+
:param useCUDA: If ``True``, use CUDA for calculations, when possible.
75+
:type useCUDA: :class:`bool`
76+
"""
77+
78+
def __init__(self, proj_geom, vol_geom, proj_type, useCUDA=False):
79+
self.vol_geom = vol_geom
80+
self.recSize = vol_geom['GridColCount']
81+
self.angles = proj_geom['ProjectionAngles']
82+
self.nDet = proj_geom['DetectorCount']
83+
nexpow = int(pow(2, math.ceil(math.log(2 * self.nDet, 2))))
84+
self.filterSize = nexpow / 2 + 1
85+
self.nProj = self.angles.shape[0]
86+
self.proj_geom = proj_geom
87+
self.proj_id = ac.create_projector(proj_type, proj_geom, vol_geom)
88+
self.useCUDA = useCUDA
89+
self.T = ASTRAProjector2DTranspose(self)
90+
91+
def backProject(self, data):
92+
"""Backproject a sinogram.
93+
94+
:param data: The sinogram data or ID.
95+
:type data: :class:`numpy.ndarray` or :class:`int`
96+
:returns: :class:`numpy.ndarray` -- The backprojection.
97+
98+
"""
99+
vol_id, vol = ac.create_backprojection(
100+
data, self.proj_id, self.useCUDA, True)
101+
data2d.delete(vol_id)
102+
return vol
103+
104+
def forwardProject(self, data):
105+
"""Forward project an image.
106+
107+
:param data: The image data or ID.
108+
:type data: :class:`numpy.ndarray` or :class:`int`
109+
:returns: :class:`numpy.ndarray` -- The forward projection.
110+
111+
"""
112+
sin_id, sino = ac.create_sino(data, self.proj_id, self.useCUDA, True)
113+
data2d.delete(sin_id)
114+
return sino
115+
116+
def reconstruct(self, data, method, **kwargs):
117+
"""Reconstruct an image from a sinogram.
118+
119+
:param data: The sinogram data or ID.
120+
:type data: :class:`numpy.ndarray` or :class:`int`
121+
:param method: Name of the reconstruction algorithm.
122+
:type method: :class:`string`
123+
:param kwargs: Additional named parameters to pass to :func:`astra.creators.create_reconstruction`.
124+
:returns: :class:`numpy.ndarray` -- The reconstruction.
125+
126+
Example of a SIRT reconstruction using CUDA::
127+
128+
proj = ASTRAProjector2D(...)
129+
rec = proj.reconstruct(sinogram,'SIRT_CUDA',iterations=1000)
130+
131+
"""
132+
kwargs['returnData'] = True
133+
rec_id, rec = ac.create_reconstruction(
134+
method, self.proj_id, data, **kwargs)
135+
data2d.delete(rec_id)
136+
return rec
137+
138+
def __mul__(self, data):
139+
return self.forwardProject(data)

astra/PyAlgorithmFactory.pxd

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#-----------------------------------------------------------------------
2+
#Copyright 2013 Centrum Wiskunde & Informatica, Amsterdam
3+
#
4+
#Author: Daniel M. Pelt
5+
6+
#Website: http://dmpelt.github.io/pyastratoolbox/
7+
#
8+
#
9+
#This file is part of the Python interface to the
10+
#All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA Toolbox").
11+
#
12+
#The Python interface to the ASTRA Toolbox is free software: you can redistribute it and/or modify
13+
#it under the terms of the GNU General Public License as published by
14+
#the Free Software Foundation, either version 3 of the License, or
15+
#(at your option) any later version.
16+
#
17+
#The Python interface to the ASTRA Toolbox is distributed in the hope that it will be useful,
18+
#but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
#GNU General Public License for more details.
21+
#
22+
#You should have received a copy of the GNU General Public License
23+
#along with the Python interface to the ASTRA Toolbox. If not, see <http://www.gnu.org/licenses/>.
24+
#
25+
#-----------------------------------------------------------------------
26+
from libcpp.string cimport string
27+
from libcpp cimport bool
28+
from PyIncludes cimport *
29+
30+
cdef extern from "astra/AstraObjectFactory.h" namespace "astra":
31+
cdef cppclass CAlgorithmFactory:
32+
CAlgorithmFactory()
33+
CAlgorithm *create(string)
34+
35+
cdef extern from "astra/AstraObjectFactory.h" namespace "astra::CAlgorithmFactory":
36+
cdef CAlgorithmFactory* getSingletonPtr()

0 commit comments

Comments
 (0)