torchskradon 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
1
+ The MIT License (MIT)
2
+ Copyright © 2025 Tom Lütjen
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,135 @@
1
+ Metadata-Version: 2.4
2
+ Name: torchskradon
3
+ Version: 0.1.0
4
+ Summary: A differentiable implementation of scikit-image's Radon transform and filtered backprojection in PyTorch
5
+ Author-email: Tom Lütjen <tom.luetjen@icloud.com>
6
+ License: MIT
7
+ Project-URL: Repository, https://github.com/tomluetjen/torchskradon.git
8
+ Project-URL: Issues, https://github.com/tomluetjen/torchskradon/issues
9
+ Keywords: pytorch,skimage,radon,tomography
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3 :: Only
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
18
+ Requires-Python: >=3.10
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: torch>=2.2
22
+ Provides-Extra: tests
23
+ Requires-Dist: torchvision>=0.17; extra == "tests"
24
+ Requires-Dist: ruff>=0.6.9; extra == "tests"
25
+ Requires-Dist: scikit-image>=0.22; extra == "tests"
26
+ Requires-Dist: matplotlib>=3.8; extra == "tests"
27
+ Requires-Dist: pytest>=8.2; extra == "tests"
28
+ Requires-Dist: pytest-benchmark>=4.0; extra == "tests"
29
+ Requires-Dist: pytest-cov>=5.0; extra == "tests"
30
+ Provides-Extra: dev
31
+ Requires-Dist: torchvision>=0.17; extra == "dev"
32
+ Requires-Dist: ruff>=0.6.9; extra == "dev"
33
+ Requires-Dist: scikit-image>=0.22; extra == "dev"
34
+ Requires-Dist: matplotlib>=3.8; extra == "dev"
35
+ Requires-Dist: pytest>=8.2; extra == "dev"
36
+ Requires-Dist: pytest-benchmark>=4.0; extra == "dev"
37
+ Requires-Dist: pytest-cov>=5.0; extra == "dev"
38
+ Dynamic: license-file
39
+
40
+ # torchskradon
41
+
42
+ [![LICENSE](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) [![Python](https://img.shields.io/badge/python-3.10%20|%203.11%20|%203.12-blue)](#) [![PyPI](https://img.shields.io/pypi/v/torchskradon.svg?label=PyPI&logo=pypi)](https://pypi.org/project/torchskradon/) [![CI](https://github.com/tomluetjen/torchskradon/actions/workflows/python-app.yml/badge.svg?branch=main)](https://github.com/tomluetjen/torchskradon/actions/workflows/python-app.yml) [![Coverage](https://codecov.io/gh/tomluetjen/torchskradon/branch/main/graph/badge.svg)](https://codecov.io/gh/tomluetjen/torchskradon)
43
+
44
+
45
+ ## About
46
+ `torchskradon` mimics the implementation of [`radon`](https://scikit-image.org/docs/stable/api/skimage.transform.html#skimage.transform.radon) and [`iradon`](https://scikit-image.org/docs/stable/api/skimage.transform.html#skimage.transform.iradon) from [`scikit-image`](https://scikit-image.org). 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`](https://docs.pytorch.org/docs/stable/optim.html) (see [examples](#examples)).
47
+
48
+ ## Installation
49
+ ```console
50
+ pip install torchskradon
51
+ ```
52
+
53
+ ## Basic Usage
54
+ ```python
55
+ import torch
56
+ from skimage.data import shepp_logan_phantom
57
+ from skimage.transform import rescale
58
+ from torchskradon.functional import skradon, skiradon
59
+
60
+ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
61
+
62
+ image = shepp_logan_phantom()
63
+ image = rescale(image, scale=0.4, mode='reflect', channel_axis=None)
64
+ image = torch.from_numpy(image).unsqueeze(0).unsqueeze(0).to(device)
65
+ theta = torch.linspace(0.0, 180.0, max(image.size()[2:])+1)[:-1].to(device)
66
+ sinogram = skradon(image, theta=theta)
67
+ reconstruction_fbp = skiradon(sinogram, theta=theta, filter_name='ramp')
68
+ ```
69
+
70
+ ## Examples
71
+ For more detailed examples and use cases, see the `examples` directory:
72
+
73
+ - [`examples/plot_radon_transform.py`](examples/plot_radon_transform.py) - Basic forward and inverse Radon transforms
74
+ - [`examples/ct_model.ipynb`](examples/ct_model.ipynb) - Model-based CT reconstruction
75
+
76
+ ## Accuracy
77
+ ````console
78
+ ----------------------- Absolute Error of Inverse Radon Transform on MNIST test dataset: 2 tests -----------------------
79
+ Name Min Max Mean StdDev Median IQR Outliers
80
+ ------------------------------------------------------------------------------------------------------------------------
81
+ torchskradon (CPU) 0.0000e+00 2.0862e-06 3.1433e-07 2.1123e-07 2.5891e-07 2.5879e-07 2117701;247180
82
+ torchskradon (GPU) 0.0000e+00 1.9670e-06 1.3048e-07 1.0576e-07 1.0803e-07 1.1735e-07 1800730;379622
83
+ ------------------------------------------------------------------------------------------------------------------------
84
+
85
+ --------------------------- Absolute Error of Radon Transform on MNIST test dataset: 2 tests ---------------------------
86
+ Name Min Max Mean StdDev Median IQR Outliers
87
+ ------------------------------------------------------------------------------------------------------------------------
88
+ torchskradon (CPU) 0.0000e+00 6.2466e-05 1.0514e-06 1.9718e-06 0.0000e+00 1.4305e-06 7713886;6355122
89
+ torchskradon (GPU) 0.0000e+00 6.1989e-05 1.0435e-06 1.9558e-06 0.0000e+00 1.4305e-06 7633118;6271687
90
+ ------------------------------------------------------------------------------------------------------------------------
91
+
92
+ Legend:
93
+ Outliers: 1 Standard Deviation from Mean; 1.5 IQR (InterQuartile Range) from 1st Quartile and 3rd Quartile.
94
+ ````
95
+ ## Performance
96
+ ````console
97
+ --------------------------------------------------------- benchmark 'Inverse Radon Transform on MNIST test dataset': 3 tests ---------------------------------------------------------
98
+ Name (time in s) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
99
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
100
+ skimage (CPU) 18.7919 (206.14) 18.8811 (167.55) 18.8254 (197.13) 0.0346 (4.10) 18.8162 (204.12) 0.0433 (39.79) 1;0 0.0531 (0.01) 5 1
101
+ torchskradon (CPU) 5.0316 (55.20) 5.2680 (46.75) 5.1462 (53.89) 0.0983 (11.64) 5.1858 (56.26) 0.1541 (141.53) 2;0 0.1943 (0.02) 5 1
102
+ torchskradon (GPU) 0.0912 (1.0) 0.1127 (1.0) 0.0955 (1.0) 0.0084 (1.0) 0.0922 (1.0) 0.0011 (1.0) 1;1 10.4715 (1.0) 6 1
103
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
104
+
105
+ ------------------------------------------------------------- benchmark 'Radon Transform on MNIST test dataset': 3 tests ------------------------------------------------------------
106
+ Name (time in s) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
107
+ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
108
+ skimage (CPU) 39.3553 (72.82) 40.3932 (73.88) 39.6877 (73.08) 0.4297 (178.15) 39.4695 (72.65) 0.5418 (173.05) 1;0 0.0252 (0.01) 5 1
109
+ torchskradon (CPU) 12.2509 (22.67) 12.3949 (22.67) 12.3444 (22.73) 0.0604 (25.03) 12.3783 (22.78) 0.0845 (27.00) 1;0 0.0810 (0.04) 5 1
110
+ torchskradon (GPU) 0.5405 (1.0) 0.5467 (1.0) 0.5431 (1.0) 0.0024 (1.0) 0.5433 (1.0) 0.0031 (1.0) 2;0 1.8413 (1.0) 5 1
111
+ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
112
+
113
+ Legend:
114
+ Outliers: 1 Standard Deviation from Mean; 1.5 IQR (InterQuartile Range) from 1st Quartile and 3rd Quartile.
115
+ OPS: Operations Per Second, computed as 1 / Mean
116
+ ````
117
+ You can run benchmarks yourself by running:
118
+ ```console
119
+ python -m pytest --benchmark-only --benchmark-sort="name"
120
+ ```
121
+ ## Other Packages
122
+ For users interested in more flexible implementations of projection transforms check out:
123
+
124
+ 1. [`ASTRA Toolbox`](https://github.com/astra-toolbox/astra-toolbox)
125
+
126
+ 2. [`torch-radon`](https://github.com/matteo-ronchetti/torch-radon)
127
+ ## Acknowledgements
128
+ This package is inspired by implementations of the Radon transform and its' inverse in [`skimage.transform`](https://github.com/scikit-image/scikit-image/tree/main/src/skimage/transform), which are based on [1-3].
129
+
130
+ ## References
131
+ 1. JK Romberg, ["Image Projections and the Radon Transform"](https://www.clear.rice.edu/elec431/projects96/DSP/bpanalysis.html)
132
+
133
+ 2. AC Kak, M Slaney, “Principles of Computerized Tomographic Imaging”, IEEE Press 1988.
134
+
135
+ 3. 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
@@ -0,0 +1,96 @@
1
+ # torchskradon
2
+
3
+ [![LICENSE](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) [![Python](https://img.shields.io/badge/python-3.10%20|%203.11%20|%203.12-blue)](#) [![PyPI](https://img.shields.io/pypi/v/torchskradon.svg?label=PyPI&logo=pypi)](https://pypi.org/project/torchskradon/) [![CI](https://github.com/tomluetjen/torchskradon/actions/workflows/python-app.yml/badge.svg?branch=main)](https://github.com/tomluetjen/torchskradon/actions/workflows/python-app.yml) [![Coverage](https://codecov.io/gh/tomluetjen/torchskradon/branch/main/graph/badge.svg)](https://codecov.io/gh/tomluetjen/torchskradon)
4
+
5
+
6
+ ## About
7
+ `torchskradon` mimics the implementation of [`radon`](https://scikit-image.org/docs/stable/api/skimage.transform.html#skimage.transform.radon) and [`iradon`](https://scikit-image.org/docs/stable/api/skimage.transform.html#skimage.transform.iradon) from [`scikit-image`](https://scikit-image.org). 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`](https://docs.pytorch.org/docs/stable/optim.html) (see [examples](#examples)).
8
+
9
+ ## Installation
10
+ ```console
11
+ pip install torchskradon
12
+ ```
13
+
14
+ ## Basic Usage
15
+ ```python
16
+ import torch
17
+ from skimage.data import shepp_logan_phantom
18
+ from skimage.transform import rescale
19
+ from torchskradon.functional import skradon, skiradon
20
+
21
+ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
22
+
23
+ image = shepp_logan_phantom()
24
+ image = rescale(image, scale=0.4, mode='reflect', channel_axis=None)
25
+ image = torch.from_numpy(image).unsqueeze(0).unsqueeze(0).to(device)
26
+ theta = torch.linspace(0.0, 180.0, max(image.size()[2:])+1)[:-1].to(device)
27
+ sinogram = skradon(image, theta=theta)
28
+ reconstruction_fbp = skiradon(sinogram, theta=theta, filter_name='ramp')
29
+ ```
30
+
31
+ ## Examples
32
+ For more detailed examples and use cases, see the `examples` directory:
33
+
34
+ - [`examples/plot_radon_transform.py`](examples/plot_radon_transform.py) - Basic forward and inverse Radon transforms
35
+ - [`examples/ct_model.ipynb`](examples/ct_model.ipynb) - Model-based CT reconstruction
36
+
37
+ ## Accuracy
38
+ ````console
39
+ ----------------------- Absolute Error of Inverse Radon Transform on MNIST test dataset: 2 tests -----------------------
40
+ Name Min Max Mean StdDev Median IQR Outliers
41
+ ------------------------------------------------------------------------------------------------------------------------
42
+ torchskradon (CPU) 0.0000e+00 2.0862e-06 3.1433e-07 2.1123e-07 2.5891e-07 2.5879e-07 2117701;247180
43
+ torchskradon (GPU) 0.0000e+00 1.9670e-06 1.3048e-07 1.0576e-07 1.0803e-07 1.1735e-07 1800730;379622
44
+ ------------------------------------------------------------------------------------------------------------------------
45
+
46
+ --------------------------- Absolute Error of Radon Transform on MNIST test dataset: 2 tests ---------------------------
47
+ Name Min Max Mean StdDev Median IQR Outliers
48
+ ------------------------------------------------------------------------------------------------------------------------
49
+ torchskradon (CPU) 0.0000e+00 6.2466e-05 1.0514e-06 1.9718e-06 0.0000e+00 1.4305e-06 7713886;6355122
50
+ torchskradon (GPU) 0.0000e+00 6.1989e-05 1.0435e-06 1.9558e-06 0.0000e+00 1.4305e-06 7633118;6271687
51
+ ------------------------------------------------------------------------------------------------------------------------
52
+
53
+ Legend:
54
+ Outliers: 1 Standard Deviation from Mean; 1.5 IQR (InterQuartile Range) from 1st Quartile and 3rd Quartile.
55
+ ````
56
+ ## Performance
57
+ ````console
58
+ --------------------------------------------------------- benchmark 'Inverse Radon Transform on MNIST test dataset': 3 tests ---------------------------------------------------------
59
+ Name (time in s) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
60
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
61
+ skimage (CPU) 18.7919 (206.14) 18.8811 (167.55) 18.8254 (197.13) 0.0346 (4.10) 18.8162 (204.12) 0.0433 (39.79) 1;0 0.0531 (0.01) 5 1
62
+ torchskradon (CPU) 5.0316 (55.20) 5.2680 (46.75) 5.1462 (53.89) 0.0983 (11.64) 5.1858 (56.26) 0.1541 (141.53) 2;0 0.1943 (0.02) 5 1
63
+ torchskradon (GPU) 0.0912 (1.0) 0.1127 (1.0) 0.0955 (1.0) 0.0084 (1.0) 0.0922 (1.0) 0.0011 (1.0) 1;1 10.4715 (1.0) 6 1
64
+ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
65
+
66
+ ------------------------------------------------------------- benchmark 'Radon Transform on MNIST test dataset': 3 tests ------------------------------------------------------------
67
+ Name (time in s) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
68
+ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
69
+ skimage (CPU) 39.3553 (72.82) 40.3932 (73.88) 39.6877 (73.08) 0.4297 (178.15) 39.4695 (72.65) 0.5418 (173.05) 1;0 0.0252 (0.01) 5 1
70
+ torchskradon (CPU) 12.2509 (22.67) 12.3949 (22.67) 12.3444 (22.73) 0.0604 (25.03) 12.3783 (22.78) 0.0845 (27.00) 1;0 0.0810 (0.04) 5 1
71
+ torchskradon (GPU) 0.5405 (1.0) 0.5467 (1.0) 0.5431 (1.0) 0.0024 (1.0) 0.5433 (1.0) 0.0031 (1.0) 2;0 1.8413 (1.0) 5 1
72
+ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
73
+
74
+ Legend:
75
+ Outliers: 1 Standard Deviation from Mean; 1.5 IQR (InterQuartile Range) from 1st Quartile and 3rd Quartile.
76
+ OPS: Operations Per Second, computed as 1 / Mean
77
+ ````
78
+ You can run benchmarks yourself by running:
79
+ ```console
80
+ python -m pytest --benchmark-only --benchmark-sort="name"
81
+ ```
82
+ ## Other Packages
83
+ For users interested in more flexible implementations of projection transforms check out:
84
+
85
+ 1. [`ASTRA Toolbox`](https://github.com/astra-toolbox/astra-toolbox)
86
+
87
+ 2. [`torch-radon`](https://github.com/matteo-ronchetti/torch-radon)
88
+ ## Acknowledgements
89
+ This package is inspired by implementations of the Radon transform and its' inverse in [`skimage.transform`](https://github.com/scikit-image/scikit-image/tree/main/src/skimage/transform), which are based on [1-3].
90
+
91
+ ## References
92
+ 1. JK Romberg, ["Image Projections and the Radon Transform"](https://www.clear.rice.edu/elec431/projects96/DSP/bpanalysis.html)
93
+
94
+ 2. AC Kak, M Slaney, “Principles of Computerized Tomographic Imaging”, IEEE Press 1988.
95
+
96
+ 3. 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
@@ -0,0 +1,71 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "torchskradon"
7
+ version = "0.1.0"
8
+ description = "A differentiable implementation of scikit-image's Radon transform and filtered backprojection in PyTorch"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = { text = "MIT" }
12
+ authors = [{ name = "Tom Lütjen", email = "tom.luetjen@icloud.com" }]
13
+ keywords = ["pytorch", "skimage", "radon", "tomography"]
14
+ classifiers = [
15
+ "Development Status :: 4 - Beta",
16
+ "Intended Audience :: Developers",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Programming Language :: Python :: 3 :: Only",
19
+ "Programming Language :: Python :: 3.10",
20
+ "Programming Language :: Python :: 3.11",
21
+ "Programming Language :: Python :: 3.12",
22
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
23
+ ]
24
+
25
+ dependencies = ["torch>=2.2"]
26
+
27
+ [project.optional-dependencies]
28
+ tests = [
29
+ "torchvision>=0.17",
30
+ "ruff>=0.6.9",
31
+ "scikit-image>=0.22",
32
+ "matplotlib>=3.8",
33
+ "pytest>=8.2",
34
+ "pytest-benchmark>=4.0",
35
+ "pytest-cov>=5.0",
36
+ ]
37
+ dev = [
38
+ "torchvision>=0.17",
39
+ "ruff>=0.6.9",
40
+ "scikit-image>=0.22",
41
+ "matplotlib>=3.8",
42
+ "pytest>=8.2",
43
+ "pytest-benchmark>=4.0",
44
+ "pytest-cov>=5.0",
45
+ ]
46
+
47
+ [project.urls]
48
+ Repository = "https://github.com/tomluetjen/torchskradon.git"
49
+ Issues = "https://github.com/tomluetjen/torchskradon/issues"
50
+
51
+ [tool.setuptools.packages.find]
52
+ where = ["."]
53
+ include = ["torchskradon*"]
54
+ exclude = ["tests*", "examples*", "benchmarks*"]
55
+
56
+ [tool.ruff]
57
+ line-length = 100
58
+ target-version = "py310"
59
+ exclude = ["*.ipynb"]
60
+
61
+ [tool.ruff.lint]
62
+ select = ["E", "F", "I", "B", "UP"]
63
+ ignore = ["E203", "E501"]
64
+
65
+ [tool.ruff.lint.isort]
66
+ known-first-party = ["torchskradon"]
67
+
68
+ [tool.pytest.ini_options]
69
+ python_files = ["test_*.py", "benchmark_*.py"]
70
+ python_functions = ["test_*", "benchmark_*"]
71
+ testpaths = ["tests", "benchmarks"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+