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.1.tar.gz (9.9 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.1-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

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

Hashes for torchcdt-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0b2e9b3af07315af84e6ce5d00882e408e720ebbb381639a21b6629e41117330
MD5 a6da41c3eb5009f0466e46293865dd7b
BLAKE2b-256 fdfc9765b62f2216892488b6a98220baf91a907988c0f676ca39fb8a3c7781dd

See more details on using hashes here.

Provenance

The following attestation bundles were made for torchcdt-0.1.1.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.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

Hashes for torchcdt-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6058199dd727c3ba6dc73f77da0e7de4415cae026c6f5233b07021ac3b6d6f55
MD5 61b67746ba76f6290a5dd6d060d2921c
BLAKE2b-256 f3eabf4d63530c30211b41793823d204479eb5506a68db29ca1bb35f1d870434

See more details on using hashes here.

Provenance

The following attestation bundles were made for torchcdt-0.1.1-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