Skip to content

Commit 16bf5a9

Browse files
authored
Merge pull request #233 from cabouman/prerelease
Release 0.2.8, adding support for fan beam
2 parents 836ccc6 + 94c0b06 commit 16bf5a9

File tree

15 files changed

+202
-45
lines changed

15 files changed

+202
-45
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# svmbir
22

3-
*Python code for fast parallel-beam MBIR (Model Based Iterative Reconstruction)
4-
This is a python wrapper around HPImaging's supervoxel C code, [sv-mbirct](https://github.com/HPImaging/sv-mbirct).*
3+
*Python code for fast MBIR (Model Based Iterative Reconstruction)
4+
This is a python wrapper for High Performance Imaging's supervoxel C code, [HPImaging/sv-mbirct](https://github.com/HPImaging/sv-mbirct).*
55

66
Full documentation is available at: https://svmbir.readthedocs.io
77

demo/demo_fanbeam.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import os
2+
import numpy as np
3+
import matplotlib.pyplot as plt
4+
import svmbir
5+
6+
"""
7+
Fan beam demo
8+
"""
9+
10+
# Simulated sinogram parameters
11+
geometry = 'fan'
12+
dist_source_detector = 512.0
13+
magnification = 2.0
14+
num_views = 512
15+
num_channels = 512
16+
angles = np.linspace(-np.pi, np.pi, num_views, endpoint=False)
17+
18+
# Reconstruction parameters
19+
img_size = 256
20+
sharpness = 0.0
21+
T = 1.0
22+
p = 1.2
23+
snr_db = 40.0
24+
25+
# Generate phantom with a single slice
26+
phantom = svmbir.phantom.gen_shepp_logan(img_size,img_size)
27+
phantom = np.expand_dims(phantom, axis=0)
28+
sino = svmbir.project(phantom, angles, num_channels, geometry=geometry, dist_source_detector=dist_source_detector, magnification=magnification)
29+
30+
# Perform MBIR reconstruction
31+
recon = svmbir.recon(sino, angles, num_rows=img_size, num_cols=img_size, T=T, p=p, sharpness=sharpness, snr_db=snr_db, geometry=geometry, dist_source_detector=dist_source_detector, magnification=magnification)
32+
33+
# Compute Normalized Root Mean Squared Error
34+
nrmse = svmbir.phantom.nrmse(recon[0], phantom[0])
35+
36+
#plt.ion()
37+
vmin = 1.0
38+
vmax = 1.2
39+
plt.figure(); plt.imshow(phantom[0],vmin=vmin,vmax=vmax,cmap='gray'); plt.colorbar()
40+
plt.title('Shepp Logan Phantom')
41+
42+
plt.figure(); plt.imshow(np.squeeze(sino),cmap='gray'); plt.colorbar()
43+
plt.title('Sinogram')
44+
45+
plt.figure(); plt.imshow(recon[0],vmin=vmin,vmax=vmax,cmap='gray'); plt.colorbar()
46+
plt.title(f'Reconstruction, nmrse={nrmse:.3f}')
47+
48+
print("Close figures to continue")
49+
plt.show()
50+

dev_scripts/test_pypi.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# Set these accordingly:
1010

1111
python_versions=("3.7" "3.8" "3.9")
12-
svmbir_version=0.2.7
12+
svmbir_version=0.2.8
1313

1414
echo "*********************************************************"
1515
echo "**** Test install "
@@ -22,7 +22,7 @@ for pyv in ${python_versions[@]}; do
2222
conda activate sv${pyv}
2323

2424
echo "*********** Installing svmbir ${svmbir_version} *************"
25-
#pip install -i https://test.pypi.org/simple/ svmbir==$svmbir_version
25+
#pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple svmbir==$svmbir_version
2626
pip install svmbir==$svmbir_version
2727
pip install -r ../demo/requirements_demo.txt
2828

docs/README.rst

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
**svmbir** stands for Super-Voxel Model-Based Iterative Reconstruction.
2-
svmbir is an easy-to-use python package for fast parallel-beam reconstruction of tomography data using model-based priors.
1+
**svmbir** (super-voxel model-based iterative reconstruction) is an easy-to-use python package for fast iterative reconstruction of tomography data using model-based priors.
2+
The `svmbir <https://github.com/cabouman/svmbir>`_ package is a python interface to HPImaging's optimized
3+
C implementation `[sv-mbirct] <https://github.com/HPImaging/sv-mbirct>`_
4+
of the super-voxel algorithm :cite:`wang2016high` :cite:`wang2017massively`.
35

46

57
Features
68
--------
7-
* Easy-to-use python code for fast parallel-beam MBIR (Model Based Iterative Reconstruction)
8-
9-
* Interface to HPImaging's optimized C implementation `[sv-mbirct] <https://github.com/HPImaging/sv-mbirct>`_ of the super-voxel algorithm :cite:`wang2016high` :cite:`wang2017massively`
10-
11-
* Supports MBIR reconstruction with Bayesian and Plug-and-Play prior models.
9+
* Supports MBIR reconstruction with Bayesian and Plug-and-Play prior models
10+
* Supports parallel-beam and fan-beam geometries
1211

1312

1413
System Requirements
@@ -23,11 +22,11 @@ Optional System Requirements
2322
Fastest reconstruction can be obtained with,
2423

2524
* Intel-based CPU(s) supporting AVX2,AVX512
26-
* Intel ICC compiler (in "Parallel Studio XE", and now free "oneAPI")
25+
* Intel ICC compiler (included with Intel's free "oneAPI" toolkit)
2726

2827
We also recommend:
2928

30-
* Installation using conda environment
29+
* Installation to a conda virtual environment
3130

3231
License
3332
-------

docs/requirements.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
numpy==1.21.*
2+
psutil>=5.8
3+
Pillow
4+
Cython
5+
ruamel.yaml
6+
pytest
17
sphinx>=2.2
28
sphinxcontrib-bibtex==1.0
3-
ipython>=6.3.1
4-
numpy~=1.20.1
5-
matplotlib~=3.3.4
6-
ruamel.yaml~=0.16.12
79
sphinx-rtd-theme~=0.5.1
8-
psutil~=5.8.0
9-
Pillow~=8.4.0
10-
Cython~=0.29.21
10+
ipython>=6.3.1

docs/source/geom-fan.jpg

57.7 KB
Loading

docs/source/geom-parallel.jpg

52.6 KB
Loading

docs/source/overview.rst

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,36 @@
22
Overview
33
========
44

5-
**svmbir** is a Python implementation of the Super-Voxel Model Based Iterative Reconstruction (MBIR) algorithm :cite:`wang2016high` :cite:`wang2017massively` for fast reconstruction of parallel beam 3D data.
5+
**svmbir** is a Python implementation of the Super-Voxel Model Based Iterative Reconstruction (MBIR) algorithm :cite:`wang2016high` :cite:`wang2017massively` for fast reconstruction of parallel-beam and fan-beam tomography data (3D).
66
The code performs Bayesian reconstruction of tomographic data, so it is particularly well-suited for sparse view reconstruction from noisy data.
77
It also has hooks to support Plug-and-Play prior models that can dramatically improve image quality :cite:`venkatakrishnan2013plug` :cite:`sreehari2016plug`.
8+
The reconstruction engine for *svmbir* is written and optimized in C
9+
`[HPImaging/sv-mbirct] <https://github.com/HPImaging/sv-mbirct>`_ .
810

911
**How does it work?**
1012

11-
The super-voxel code can be 100x to 1000x faster than conventional code because it reorganizes operations in a way that is much better matched to a computer's cache structure. To do this, it precomputes the ``system matrix`` that describes the geometry of the tomography system and stores it in a file in encoded form. Whenever you do a reconstruction with a new geometry, the ``svmbir`` package automatically detects the new geometry, precomputes a new system matrix, and stores it in a library for future use. By default, the system matrices are stored in a subdirectory of your personal ``.cache`` directory in your home directory. So if they are taking too much space on your disk, you can remove these files at any time, and they will just be recomputed when needed.
13+
The super-voxel code can be 100x to 1000x faster than conventional MBIR code because it reorganizes operations in a way that is much better matched to a computer's cache structure.
14+
Part of this involves precomputing a *system matrix* that models the system geometry, and encoding it in a layout that facilitates parallelization and reduces the required fetches from memory during reconstruction.
15+
When system matrices are computed, they are stored to disk and will be automatically loaded whenever the same geometry is subsequently encountered.
1216

13-
**Troubleshooting**
17+
**Geometry**
18+
19+
**svmbir** currently supports *parallel-beam* and *fan-beam* (equiangular, see below) imaging geometries.
20+
21+
.. figure:: geom-fan.jpg
22+
:width: 50%
23+
:alt: fan beam geometry
24+
:align: center
25+
26+
Equiangular fan-beam geometry
27+
28+
.. figure:: geom-parallel.jpg
29+
:width: 50%
30+
:alt: parallel beam geometry
31+
:align: center
32+
33+
Parallel-beam geometry
1434

15-
*Cached System Matrix Problems:* Rare updates to the software package could include changes to the encoding of the system matrix and result in existing pre-computed matrix files being incompatible after the update. The last such update was on (2020-12-02). To remove the outdated files, delete the cache directory located at ``~/.cache/svmbir``. The package will regenerate the system matrices as needed at the time of reconstruction.
1635

1736
*View Angle Ordering:* It is common practice to collect view data using techniques such as the "golden ratio" method in which the view angles are not collected in monotonically increasing order on the interval :math:`[0,2\pi)`. While ``svmbir`` will produce the correct reconstruction regardless of view ordering, its reconstruction speed will be substantially degraded when the views are not in monotone order. In this case, we highly recommend that users reorder the sinogram views using the provided ``sino_sort`` function. The ``sino_sort`` function first wraps the view angles modulo :math:`2\pi`, and then sorts the views to be in monotonically increasing order by view angle.
1837

@@ -37,3 +56,11 @@ Using this convention, the 3D array, ``image``, will be in units of photons/AU.
3756
.. math::
3857
3958
\mbox{image in photons/mm} = \frac{ \mbox{image in photons/ALU} }{ 5 \mbox{mm} / \mbox{ALU}}
59+
60+
**Matrix caching**
61+
62+
When system matrices are computed, they are stored to disk and will be automatically loaded whenever the same geometry is subsequently encountered.
63+
By default, the system matrices are stored in the subfolder ``~/.cache/svmbir/sysmatrix`` of your home directory.
64+
The matrix files can be removed at any time, and should be periodically cleaned out to reduce disk use.
65+
Occasionally, updates to the software package include changes to the encoding of the system matrix, in which case the the cached matrix files should also be cleaned out to avoid incompatibility.
66+

docs/source/theory.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Theory
33
======
44

5-
Super-Voxel Model-Based Iterative Reconstruction (SVMBIR) is a fast algorithm for computing MBIR reconstructions from parallel beam tomographic data.
5+
Super-Voxel Model-Based Iterative Reconstruction (SVMBIR) is a fast algorithm for computing MBIR reconstructions from tomographic data.
66
MBIR reconstruction works by solving the following optimization problem
77

88
.. math::
@@ -22,7 +22,7 @@ The forward model term has the form,
2222
2323
where :math:`y` is the sinogram data,
2424
where :math:`x` is the unknown image to be reconstructed,
25-
:math:`A` is the linear projection operator for the parallel-beam geometry,
25+
:math:`A` is the linear projection operator for the specified imaging geometry,
2626
:math:`\Lambda` is the diagonal matrix of sinogram weights, :math:`\Vert y \Vert_\Lambda^2 = y^T \Lambda y`, and :math:`\sigma_y` is a parameter controling the assumed standard deviation of the measurement noise.
2727

2828
These quantities correspond to the following python variables:

svmbir/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = '0.2.7'
1+
__version__ = '0.2.8'
22
from .svmbir import *
33
from .phantom import *
44
__all__ = ['_svmbir_lib_path','_clear_cache','sino_sort','auto_sigma_x','auto_sigma_p','auto_sigma_y', 'calc_weights','project','backproject','recon']

0 commit comments

Comments
 (0)