A differentiable implementation of the (Radon-) Cumulative Distribution Transform in PyTorch
Project description
torchcdt
About
torchcdt implements the (Radon-) Cumulative Distribution Transform [1, 2] and its' inverse with different normalization approaches [3, 4] to enhance feature extraction. All transforms work with batched multi-channel data and are fully differentiable. This allows backpropagation through torchcdt transforms to train neural networks or to solve optimization problems with torch.optim (see examples).
Installation
pip install torchcdt
Basic Usage
import matplotlib.pyplot as plt
import torch
from torchskradon.functional import skradon
import torchcdt.helpers as helpers
from torchcdt.functional import ircdt, rcdt
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
N = 128
s = torch.zeros((1, 1, N, N), device=device)
x = torch.linspace(-10, 10, N, device=device)
y = torch.linspace(-10, 10, N, device=device)
xx, yy = torch.meshgrid(x, y, indexing="ij")
x = x.unsqueeze(0)
y = y.unsqueeze(0)
xx = xx.unsqueeze(0)
yy = yy.unsqueeze(0)
s[0, 0] = torch.exp(-(xx**2 + yy**2) / 2) / (2 * torch.pi)
# This is not needed unless we want the reconstruction to have the exact same scaling
s = helpers.make_positive_density(s, dim=(-2, -1), eps=1e-6)
s_sinogram = skradon(s, circle=False)
fig, axs = plt.subplots(1, 2, figsize=(15, 5))
axs[0].imshow(s[0, 0].cpu().numpy())
axs[0].set_title("Input image")
axs[1].imshow(s_sinogram[0, 0].cpu().numpy())
axs[1].set_title("Sinogram")
plt.show()
s_hat = rcdt(s, circle=False)
s_reco = ircdt(s_hat, circle=False)
fig, ax = plt.subplots(1, 2, figsize=(15, 5))
ax[0].imshow(s_hat[0, 0].cpu().numpy())
ax[0].set_title("R-CDT")
ax[1].imshow(s_reco[0, 0].cpu().numpy())
ax[1].set_title("Reconstructed image")
plt.show()
Examples
For more detailed examples and use cases, see the examples directory:
examples/cdt_properties.py- Basic properties of forward and inverse CDT transformsexamples/linmnist_classifictation.ipynb- SVM classification of LinMNIST dataset
Other Packages
This package is inspired by
Acknowledgements
I would like to thank Dr. Matthias Beckmann for his supervision and guidance during a reading course on this topic.
References
-
Park SR, Kolouri S, Kundu S, Rohde GK, "The cumulative distribution transform and linear pattern classification", Applied and Computational Harmonic Analysis, 2017
-
Kolouri S, Park SR, Rohde GK, "The Radon Cumulative Distribution Transform and Its Application to Image Classification", IEEE transactions on image processing, 2016
-
Beckmann M, Beinert R, Bresch J, "Max-Normalized Radon Cumulative Distribution Transform for Limited Data Classification", International Conference on Scale Space and Variational Methods in Computer Vision (SSVM), 2025
-
Beckmann M, Beinert R, Bresch J, "Normalized Radon Cumulative Distribution Transforms for Invariance and Robustness in Optimal Transport Based Image Classification", International Conference on Scale Space and Variational Methods in Computer Vision (SSVM), 2025
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 torchcdt-0.1.1.tar.gz.
File metadata
- Download URL: torchcdt-0.1.1.tar.gz
- Upload date:
- Size: 9.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b2e9b3af07315af84e6ce5d00882e408e720ebbb381639a21b6629e41117330
|
|
| MD5 |
a6da41c3eb5009f0466e46293865dd7b
|
|
| BLAKE2b-256 |
fdfc9765b62f2216892488b6a98220baf91a907988c0f676ca39fb8a3c7781dd
|
Provenance
The following attestation bundles were made for torchcdt-0.1.1.tar.gz:
Publisher:
python-publish.yml on tomluetjen/torchcdt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torchcdt-0.1.1.tar.gz -
Subject digest:
0b2e9b3af07315af84e6ce5d00882e408e720ebbb381639a21b6629e41117330 - Sigstore transparency entry: 1391778124
- Sigstore integration time:
-
Permalink:
tomluetjen/torchcdt@be9b7ddc69b1e7f2667de9f6b721bf4a55db0080 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/tomluetjen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@be9b7ddc69b1e7f2667de9f6b721bf4a55db0080 -
Trigger Event:
release
-
Statement type:
File details
Details for the file torchcdt-0.1.1-py3-none-any.whl.
File metadata
- Download URL: torchcdt-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.2 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 |
6058199dd727c3ba6dc73f77da0e7de4415cae026c6f5233b07021ac3b6d6f55
|
|
| MD5 |
61b67746ba76f6290a5dd6d060d2921c
|
|
| BLAKE2b-256 |
f3eabf4d63530c30211b41793823d204479eb5506a68db29ca1bb35f1d870434
|
Provenance
The following attestation bundles were made for torchcdt-0.1.1-py3-none-any.whl:
Publisher:
python-publish.yml on tomluetjen/torchcdt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torchcdt-0.1.1-py3-none-any.whl -
Subject digest:
6058199dd727c3ba6dc73f77da0e7de4415cae026c6f5233b07021ac3b6d6f55 - Sigstore transparency entry: 1391778127
- Sigstore integration time:
-
Permalink:
tomluetjen/torchcdt@be9b7ddc69b1e7f2667de9f6b721bf4a55db0080 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/tomluetjen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@be9b7ddc69b1e7f2667de9f6b721bf4a55db0080 -
Trigger Event:
release
-
Statement type: