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
Metadata
Release files for torchcdt 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| torchcdt-0.1.1.tar.gz | 9.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| torchcdt-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.1 kB
Release files / torchcdt-0.1.1.tar.gz
| Download URL | torchcdt-0.1.1.tar.gz |
|---|---|
| Size | 9.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0b2e9b3af07315af84e6ce5d00882e408e720ebbb381639a21b6629e41117330
|
|
BLAKE2b-256 checksum How to use checksums |
fdfc9765b62f2216892488b6a98220baf91a907988c0f676ca39fb8a3c7781dd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 26, 2026.
Transparency logRelease files / torchcdt-0.1.1-py3-none-any.whl
| Download URL | torchcdt-0.1.1-py3-none-any.whl |
|---|---|
| Size | 7.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6058199dd727c3ba6dc73f77da0e7de4415cae026c6f5233b07021ac3b6d6f55
|
|
BLAKE2b-256 checksum How to use checksums |
f3eabf4d63530c30211b41793823d204479eb5506a68db29ca1bb35f1d870434
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 26, 2026.
Transparency log