Differentiable CT Reconstruction in Pure PyTorch
Project description
TorchTomo
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 onpushandpull_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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f2ca63df7a6032db194d502da73fe629c9c01c7b5adf72d66f96a8b972fa4240
|
|
| MD5 |
fc08d90f52d90ea4d2314228547a434c
|
|
| BLAKE2b-256 |
5643ac38fa167ad87ed6b6bf9192b16fbb04c17a9c7ea873dcc6854e88023a7f
|
Provenance
The following attestation bundles were made for torchtomo-0.2.0.tar.gz:
Publisher:
publish.yml on itu-biai/torchtomo
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torchtomo-0.2.0.tar.gz -
Subject digest:
f2ca63df7a6032db194d502da73fe629c9c01c7b5adf72d66f96a8b972fa4240 - Sigstore transparency entry: 1328132192
- Sigstore integration time:
-
Permalink:
itu-biai/torchtomo@9064ea12dc83cef426f56fac510af8ed12b48599 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/itu-biai
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9064ea12dc83cef426f56fac510af8ed12b48599 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3d1d25caedd84fe21abf208ad569b0d153ee9f241eed345c533a04c76c29ad6c
|
|
| MD5 |
0a8df5d5f88edf72797def6ce46a82cd
|
|
| BLAKE2b-256 |
b0200954a58aad70dc18680a1dc41835937a9b629c198ce8a0420baf956d5d46
|
Provenance
The following attestation bundles were made for torchtomo-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on itu-biai/torchtomo
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torchtomo-0.2.0-py3-none-any.whl -
Subject digest:
3d1d25caedd84fe21abf208ad569b0d153ee9f241eed345c533a04c76c29ad6c - Sigstore transparency entry: 1328132200
- Sigstore integration time:
-
Permalink:
itu-biai/torchtomo@9064ea12dc83cef426f56fac510af8ed12b48599 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/itu-biai
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9064ea12dc83cef426f56fac510af8ed12b48599 -
Trigger Event:
release
-
Statement type: