Skip to main content

colortransfer-triton

简体中文 · Installation · API · Methods · Benchmark

ColorTransfer Triton implements AdaIN, Wavelet, Sliced OT, Sinkhorn and ColorFM-O color transfer with Triton GPU kernels and a PyTorch tensor API. No pretrained weights.

Qualitative examples

Two aligned color transfer comparisons

Figure 1. Aligned pairs: Astronaut cool-cast recovery and Chelsea warm grading.

Two different-content color transfer comparisons

Figure 2. Different-content pairs: Astronaut → Coffee and Coffee → Chelsea.

Get started

Linux, Python 3.10+, NVIDIA GPU, CUDA PyTorch 2.6+ and compatible Triton 3.2+.

python -m pip install -e .

Python

import torch
import colortransfer_triton as ct

source = torch.rand(1, 3, 512, 512, device="cuda")  # replace with RGB images
reference = torch.rand_like(source)
result = ct.adain(source, reference)
result = ct.transfer(source, reference, method="sliced_ot")

lut = ct.fit_colorfm(source, reference, steps=700)
result = lut(source, strength=0.8)  # reuse without fitting again
Tensor Contract
source NCHW RGB, finite values in [0,1], CUDA float16/bfloat16/float32
reference Same device; batch size 1 or matching the source; spatial size may differ except for Wavelet
Output Same shape and device as the source, contiguous float32

The image API is inference-only; detach inputs that require gradients.

Methods

Method Mechanism When to use
ct.adain Match RGB channel means and variances independently Global color-cast and contrast adjustment
ct.wavelet Retain source high frequencies and replace low frequencies Restore color from a spatially aligned reference
ct.sliced_ot Repeatedly project colors onto random directions and match sorted values Match color distributions beyond channel statistics
ct.sinkhorn Entropy-regularized transport with a barycentric color map Joint RGB distribution matching with adjustable smoothing
ct.partial_sinkhorn Transport only part of the distribution mass References with colors that should not all be matched
ct.colorfm Fit a color velocity field and integrate its flow Nonlinear color mapping through per-pair optimization

Wavelet uses an undecimated, dilated binomial pyramid, not a Haar/DWT transform. Its reference must have the same dimensions and spatial alignment. The other methods match color distributions without spatial correspondence or semantic object matching.

ColorFM implements the nonsemantic ColorFM-O variant. It trains a small MLP from scratch for each pair using sampled RGB colors: no pretrained weights or segmentation model, but an optimization stage is required. AdaIN, Wavelet and the OT methods do not train a neural network.

OT/ColorFM use sampled fitting and a 3D LUT approximation. Reuse maps with ct.fit_lut or ct.fit_colorfm. strength controls blending; clamp=True clips to [0,1].

Reuse a color map

lut = ct.fit_lut(
    source,
    reference,
    method="sinkhorn",
    samples=1024,
    lut_size=33,
    epsilon=0.03,
    iterations=100,
    seed=0,
)
result = lut(source, strength=0.8)

Fitting runs on sampled colors; the full image uses Triton trilinear LUT lookup with fused blending and clipping. This avoids a full-resolution pixel-to-pixel transport matrix on large images. A fitted map can be applied at other resolutions, but remains specific to the fitted color distributions; refit when the scene or reference changes.

Key parameters

Parameter Default Effect
strength 1.0 Output blend in [0,1]; 0 retains the source, 1 applies the full transfer
Wavelet levels 5 More levels restrict replacement to coarser color variations
OT samples 1024 More samples improve distribution coverage; Sinkhorn matrix storage grows quadratically
lut_size 33 RGB grid edge length; table size grows cubically
OT iterations 32 / 100 Sliced OT projections / Sinkhorn updates
Sinkhorn epsilon 0.03 Larger values smooth transport; smaller values may require more iterations
Partial Sinkhorn mass 0.8 Fraction of distribution mass transported, not an output blend
ColorFM steps / samples 700 / 16384 Optimization steps and sampled colors
ColorFM ode_steps 5 Midpoint integration steps used to build the LUT

Sinkhorn convergence is available in lut.diagnostics as marginal_error; a fixed iteration count does not guarantee convergence.

Reproduce figures

python -m pip install -e ".[figures]"
python examples/color_transfer.py --suite --output assets --save-images
python examples/color_transfer.py --source source.png --reference reference.png --save-images

Benchmark

python benchmarks/benchmark.py --height 2160 --width 3840 --repeats 30
python benchmarks/benchmark.py --colorfm --repeats 5

Tests

python -m pip install -e ".[test,figures]"
python -m pytest -q

License

MIT. Example photographs from scikit-image: Astronaut (NASA, public domain), Chelsea (Stefan van der Walt, CC0), Coffee (Rachel Michetti, CC0).

Publishing

Version tags automatically build and publish to PyPI after CI passes. See RELEASING.md for one-time Trusted Publisher setup and release steps.

Metadata

Release files for colortransfer-triton 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for colortransfer-triton 0.1.0
File Size Uploaded
colortransfer_triton-0.1.0.tar.gz 77.0 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for colortransfer-triton 0.1.0
File Interpreter ABI Platform
colortransfer_triton-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 77.0 MB

Release files / colortransfer_triton-0.1.0.tar.gz

Download URL colortransfer_triton-0.1.0.tar.gz
Size 77.0 MB
Tags Source
SHA-256 checksum
How to use checksums
adc654c026c0e019e5f8adfdf0dcb1bf16c7e5714824a88f269de6cac99a6ef7
BLAKE2b-256 checksum
How to use checksums
1a013b3fb91e4b96c709acb3d750f1aeaec94d1d0ad729161a9525e2e09cf3f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 15, 2026.

Transparency log

Release files / colortransfer_triton-0.1.0-py3-none-any.whl

Download URL colortransfer_triton-0.1.0-py3-none-any.whl
Size 21.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
58dc64556d9febcc982b0dfd7610f09d8ab11e848cfa206b81321dff5d7e431f
BLAKE2b-256 checksum
How to use checksums
f79424290cd459d936d6204a685c2019f357dc7307d7d91730225fe8b455a029
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 15, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page