Skip to main content

A differentiable implementation of the (Radon-) Cumulative Distribution Transform in PyTorch

Project description

torchcdt

LICENSE Python PyPI CI Coverage

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:

Other Packages

This package is inspired by

  1. PyTransKit

  2. Cumulative-Distribution-Transform

  3. Radon-Cumulative-Distribution-Transform

  4. NR-CDT

Acknowledgements

I would like to thank Dr. Matthias Beckmann for his supervision and guidance during a reading course on this topic.

References

  1. Park SR, Kolouri S, Kundu S, Rohde GK, "The cumulative distribution transform and linear pattern classification", Applied and Computational Harmonic Analysis, 2017

  2. Kolouri S, Park SR, Rohde GK, "The Radon Cumulative Distribution Transform and Its Application to Image Classification", IEEE transactions on image processing, 2016

  3. 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

  4. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

torchcdt-0.1.0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

torchcdt-0.1.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file torchcdt-0.1.0.tar.gz.

File metadata

  • Download URL: torchcdt-0.1.0.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for torchcdt-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9d9c150c4c4ede2f08269f8058d51f840c3cb9456306b9a9893fc073acf460f8
MD5 782805ae039e7565cebbe4416754a5b1
BLAKE2b-256 53093a81c800fba337f31bee1ed49eeea0b4e9a836b35338d1760aefaa1f0882

See more details on using hashes here.

Provenance

The following attestation bundles were made for torchcdt-0.1.0.tar.gz:

Publisher: python-publish.yml on tomluetjen/torchcdt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file torchcdt-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: torchcdt-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for torchcdt-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e0aa4091a235052312f6565e6df95de62b6b746a6b26ff00d0ed9abbbe5f6399
MD5 03247045b2915d8d4e8ccd7ab2bfadaf
BLAKE2b-256 42d08f282673e0f35ac53ead7f99bbc82c01080ac82a5c6216ae8787d8295cb1

See more details on using hashes here.

Provenance

The following attestation bundles were made for torchcdt-0.1.0-py3-none-any.whl:

Publisher: python-publish.yml on tomluetjen/torchcdt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page