A differentiable implementation of scikit-image's Radon transform and filtered backprojection in PyTorch
Project description
torchskradon
About
torchskradon mimics the implementation of radon and iradon from scikit-image. All transforms work with batched multi-channel data and are fully differentiable. This allows backpropagation through torchskradon functions to train neural networks or solve optimization problems with torch.optim (see examples).
Installation
pip install torchskradon
Basic Usage
import torch
from skimage.data import shepp_logan_phantom
from skimage.transform import rescale
from torchskradon.functional import skradon, skiradon
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
image = shepp_logan_phantom()
image = rescale(image, scale=0.4, mode='reflect', channel_axis=None)
image = torch.from_numpy(image).unsqueeze(0).unsqueeze(0).to(device)
theta = torch.linspace(0.0, 180.0, max(image.size()[2:])+1)[:-1].to(device)
sinogram = skradon(image, theta=theta)
reconstruction_fbp = skiradon(sinogram, theta=theta, filter_name='ramp')
Examples
For more detailed examples and use cases, see the examples directory:
examples/plot_radon_transform.py- Basic forward and inverse Radon transformsexamples/ct_model.ipynb- Model-based CT reconstruction
Accuracy on MNIST
----------------------- Absolute Error of Inverse Radon Transform on MNIST test dataset: 2 tests -----------------------
Name Min Max Mean StdDev Median IQR Outliers
------------------------------------------------------------------------------------------------------------------------
torchskradon (CPU) 0.0000e+00 2.2054e-06 3.1475e-07 2.1740e-07 2.5937e-07 2.6217e-07 2159268;272232
torchskradon (GPU) 0.0000e+00 1.9670e-06 1.4094e-07 1.2985e-07 1.0803e-07 1.2759e-07 1415341;427665
------------------------------------------------------------------------------------------------------------------------
--------------------------- Absolute Error of Radon Transform on MNIST test dataset: 2 tests ---------------------------
Name Min Max Mean StdDev Median IQR Outliers
------------------------------------------------------------------------------------------------------------------------
torchskradon (CPU) 0.0000e+00 6.2466e-05 1.0514e-06 1.9718e-06 0.0000e+00 1.4305e-06 7713886;6355122
torchskradon (GPU) 0.0000e+00 6.1989e-05 1.0435e-06 1.9558e-06 0.0000e+00 1.4305e-06 7633118;6271687
------------------------------------------------------------------------------------------------------------------------
Legend:
Outliers: 1 Standard Deviation from Mean; 1.5 IQR (InterQuartile Range) from 1st Quartile and 3rd Quartile.
Performance on MNIST
--------------------------------------------------------- benchmark 'Inverse Radon Transform on MNIST test dataset': 3 tests --------------------------------------------------------
Name (time in s) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
skimage (CPU) 16.8473 (157.73) 16.8693 (130.60) 16.8537 (150.81) 0.0091 (1.06) 16.8511 (155.21) 0.0096 (4.75) 1;0 0.0593 (0.01) 5 1
torchskradon (CPU) 4.8955 (45.83) 5.2628 (40.75) 4.9870 (44.63) 0.1554 (18.10) 4.9192 (45.31) 0.1215 (59.92) 1;1 0.2005 (0.02) 5 1
torchskradon (GPU) 0.1068 (1.0) 0.1292 (1.0) 0.1118 (1.0) 0.0086 (1.0) 0.1086 (1.0) 0.0020 (1.0) 1;1 8.9483 (1.0) 6 1
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------- benchmark 'Radon Transform on MNIST test dataset': 3 tests ------------------------------------------------------------
Name (time in s) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
skimage (CPU) 36.6816 (78.12) 37.3837 (78.01) 36.8518 (77.68) 0.2996 (79.20) 36.7269 (77.48) 0.2385 (41.00) 1;1 0.0271 (0.01) 5 1
torchskradon (CPU) 10.4956 (22.35) 10.6328 (22.19) 10.5554 (22.25) 0.0532 (14.07) 10.5572 (22.27) 0.0763 (13.12) 2;0 0.0947 (0.04) 5 1
torchskradon (GPU) 0.4695 (1.0) 0.4792 (1.0) 0.4744 (1.0) 0.0038 (1.0) 0.4740 (1.0) 0.0058 (1.0) 2;0 2.1080 (1.0) 5 1
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Legend:
Outliers: 1 Standard Deviation from Mean; 1.5 IQR (InterQuartile Range) from 1st Quartile and 3rd Quartile.
OPS: Operations Per Second, computed as 1 / Mean
You can run benchmarks yourself by running:
python -m pytest --benchmark-only --benchmark-sort="name"
Other Packages
For users interested in more flexible implementations of projection transforms check out:
Acknowledgements
This package is inspired by implementations of the Radon transform and its' inverse in skimage.transform, which are based on [1-3].
References
-
JK Romberg, "Image Projections and the Radon Transform"
-
AC Kak, M Slaney, “Principles of Computerized Tomographic Imaging”, IEEE Press 1988.
-
B.R. Ramesh, N. Srinivasa, K. Rajgopal, “An Algorithm for Computing the Discrete Radon Transform With Some Applications”, Proceedings of the Fourth IEEE Region 10 International Conference, TENCON ‘89, 1989
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
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 torchskradon-0.1.3.tar.gz.
File metadata
- Download URL: torchskradon-0.1.3.tar.gz
- Upload date:
- Size: 16.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be4b4851c0b65e9978cb9233d827205d9eae17f6067757ab3ceb5a829865bdc1
|
|
| MD5 |
66253bd968934351f6ae773bcc31128b
|
|
| BLAKE2b-256 |
4bc36fff3b2fcfbcf9a345b68fbee02464d7933c17059f54dbe4e26c3b918f5c
|
Provenance
The following attestation bundles were made for torchskradon-0.1.3.tar.gz:
Publisher:
python-publish.yml on tomluetjen/torchskradon
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torchskradon-0.1.3.tar.gz -
Subject digest:
be4b4851c0b65e9978cb9233d827205d9eae17f6067757ab3ceb5a829865bdc1 - Sigstore transparency entry: 1391732762
- Sigstore integration time:
-
Permalink:
tomluetjen/torchskradon@d5a0a4564ecbad6da75b61e894b72202d85a7c76 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/tomluetjen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@d5a0a4564ecbad6da75b61e894b72202d85a7c76 -
Trigger Event:
release
-
Statement type:
File details
Details for the file torchskradon-0.1.3-py3-none-any.whl.
File metadata
- Download URL: torchskradon-0.1.3-py3-none-any.whl
- Upload date:
- Size: 10.1 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 |
6e9e89cda0b86f0d08714179345005003afaf69d2382956d54e50437c5739dc9
|
|
| MD5 |
869368620809859547795d49c693f32d
|
|
| BLAKE2b-256 |
c17069f53d6910a02d99d1608eab260e33d50efeb9f9d1beaf7d2603d74d40b5
|
Provenance
The following attestation bundles were made for torchskradon-0.1.3-py3-none-any.whl:
Publisher:
python-publish.yml on tomluetjen/torchskradon
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torchskradon-0.1.3-py3-none-any.whl -
Subject digest:
6e9e89cda0b86f0d08714179345005003afaf69d2382956d54e50437c5739dc9 - Sigstore transparency entry: 1391732774
- Sigstore integration time:
-
Permalink:
tomluetjen/torchskradon@d5a0a4564ecbad6da75b61e894b72202d85a7c76 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/tomluetjen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@d5a0a4564ecbad6da75b61e894b72202d85a7c76 -
Trigger Event:
release
-
Statement type: