Skip to main content

Analytical Tomographic Image Reconstruction

Welcome to the Analytical Tomographic Image Reconstruction repository! This collection of Python code provides implementations for various analytical tomographic image reconstruction algorithms. These algorithms play a crucial role in transforming projection data into detailed images, making them valuable tools in medical imaging, materials science, and more. Included are Fourier Gridding, Backproject Filter, Filtered Backprojection and Convolve Backproject.

Reconstructions of the Shepp-Logan phantom with each method

Installation

pip install git+https://github.com/GivralNguyen/Python-Medical-Analytical-Tomographic-Image-Reconstruction.git

Or from a local clone (editable, with the extras for the notebook and tests):

git clone https://github.com/GivralNguyen/Python-Medical-Analytical-Tomographic-Image-Reconstruction.git
cd Python-Medical-Analytical-Tomographic-Image-Reconstruction
pip install -e ".[notebook,test]"

Requires Python ≥ 3.9; dependencies (numpy, scipy, scikit-image, imageio) are installed automatically.

Quick Start

import numpy as np
import tomorecon as tr

phantom = tr.shepp_logan()             # 256 x 256, bundled with the package
theta = np.arange(180)                 # projection angles in degrees
sinogram = tr.radon(phantom, theta)    # shape (256, 180): one projection per column

image = tr.fbp(sinogram, theta)                         # filtered backprojection
image = tr.fbp(sinogram, theta, filter="hann")          # 'ramp', 'shepp-logan', 'cosine', 'hamming', 'hann'
image = tr.cbp(sinogram, theta)                         # convolve-backproject (spatial-domain filtering)
image = tr.bpf(sinogram, theta)                         # backproject-filter (2-D cone filter)
image = tr.fourier_gridding(sinogram, theta)            # direct Fourier reconstruction
image = tr.backproject(sinogram, theta)                 # unfiltered backprojection (blurred)

Every step is also available on its own, e.g. tr.filter_sinogram, tr.convolve_sinogram, tr.spatial_kernel, tr.cone_filter, tr.projection_spectra, tr.polar_to_cartesian and tr.inverse_fft2. See the tutorial for how they fit together.

API

Function Description
shepp_logan(size=256), disk(...), load_image(path, size=256) Test objects
radon(image, theta=None, circle=True) Sinogram, shape (n_detectors, n_angles)
backproject(sinogram, theta=None, output_size=None, interval=1) Unfiltered backprojection
fbp(sinogram, theta=None, filter="ramp", output_size=None) Filtered backprojection
cbp(sinogram, theta=None, filter="ramp", output_size=None) Convolve-backproject
bpf(sinogram, theta=None, filter="ramp", output_size=None, grid_factor=2) Backproject-filter
fourier_gridding(sinogram, theta=None, output_size=None, oversample=4) Direct Fourier reconstruction

Angles are in degrees; if theta is omitted, the projections are assumed equally spaced over [0°, 180°).

Sample Results

All images below are produced from the 256×256 Shepp-Logan phantom with 180 projections (0°–179°), using the code in this repository. See tutorial.ipynb for the full walkthrough.

Radon Transform

Each column of the sinogram is one projection: the line integrals of the object along parallel rays at angle θ.

Phantom and its sinogram

Fourier Gridding

By the Fourier slice theorem, the 1-D Fourier transform of a projection at angle θ is a radial line through the 2-D Fourier transform of the object. The slices are interpolated from the polar grid onto a Cartesian grid, and an inverse 2-D FFT gives the image. The projections are zero-padded 4× first (oversampling), which keeps the interpolation error small.

Fourier gridding: 1-D FT of projections, interpolated 2-D spectrum, reconstruction

Backprojection

Smearing every projection back across the image plane. With few angles the streaks are obvious; with all 180 angles the result is the object blurred by 1/r.

Unfiltered backprojection with 1, 2, 10, 45 and 180 projections

Backproject Filter

The 1/r blur of the backprojection is removed afterwards in 2-D: multiply its spectrum by the cone filter |ρ| and transform back. The backprojection is computed on a 2× larger grid, since the blur extends far outside the object.

Backproject-filter: backprojection, spectrum before and after the cone filter, result

Filtered Backprojection

Each projection is filtered with a 1-D ramp filter |ω| (optionally apodized) before backprojection. Smoother windows trade resolution for less noise.

Filter responses, filtered sinogram, and FBP with each filter

Convolve Backproject

The same filtering as FBP, but done in the spatial domain by convolving each projection with the inverse Fourier transform of the filter. The result is identical to FBP up to floating-point error.

Spatial kernels, convolved sinogram, CBP reconstruction

Code Structure

The package lives in src/tomorecon/:

Module Contents
phantoms.py shepp_logan, disk, load_image
projection.py radon: the forward model
backprojection.py backproject, fbp, cbp, bpf
filters.py Ramp-type filters (fourier_filter), their spatial kernels (spatial_kernel), filter_sinogram, convolve_sinogram and the 2-D cone_filter
gridding.py fourier_gridding and its steps: projection_spectra, polar_to_cartesian, inverse_fft2, polar_grid, cartesian_grid

Outside the package:

  • tutorial.ipynb: Jupyter notebook demonstrating the usage of all reconstruction methods with examples and visualizations.
  • tests/: checks that every method reconstructs the phantom accurately (run pytest).
  • data/: extra sample images for load_image.

Tutorial

After installing with the notebook extra, explore the provided tutorial.ipynb notebook for comprehensive examples and visualizations of each reconstruction method. You can experiment with different data sources and filters to see how these algorithms perform under various conditions.

Contributing

We welcome contributions to enhance and expand this repository. If you have improvements, additional algorithms, or new features to suggest, please feel free to open an issue or submit a pull request.

Acknowledgments

Special thanks to me for writing this and Prof. Lasser for the wonderful Seminar course

License

This code is released under the MIT License. Feel free to use, modify, and distribute the code in accordance with the terms of the license.

Happy reconstructing! 🌐🖼️

Metadata

Release files for tomorecon 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tomorecon 0.1.0
File Size Uploaded Provenance Actions
tomorecon-0.1.0.tar.gz 17.4 kB Without provenance Details for tomorecon-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tomorecon 0.1.0
File Interpreter ABI Platform Actions
tomorecon-0.1.0-py3-none-any.whl Python 3 none any Details for tomorecon-0.1.0-py3-none-any.whl

Total release size: 36.7 kB

Release files / tomorecon-0.1.0.tar.gz

Download URL tomorecon-0.1.0.tar.gz
Size 17.4 kB
Tags Source
SHA-256 checksum
How to use checksums
4153706d400c8304f4a0f644e62712c8b995a99456055840cd2e6514e4ff9429
BLAKE2b-256 checksum
How to use checksums
68ad700c23daa490fa1824990de74cd5f51aa25d4a4721604f1fdab7622a9b79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.9

Release files / tomorecon-0.1.0-py3-none-any.whl

Download URL tomorecon-0.1.0-py3-none-any.whl
Size 19.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e6fc851a16f0011e8c4fa5f19b43303274405498b5a16284f7c9c7728549b3e7
BLAKE2b-256 checksum
How to use checksums
e70b52f048b3acd844af9cd61e574dad3ef6d28472f19e2d36e05314576872b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.9

Security for tomorecon 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page