torchskradon


Nametorchskradon JSON
Version 0.1.0 PyPI version JSON
download
home_pageNone
SummaryA differentiable implementation of scikit-image's Radon transform and filtered backprojection in PyTorch
upload_time2025-10-19 09:28:44
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseMIT
keywords pytorch skimage radon tomography
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # torchskradon

[![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)


## About
`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)).

## Installation
```console
pip install torchskradon
```

## Basic Usage
```python
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`](examples/plot_radon_transform.py) - Basic forward and inverse Radon transforms
- [`examples/ct_model.ipynb`](examples/ct_model.ipynb) - Model-based CT reconstruction

## Accuracy
````console
----------------------- 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.0862e-06    3.1433e-07    2.1123e-07    2.5891e-07    2.5879e-07 2117701;247180
torchskradon (GPU)        0.0000e+00    1.9670e-06    1.3048e-07    1.0576e-07    1.0803e-07    1.1735e-07 1800730;379622
------------------------------------------------------------------------------------------------------------------------

--------------------------- 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 
````console
--------------------------------------------------------- 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)          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
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
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
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

------------------------------------------------------------- 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)          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
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
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
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

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:
```console
  python -m pytest --benchmark-only --benchmark-sort="name"
```
## Other Packages
For users interested in more flexible implementations of projection transforms check out:

1. [`ASTRA Toolbox`](https://github.com/astra-toolbox/astra-toolbox)

2. [`torch-radon`](https://github.com/matteo-ronchetti/torch-radon)
## Acknowledgements
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].

## References
1. JK Romberg, ["Image Projections and the Radon Transform"](https://www.clear.rice.edu/elec431/projects96/DSP/bpanalysis.html)

2. AC Kak, M Slaney, “Principles of Computerized Tomographic Imaging”, IEEE Press 1988.

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  

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "torchskradon",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "pytorch, skimage, radon, tomography",
    "author": null,
    "author_email": "Tom L\u00fctjen <tom.luetjen@icloud.com>",
    "download_url": "https://files.pythonhosted.org/packages/7b/47/4416b21f652dad0b4f5bae10b654db3a2d8c9699d50cf4da8df24b2df0bf/torchskradon-0.1.0.tar.gz",
    "platform": null,
    "description": "# torchskradon\n\n[![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)\n\n\n## About\n`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)).\n\n## Installation\n```console\npip install torchskradon\n```\n\n## Basic Usage\n```python\nimport torch\nfrom skimage.data import shepp_logan_phantom\nfrom skimage.transform import rescale\nfrom torchskradon.functional import skradon, skiradon\n\ndevice = torch.device('cuda' if torch.cuda.is_available() else 'cpu')\n\nimage = shepp_logan_phantom()\nimage = rescale(image, scale=0.4, mode='reflect', channel_axis=None)\nimage = torch.from_numpy(image).unsqueeze(0).unsqueeze(0).to(device)\ntheta = torch.linspace(0.0, 180.0, max(image.size()[2:])+1)[:-1].to(device)\nsinogram = skradon(image, theta=theta)\nreconstruction_fbp = skiradon(sinogram, theta=theta, filter_name='ramp')\n```\n\n## Examples\nFor more detailed examples and use cases, see the `examples` directory:\n\n- [`examples/plot_radon_transform.py`](examples/plot_radon_transform.py) - Basic forward and inverse Radon transforms\n- [`examples/ct_model.ipynb`](examples/ct_model.ipynb) - Model-based CT reconstruction\n\n## Accuracy\n````console\n----------------------- Absolute Error of Inverse Radon Transform on MNIST test dataset: 2 tests -----------------------\nName                             Min           Max          Mean        StdDev        Median           IQR      Outliers\n------------------------------------------------------------------------------------------------------------------------\ntorchskradon (CPU)        0.0000e+00    2.0862e-06    3.1433e-07    2.1123e-07    2.5891e-07    2.5879e-07 2117701;247180\ntorchskradon (GPU)        0.0000e+00    1.9670e-06    1.3048e-07    1.0576e-07    1.0803e-07    1.1735e-07 1800730;379622\n------------------------------------------------------------------------------------------------------------------------\n\n--------------------------- Absolute Error of Radon Transform on MNIST test dataset: 2 tests ---------------------------\nName                             Min           Max          Mean        StdDev        Median           IQR      Outliers\n------------------------------------------------------------------------------------------------------------------------\ntorchskradon (CPU)        0.0000e+00    6.2466e-05    1.0514e-06    1.9718e-06    0.0000e+00    1.4305e-06 7713886;6355122\ntorchskradon (GPU)        0.0000e+00    6.1989e-05    1.0435e-06    1.9558e-06    0.0000e+00    1.4305e-06 7633118;6271687\n------------------------------------------------------------------------------------------------------------------------\n\nLegend:\n  Outliers: 1 Standard Deviation from Mean; 1.5 IQR (InterQuartile Range) from 1st Quartile and 3rd Quartile.\n````\n## Performance \n````console\n--------------------------------------------------------- benchmark 'Inverse Radon Transform on MNIST test dataset': 3 tests ---------------------------------------------------------\nName (time in s)           Min                Max               Mean            StdDev             Median               IQR            Outliers      OPS            Rounds  Iterations\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\nskimage (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\ntorchskradon (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\ntorchskradon (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\n--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n\n------------------------------------------------------------- benchmark 'Radon Transform on MNIST test dataset': 3 tests ------------------------------------------------------------\nName (time in s)           Min                Max               Mean            StdDev             Median               IQR            Outliers     OPS            Rounds  Iterations\n-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\nskimage (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\ntorchskradon (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\ntorchskradon (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\n-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n\nLegend:\n  Outliers: 1 Standard Deviation from Mean; 1.5 IQR (InterQuartile Range) from 1st Quartile and 3rd Quartile.\n  OPS: Operations Per Second, computed as 1 / Mean\n````\nYou can run benchmarks yourself by running:\n```console\n  python -m pytest --benchmark-only --benchmark-sort=\"name\"\n```\n## Other Packages\nFor users interested in more flexible implementations of projection transforms check out:\n\n1. [`ASTRA Toolbox`](https://github.com/astra-toolbox/astra-toolbox)\n\n2. [`torch-radon`](https://github.com/matteo-ronchetti/torch-radon)\n## Acknowledgements\nThis 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].\n\n## References\n1. JK Romberg, [\"Image Projections and the Radon Transform\"](https://www.clear.rice.edu/elec431/projects96/DSP/bpanalysis.html)\n\n2. AC Kak, M Slaney, \u201cPrinciples of Computerized Tomographic Imaging\u201d, IEEE Press 1988.\n\n3. B.R. Ramesh, N. Srinivasa, K. Rajgopal, \u201cAn Algorithm for Computing the Discrete Radon Transform With Some Applications\u201d, Proceedings of the Fourth IEEE Region 10 International Conference, TENCON \u201889, 1989  \n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A differentiable implementation of scikit-image's Radon transform and filtered backprojection in PyTorch",
    "version": "0.1.0",
    "project_urls": {
        "Issues": "https://github.com/tomluetjen/torchskradon/issues",
        "Repository": "https://github.com/tomluetjen/torchskradon.git"
    },
    "split_keywords": [
        "pytorch",
        " skimage",
        " radon",
        " tomography"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "d74e2763c751a102c2bdfecb37307c0ad4fc5c72938e2d510182d0e3b71fdfdf",
                "md5": "5b71012587acdee0a26ffe59a8c969c3",
                "sha256": "8eaf20d65462edb8d60fc2f4485be04ac7d48f63872b4d488319a26b00c30061"
            },
            "downloads": -1,
            "filename": "torchskradon-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5b71012587acdee0a26ffe59a8c969c3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 9159,
            "upload_time": "2025-10-19T09:28:42",
            "upload_time_iso_8601": "2025-10-19T09:28:42.985995Z",
            "url": "https://files.pythonhosted.org/packages/d7/4e/2763c751a102c2bdfecb37307c0ad4fc5c72938e2d510182d0e3b71fdfdf/torchskradon-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "7b474416b21f652dad0b4f5bae10b654db3a2d8c9699d50cf4da8df24b2df0bf",
                "md5": "57932fd3ff408a6b12d419bd8fe82b5a",
                "sha256": "e52ef23d83f4d1205f7bbbff1c4b64489ca07449282eac3120744bf7b03e3643"
            },
            "downloads": -1,
            "filename": "torchskradon-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "57932fd3ff408a6b12d419bd8fe82b5a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 15951,
            "upload_time": "2025-10-19T09:28:44",
            "upload_time_iso_8601": "2025-10-19T09:28:44.343533Z",
            "url": "https://files.pythonhosted.org/packages/7b/47/4416b21f652dad0b4f5bae10b654db3a2d8c9699d50cf4da8df24b2df0bf/torchskradon-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-10-19 09:28:44",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "tomluetjen",
    "github_project": "torchskradon",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "torchskradon"
}
        
Elapsed time: 1.04645s