Skip to main content

build

colortrans

An implementation of various algorithms for transferring the colors from a reference image to a content image while preserving the qualitative appearance of the content image (i.e., color transfer).

Installation

Requirements

  • Python 3.8 or greater (earlier versions may work, but are not tested)

Install

$ pip3 install colortrans

Update

$ pip3 install --upgrade colortrans

Command-Line Usage

The program can be used from the command line.

The general command line usage is shown below.

$ colortrans [--method METHOD] [--single-precision] CONTENT REFERENCE OUTPUT

CONTENT is the path to the content image, REFERENCE is the path to the style image, and OUTPUT is the path to save the output image.

METHOD specifies the color transfer algorithm. The following methods are supported:

  1. lhm Linear Histogram Matching [1] (default)
  2. pccm Principal Components Color Matching [2, 3]
  3. reinhard Reinhard et al. [4]

If the optional --single-precision flag is present, 32-bit floats will be used instead of 64-bit floats.

If the launcher script was not installed within a directory on your PATH, colortrans can be launched by passing its module name to Python.

$ python3 -m colortrans [--method METHOD] CONTENT REFERENCE OUTPUT

Library Usage

The algorithms can also be used directly from Python programs. Each of the methods listed above has a corresponding function, transfer_METHOD, taking two NumPy arrays corresponding to the content and reference image, respectively. The arrays have HxWxC data ordering (channels-last). The functions also take an optional keyword argument, single_precision, a boolean that specifies whether 32-bit floats will be used instead of 64-bit floats (defaults to False).

Example

import colortrans
import numpy as np
from PIL import Image

# Load data
with Image.open('/path/to/content.jpg') as img:
    content = np.array(img.convert('RGB'))
with Image.open('/path/to/reference.jpg') as img:
    reference = np.array(img.convert('RGB'))

# Transfer colors using different algorithms
output_lhm = colortrans.transfer_lhm(content, reference)
output_pccm = colortrans.transfer_pccm(content, reference)
output_reinhard = colortrans.transfer_reinhard(content, reference)

# Save outputs
Image.fromarray(output_lhm).save('/path/to/output_lhm.jpg')
Image.fromarray(output_pccm).save('/path/to/output_pccm.jpg')
Image.fromarray(output_reinhard).save('/path/to/output_reinhard.jpg')

References

[1] Hertzmann, Aaron. "Algorithms for Rendering in Artistic Styles." Ph.D., New York University, 2001.

[2] Kotera, Hiroaki, Hung-Shing Chen, and Tetsuro Morimoto. "Object-to-Object Color Mapping by Image Segmentation." In Color Imaging: Device-Independent Color, Color Hardcopy, and Graphic Arts IV, 3648:148–57. SPIE, 1998.

[3] Kotera, Hiroaki. "A Scene-Referred Color Transfer for Pleasant Imaging on Display." In IEEE International Conference on Image Processing 2005, 2:II–5, 2005.

[4] Reinhard, Erik, Michael Adhikhmin, Bruce Gooch, and Peter Shirley. "Color Transfer between Images." IEEE Computer Graphics and Applications 21, no. 5 (July 2001): 34–41.

Release files for colortrans 1.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 colortrans 1.1.0
File Size Uploaded
colortrans-1.1.0.tar.gz 6.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for colortrans 1.1.0
File Interpreter ABI Platform
colortrans-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.3 kB

Release files / colortrans-1.1.0.tar.gz

Download URL colortrans-1.1.0.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
ba74ef9cac2b1de5070e80021dd790b1176885f0d2a28eacd47786b381dec1f8
BLAKE2b-256 checksum
How to use checksums
2ea3b502c4c28d689aae3a032b5893c7b86debea1a1a463d169b86928c79e5e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Release files / colortrans-1.1.0-py3-none-any.whl

Download URL colortrans-1.1.0-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
87b9d7ffea3ddffb20d57d0404906f6e822795f2178463730ef385351a23b05b
BLAKE2b-256 checksum
How to use checksums
354e38bd8f7a223de4e500eeb519855189289fd16b48902c449b31681fc17077
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.0

2 release files

0.0.1

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