Skip to content

Commit

Permalink
Add python sample scripts for EM_CUDA, FBP_CUDA
Browse files Browse the repository at this point in the history
  • Loading branch information
wjp committed Jul 16, 2024
1 parent b592058 commit a936526
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 2 deletions.
42 changes: 41 additions & 1 deletion docs/algs/EM_CUDA.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,47 @@ cfg.option.PixelSuperSampling optional Specifies the amount of pixel supersam
Example
-------

.. code-block:: matlab
.. tabs::
.. group-tab:: Python
.. code-block:: python
import astra
import matplotlib.pyplot as plt
import numpy
# create geometries and projector
proj_geom = astra.create_proj_geom('parallel', 1.0, 256, numpy.linspace(0, numpy.pi, 180, endpoint=False))
vol_geom = astra.create_vol_geom(256,256)
proj_id = astra.create_projector('cuda', proj_geom, vol_geom)
# generate phantom image
V_exact_id, V_exact = astra.data2d.shepp_logan(vol_geom)
# create forward projection
sinogram_id, sinogram = astra.create_sino(V_exact, proj_id)
# reconstruct
# initialize with ones to allow for multiplicative updates
recon_id = astra.data2d.create('-vol', vol_geom, 1.0)
cfg = astra.astra_dict('EM_CUDA')
cfg['ProjectorId'] = proj_id
cfg['ProjectionDataId'] = sinogram_id
cfg['ReconstructionDataId'] = recon_id
em_id = astra.algorithm.create(cfg)
astra.algorithm.run(em_id, 15)
V = astra.data2d.get(recon_id)
plt.gray()
plt.imshow(V)
plt.show()
# garbage disposal
astra.data2d.delete([sinogram_id, recon_id, V_exact_id])
astra.projector.delete(proj_id)
astra.algorithm.delete(em_id)
.. group-tab:: Matlab
.. code-block:: matlab
%% create phantom
V_exact = phantom(256);
Expand Down
42 changes: 41 additions & 1 deletion docs/algs/FBP_CUDA.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,47 @@ cfg.option.ShortScan optional Only for use with the fanflat geometry. If enab
Example
-------

.. code-block:: matlab
.. tabs::
.. group-tab:: Python
.. code-block:: python
import astra
import matplotlib.pyplot as plt
import numpy
# create geometries and projector
proj_geom = astra.create_proj_geom('parallel', 1.0, 256, numpy.linspace(0, numpy.pi, 180, endpoint=False))
vol_geom = astra.create_vol_geom(256,256)
proj_id = astra.create_projector('cuda', proj_geom, vol_geom)
# generate phantom image
V_exact_id, V_exact = astra.data2d.shepp_logan(vol_geom)
# create forward projection
sinogram_id, sinogram = astra.create_sino(V_exact, proj_id)
# reconstruct
recon_id = astra.data2d.create('-vol', vol_geom, 0)
cfg = astra.astra_dict('FBP_CUDA')
cfg['ProjectorId'] = proj_id
cfg['ProjectionDataId'] = sinogram_id
cfg['ReconstructionDataId'] = recon_id
cfg['option'] = { 'MinConstraint': 0, 'MaxConstraint': 1 }
fbp_id = astra.algorithm.create(cfg)
astra.algorithm.run(fbp_id)
V = astra.data2d.get(recon_id)
plt.gray()
plt.imshow(V)
plt.show()
# garbage disposal
astra.data2d.delete([sinogram_id, recon_id, V_exact_id])
astra.projector.delete(proj_id)
astra.algorithm.delete(fbp_id)
.. group-tab:: Matlab
.. code-block:: matlab
%% create phantom
V_exact = phantom(256);
Expand Down

0 comments on commit a936526

Please sign in to comment.