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

MIT

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.1.0.tar.gz (15.4 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.1.0-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for torchtomo-0.1.0.tar.gz
Algorithm Hash digest
SHA256 18022c2311a3ac671d2c8ca3c22aae78ec0a202f3637b50cac416e73bb672a21
MD5 3fbee59061e1dbd84368f9818187f765
BLAKE2b-256 32d8f0cf10b0b25c64901ca1517d6f3cd507339e63a642928226f0c543a74b94

See more details on using hashes here.

Provenance

The following attestation bundles were made for torchtomo-0.1.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.1.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for torchtomo-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5e58990ee8506ad49591c5546bf510bc504049c1e8822e44cc01248b1970e348
MD5 083f3e12f21e7adc38f38d8ec14b632b
BLAKE2b-256 830d6cf0a95f076ad36a299b0c1ef4c16f54691af152f9e9d3f04f0c6efaf855

See more details on using hashes here.

Provenance

The following attestation bundles were made for torchtomo-0.1.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