Skip to main content

Differentiable CT Reconstruction in Pure PyTorch

Project description

TorchTomo

PyPI Changelog Tests License

Differentiable CT reconstruction primitives in pure PyTorch.

TorchTomo provides forward projection, adjoint backprojection, and filtered backprojection for parallel-beam and fan-beam geometries, with support for CPU, CUDA, and Apple Silicon (MPS).

Features

  • Pure PyTorch implementation with no custom CUDA build step
  • Autograd-friendly operators for learned reconstruction pipelines
  • Parallel-beam and fan-beam (flat detector) projectors
  • Built-in FBP filters: ramp, shepp-logan, cosine, hamming, hann, none
  • Built-in phantom generators for quick experiments

Installation

pip install torchtomo

Quick Start (Parallel Beam)

import torch
from torchtomo import ParallelBeam, shepp_logan

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

phantom = shepp_logan(size=256, device=device)  # [1, 1, 256, 256]
projector = ParallelBeam(img_size=256, n_angles=180, n_det=256).to(device)

sinogram = projector.forward(phantom)                 # [1, 1, 180, 256]
recon = projector.fbp(sinogram, filter_name="ramp")   # [1, 1, 256, 256]

Fan-Beam Example

from torchtomo import FanBeam, shepp_logan

phantom = shepp_logan(size=256)
projector = FanBeam(
    img_size=256,
    n_angles=360,
    n_det=400,
    src_dist=500.0,
    det_dist=500.0,
)

sinogram = projector.forward(phantom)
recon = projector.fbp(sinogram, filter_name="hann")

Differentiable Optimization Example

import torch
import torch.nn.functional as F
from torchtomo import ParallelBeam

projector = ParallelBeam(img_size=256, n_angles=180)
x = torch.zeros(1, 1, 256, 256, requires_grad=True)
y = torch.randn(1, 1, 180, 256)

loss = F.mse_loss(projector.forward(x), y)
loss.backward()  # gradients flow through projection operators

API Snapshot

  • ParallelBeam(...)
  • FanBeam(...)
  • projector.forward(image)
  • projector.backward(sinogram)
  • projector.fbp(sinogram, filter_name="ramp")
  • apply_filter(sinogram, filter_name=...)
  • shepp_logan(size=..., device=...)
  • circle_phantom(size=..., n_circles=..., device=...)
  • torchtomo.phantom.forbild(size=..., device=...)

Tensor Shapes

  • Image: [B, 1, H, W]
  • Sinogram: [B, 1, n_angles, n_det]

Development

git clone https://github.com/itu-biai/torchtomo.git
cd torchtomo
pip install -e ".[dev]"
make test
make lint
make build

CI/CD

  • .github/workflows/test.yml: Python test matrix on push and pull_request
  • .github/workflows/publish.yml: release-triggered test matrix and PyPI publish step

License

Creative Commons Attribution-NonCommercial 4.0 International (CC BY-NC 4.0).
Commercial use by third parties requires prior written permission from the authors.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

torchtomo-0.2.0.tar.gz (15.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

torchtomo-0.2.0-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file torchtomo-0.2.0.tar.gz.

File metadata

  • Download URL: torchtomo-0.2.0.tar.gz
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for torchtomo-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f2ca63df7a6032db194d502da73fe629c9c01c7b5adf72d66f96a8b972fa4240
MD5 fc08d90f52d90ea4d2314228547a434c
BLAKE2b-256 5643ac38fa167ad87ed6b6bf9192b16fbb04c17a9c7ea873dcc6854e88023a7f

See more details on using hashes here.

Provenance

The following attestation bundles were made for torchtomo-0.2.0.tar.gz:

Publisher: publish.yml on itu-biai/torchtomo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file torchtomo-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: torchtomo-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for torchtomo-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3d1d25caedd84fe21abf208ad569b0d153ee9f241eed345c533a04c76c29ad6c
MD5 0a8df5d5f88edf72797def6ce46a82cd
BLAKE2b-256 b0200954a58aad70dc18680a1dc41835937a9b629c198ce8a0420baf956d5d46

See more details on using hashes here.

Provenance

The following attestation bundles were made for torchtomo-0.2.0-py3-none-any.whl:

Publisher: publish.yml on itu-biai/torchtomo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page