forked from dmpelt/pyastratoolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
70 changed files
with
6,101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
build/ | ||
dist/ | ||
docSRC/_build/ | ||
|
||
*.c | ||
*.cpp | ||
*.so | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#----------------------------------------------------------------------- | ||
#Copyright 2013 Centrum Wiskunde & Informatica, Amsterdam | ||
# | ||
#Author: Daniel M. Pelt | ||
#Contact: [email protected] | ||
#Website: http://dmpelt.github.io/pyastratoolbox/ | ||
# | ||
# | ||
#This file is part of the Python interface to the | ||
#All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA Toolbox"). | ||
# | ||
#The Python interface to the ASTRA Toolbox is free software: you can redistribute it and/or modify | ||
#it under the terms of the GNU General Public License as published by | ||
#the Free Software Foundation, either version 3 of the License, or | ||
#(at your option) any later version. | ||
# | ||
#The Python interface to the ASTRA Toolbox is distributed in the hope that it will be useful, | ||
#but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
#GNU General Public License for more details. | ||
# | ||
#You should have received a copy of the GNU General Public License | ||
#along with the Python interface to the ASTRA Toolbox. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
#----------------------------------------------------------------------- | ||
|
||
To use the Python interface, you need the All Scale Tomographic Reconstruction Antwerp Toolbox: | ||
https://code.google.com/p/astra-toolbox/ | ||
Please install the ASTRA toolbox first. | ||
|
||
Other requirements: Cython (version >= 0.13), NumPy | ||
|
||
Use install.sh to install the Python interface to the ASTRA toolbox. | ||
Only run install.sh as ./install.sh in the base directory of the interface code. | ||
You need write permission to the $PYTHON_PATH directory. | ||
We recommend using a Python virtualenv if root access is impossible. | ||
The Python interface to the ASTRA Toolbox uses Python version 2. | ||
|
||
Usage: ./install.sh [-i astra_include_path] [-l astra_library_path] [-p python_executable_path] [-c cuda_path] | ||
|
||
-i astra_include_path: specify path to astra header files (without trailing astra/) (Optional) | ||
-l astra_library_path: specify parent path of astra library file (Optional) | ||
-p python_executable_path: specify path to python executable (Optional) | ||
-c cuda_path: path to CUDA (Optional) | ||
-h: print this help (Optional) | ||
|
||
Note that the paths only have to be specified if they are not already in your $LD_LIBRARY_PATH, etcetera. | ||
|
||
When compiling with CUDA, the astra_include_path should be set to the 'include' directory of the ASTRA toolbox | ||
source. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
COPYING |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
# file GENERATED by distutils, do NOT edit | ||
COPYING | ||
INSTALL | ||
README | ||
builder.py | ||
install.sh | ||
astra/ASTRAProjector.py | ||
astra/PyAlgorithmFactory.pxd | ||
astra/PyAlgorithmManager.pxd | ||
astra/PyData2DManager.pxd | ||
astra/PyData3DManager.pxd | ||
astra/PyIncludes.pxd | ||
astra/PyMatrixManager.pxd | ||
astra/PyProjector2DFactory.pxd | ||
astra/PyProjector2DManager.pxd | ||
astra/PyXMLDocument.pxd | ||
astra/__init__.py | ||
astra/algorithm.py | ||
astra/algorithm_c.cpp | ||
astra/algorithm_c.pyx | ||
astra/astra.py | ||
astra/astra_c.cpp | ||
astra/astra_c.pyx | ||
astra/creators.py | ||
astra/data2d.py | ||
astra/data2d_c.cpp | ||
astra/data2d_c.pyx | ||
astra/data3d.py | ||
astra/data3d_c.cpp | ||
astra/data3d_c.pyx | ||
astra/extrautils.c | ||
astra/extrautils.pyx | ||
astra/functions.py | ||
astra/matlab.py | ||
astra/matrix.py | ||
astra/matrix_c.cpp | ||
astra/matrix_c.pyx | ||
astra/projector.py | ||
astra/projector_c.cpp | ||
astra/projector_c.pyx | ||
astra/utils.cpp | ||
astra/utils.pxd | ||
astra/utils.pyx | ||
doc/.buildinfo | ||
doc/ASTRAProjector.html | ||
doc/algorithm.html | ||
doc/creators.html | ||
doc/data2d.html | ||
doc/data3d.html | ||
doc/functions.html | ||
doc/genindex.html | ||
doc/index.html | ||
doc/matlab.html | ||
doc/matrix.html | ||
doc/objects.inv | ||
doc/projector.html | ||
doc/py-modindex.html | ||
doc/search.html | ||
doc/searchindex.js | ||
doc/_modules/index.html | ||
doc/_modules/astra/ASTRAProjector.html | ||
doc/_modules/astra/algorithm.html | ||
doc/_modules/astra/creators.html | ||
doc/_modules/astra/data2d.html | ||
doc/_modules/astra/data3d.html | ||
doc/_modules/astra/functions.html | ||
doc/_modules/astra/matlab.html | ||
doc/_modules/astra/matrix.html | ||
doc/_modules/astra/projector.html | ||
doc/_sources/ASTRAProjector.txt | ||
doc/_sources/algorithm.txt | ||
doc/_sources/creators.txt | ||
doc/_sources/data2d.txt | ||
doc/_sources/data3d.txt | ||
doc/_sources/functions.txt | ||
doc/_sources/index.txt | ||
doc/_sources/matlab.txt | ||
doc/_sources/matrix.txt | ||
doc/_sources/projector.txt | ||
doc/_static/ajax-loader.gif | ||
doc/_static/basic.css | ||
doc/_static/comment-bright.png | ||
doc/_static/comment-close.png | ||
doc/_static/comment.png | ||
doc/_static/default.css | ||
doc/_static/doctools.js | ||
doc/_static/down-pressed.png | ||
doc/_static/down.png | ||
doc/_static/file.png | ||
doc/_static/jquery.js | ||
doc/_static/minus.png | ||
doc/_static/plus.png | ||
doc/_static/pygments.css | ||
doc/_static/searchtools.js | ||
doc/_static/sidebar.js | ||
doc/_static/underscore.js | ||
doc/_static/up-pressed.png | ||
doc/_static/up.png | ||
doc/_static/websupport.js | ||
examples/phantom.mat | ||
examples/s001_sinogram_par2d.py | ||
examples/s002_data2d.py | ||
examples/s003_gpu_reconstruction.py | ||
examples/s004_cpu_reconstruction.py | ||
examples/s005_3d_geometry.py | ||
examples/s006_3d_data.py | ||
examples/s007_3d_reconstruction.py | ||
examples/s008_gpu_selection.py | ||
examples/s009_projection_matrix.py | ||
examples/s010_supersampling.py | ||
examples/s011_object_info.py | ||
examples/s012_masks.py | ||
examples/s013_constraints.py | ||
examples/s014_FBP.py | ||
examples/s015_fp_bp.py | ||
examples/s016_plots.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
include INSTALL | ||
include COPYING | ||
include install.sh | ||
recursive-include examples *.py *.mat | ||
recursive-include astra *.pyx *.pxd | ||
recursive-include doc * | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
INSTALL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
#----------------------------------------------------------------------- | ||
#Copyright 2013 Centrum Wiskunde & Informatica, Amsterdam | ||
# | ||
#Author: Daniel M. Pelt | ||
#Contact: [email protected] | ||
#Website: http://dmpelt.github.io/pyastratoolbox/ | ||
# | ||
# | ||
#This file is part of the Python interface to the | ||
#All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA Toolbox"). | ||
# | ||
#The Python interface to the ASTRA Toolbox is free software: you can redistribute it and/or modify | ||
#it under the terms of the GNU General Public License as published by | ||
#the Free Software Foundation, either version 3 of the License, or | ||
#(at your option) any later version. | ||
# | ||
#The Python interface to the ASTRA Toolbox is distributed in the hope that it will be useful, | ||
#but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
#GNU General Public License for more details. | ||
# | ||
#You should have received a copy of the GNU General Public License | ||
#along with the Python interface to the ASTRA Toolbox. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
#----------------------------------------------------------------------- | ||
|
||
|
||
import creators as ac | ||
import math | ||
import data2d | ||
|
||
|
||
class ASTRAProjector2DTranspose(): | ||
"""Implements the ``proj.T`` functionality. | ||
Do not use directly, since it can be accessed as member ``.T`` of | ||
an :class:`ASTRAProjector2D` object. | ||
""" | ||
def __init__(self, parentProj): | ||
self.parentProj = parentProj | ||
|
||
def __mul__(self, data): | ||
return self.parentProj.backProject(data) | ||
|
||
|
||
class ASTRAProjector2D(object): | ||
"""Helps with various common ASTRA Toolbox 2D operations. | ||
This class can perform several often used toolbox operations, such as: | ||
* Forward projecting | ||
* Back projecting | ||
* Reconstructing | ||
Note that this class has a some computational overhead, because it | ||
copies a lot of data. If you use many repeated operations, directly | ||
using the PyAstraToolbox methods directly is faster. | ||
You can use this class as an abstracted weight matrix :math:`W`: multiplying an instance | ||
``proj`` of this class by an image results in a forward projection of the image, and multiplying | ||
``proj.T`` by a sinogram results in a backprojection of the sinogram:: | ||
proj = ASTRAProjector2D(...) | ||
fp = proj*image | ||
bp = proj.T*sinogram | ||
:param proj_geom: The projection geometry. | ||
:type proj_geom: :class:`dict` | ||
:param vol_geom: The volume geometry. | ||
:type vol_geom: :class:`dict` | ||
:param proj_type: Projector type, such as ``'line'``, ``'linear'``, ... | ||
:type proj_type: :class:`string` | ||
:param useCUDA: If ``True``, use CUDA for calculations, when possible. | ||
:type useCUDA: :class:`bool` | ||
""" | ||
|
||
def __init__(self, proj_geom, vol_geom, proj_type, useCUDA=False): | ||
self.vol_geom = vol_geom | ||
self.recSize = vol_geom['GridColCount'] | ||
self.angles = proj_geom['ProjectionAngles'] | ||
self.nDet = proj_geom['DetectorCount'] | ||
nexpow = int(pow(2, math.ceil(math.log(2 * self.nDet, 2)))) | ||
self.filterSize = nexpow / 2 + 1 | ||
self.nProj = self.angles.shape[0] | ||
self.proj_geom = proj_geom | ||
self.proj_id = ac.create_projector(proj_type, proj_geom, vol_geom) | ||
self.useCUDA = useCUDA | ||
self.T = ASTRAProjector2DTranspose(self) | ||
|
||
def backProject(self, data): | ||
"""Backproject a sinogram. | ||
:param data: The sinogram data or ID. | ||
:type data: :class:`numpy.ndarray` or :class:`int` | ||
:returns: :class:`numpy.ndarray` -- The backprojection. | ||
""" | ||
vol_id, vol = ac.create_backprojection( | ||
data, self.proj_id, self.useCUDA, True) | ||
data2d.delete(vol_id) | ||
return vol | ||
|
||
def forwardProject(self, data): | ||
"""Forward project an image. | ||
:param data: The image data or ID. | ||
:type data: :class:`numpy.ndarray` or :class:`int` | ||
:returns: :class:`numpy.ndarray` -- The forward projection. | ||
""" | ||
sin_id, sino = ac.create_sino(data, self.proj_id, self.useCUDA, True) | ||
data2d.delete(sin_id) | ||
return sino | ||
|
||
def reconstruct(self, data, method, **kwargs): | ||
"""Reconstruct an image from a sinogram. | ||
:param data: The sinogram data or ID. | ||
:type data: :class:`numpy.ndarray` or :class:`int` | ||
:param method: Name of the reconstruction algorithm. | ||
:type method: :class:`string` | ||
:param kwargs: Additional named parameters to pass to :func:`astra.creators.create_reconstruction`. | ||
:returns: :class:`numpy.ndarray` -- The reconstruction. | ||
Example of a SIRT reconstruction using CUDA:: | ||
proj = ASTRAProjector2D(...) | ||
rec = proj.reconstruct(sinogram,'SIRT_CUDA',iterations=1000) | ||
""" | ||
kwargs['returnData'] = True | ||
rec_id, rec = ac.create_reconstruction( | ||
method, self.proj_id, data, **kwargs) | ||
data2d.delete(rec_id) | ||
return rec | ||
|
||
def __mul__(self, data): | ||
return self.forwardProject(data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#----------------------------------------------------------------------- | ||
#Copyright 2013 Centrum Wiskunde & Informatica, Amsterdam | ||
# | ||
#Author: Daniel M. Pelt | ||
#Contact: [email protected] | ||
#Website: http://dmpelt.github.io/pyastratoolbox/ | ||
# | ||
# | ||
#This file is part of the Python interface to the | ||
#All Scale Tomographic Reconstruction Antwerp Toolbox ("ASTRA Toolbox"). | ||
# | ||
#The Python interface to the ASTRA Toolbox is free software: you can redistribute it and/or modify | ||
#it under the terms of the GNU General Public License as published by | ||
#the Free Software Foundation, either version 3 of the License, or | ||
#(at your option) any later version. | ||
# | ||
#The Python interface to the ASTRA Toolbox is distributed in the hope that it will be useful, | ||
#but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
#GNU General Public License for more details. | ||
# | ||
#You should have received a copy of the GNU General Public License | ||
#along with the Python interface to the ASTRA Toolbox. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
#----------------------------------------------------------------------- | ||
from libcpp.string cimport string | ||
from libcpp cimport bool | ||
from PyIncludes cimport * | ||
|
||
cdef extern from "astra/AstraObjectFactory.h" namespace "astra": | ||
cdef cppclass CAlgorithmFactory: | ||
CAlgorithmFactory() | ||
CAlgorithm *create(string) | ||
|
||
cdef extern from "astra/AstraObjectFactory.h" namespace "astra::CAlgorithmFactory": | ||
cdef CAlgorithmFactory* getSingletonPtr() |
Oops, something went wrong.