lcms2.Transform

class Transform(src: Any, *args: Any, intent: Any = Intent.RELATIVE_COLORIMETRIC, flags: Any = None, proof: Any = None, proof_intent: Any = Intent.RELATIVE_COLORIMETRIC, gamut_check: bool = False, bpc: bool | Sequence[bool] = False, optimize: bool = True, precision: str = 'auto', adaptation: Sequence[float] | None = None)[source]

Bases: object

A colour transform from one profile to another (or through a chain of profiles).

Pixel formats are inferred from each input array (dtype, channel count, alpha) and one LittleCMS transform is cached per format pair. The explicit form with format strings, Transform(src, "RGB_8", dst, "RGB_16"), fixes the formats instead.

Parameters:
  • src (Profile, str, path or list of those) – Source profile; a list makes a multi-profile transform (dst omitted).

  • dst (Profile, str or path) – Destination profile.

  • intent (Intent, str or int, or one per profile) – Rendering intent: "relative" (default; in-gamut colors unchanged), "perceptual", "saturation" or "absolute".

  • bpc (bool or one per profile) – Black point compensation.

  • proof (Profile, optional) – Proofing profile: simulate proof on dst (soft proofing).

  • proof_intent (intent) – Intent from the source to the proofing device (0-3).

  • gamut_check (bool) – Mark colours outside the proof gamut with the alarm colour (see set_alarm_codes()).

  • optimize (bool) – Allow LittleCMS to precalculate (False adds NOOPTIMIZE).

  • precision ({"auto", "high", "low"}) – Precalculation table size.

  • flags (Flag, int or str) – Any other cmsFLAGS_*.

  • adaptation (sequence of float, optional) – Per-profile adaptation states (makes an extended transform).

Raises:

CMSError – When LittleCMS cannot build the transform (e.g. incompatible profiles).

Examples

>>> import numpy as np, lcms2
>>> t = lcms2.Transform("sRGB", "Lab", intent="relative")
>>> t(np.array([255, 0, 0], np.uint8)).round(2)
array([54.29, 80.81, 69.89])
>>> t = lcms2.Transform(lcms2.Profile("sRGB"), "RGB_8", lcms2.Profile("Lab"), "Lab_DBL")
>>> t.apply([255, 255, 255]).round(3) + 0.0
array([100.,   0.,   0.])
__init__(src: Any, *args: Any, intent: Any = Intent.RELATIVE_COLORIMETRIC, flags: Any = None, proof: Any = None, proof_intent: Any = Intent.RELATIVE_COLORIMETRIC, gamut_check: bool = False, bpc: bool | Sequence[bool] = False, optimize: bool = True, precision: str = 'auto', adaptation: Sequence[float] | None = None) → None[source]

Methods

__init__(src, *args[, intent, flags, proof, ...])

apply(data[, out, out_dtype])

Transform pixel data; the last axis holds the channels.

to_device_link([version, flags])

A device link profile equivalent to this transform.

Attributes

input_format

Explicit input format name, or None when formats are inferred.

input_profile

The first profile.

output_format

Explicit output format name, or None when formats are inferred.

output_profile

The last profile.

property input_profile: Profile

The first profile.

property output_profile: Profile

The last profile.

property input_format: str | None

Explicit input format name, or None when formats are inferred.

property output_format: str | None

Explicit output format name, or None when formats are inferred.

apply(data: Any, out: ndarray | None = None, *, out_dtype: DTypeLike = None) → ndarray[source]

Transform pixel data; the last axis holds the channels.

Parameters:
  • data (array-like) – (..., channels) pixels ((H, W) works for gray). Lists of ints become uint8/uint16, floats float64. Non-contiguous input is copied.

  • out (numpy.ndarray, optional) – Preallocated C-contiguous output of the right shape and dtype.

  • out_dtype (dtype, optional) – Output dtype (inferred transforms only). Default: the input dtype, except integer input into Lab/XYZ which gives float64.

Returns:

numpy.ndarray – The transformed pixels (out when given).

Examples

>>> import lcms2
>>> t = lcms2.Transform("sRGB", "sRGB")
>>> t.apply([[0, 128, 255]])
array([[  0, 128, 255]], dtype=uint8)

A device link profile equivalent to this transform.

Examples

>>> import lcms2
>>> link = lcms2.Transform("sRGB", "Lab").to_device_link()
>>> str(link.device_class)
'link'