cutcutcodec.core.colorspace.func.convert

cutcutcodec.core.colorspace.func.convert(src: str, dst: str) tuple[Basic, Basic, Basic][source]

Return the symbolic expression to convert colorspace.

Parameters

src, dststr

The source and destination colorspace formatted as {name}[_{colorspace}]. with name in « y’bpbr », « r’g’b” », « rgb », « xyz ».

Returns

componantstuple[sympy.core.basic.Basic, sympy.core.basic.Basic, sympy.core.basic.Basic]

The 3 sympy equations that link the input color space components, to each of the output components.

Notes

When several names are given, the first matching is taken.

Examples

>>> import sympy, torch
>>> from cutcutcodec.core.colorspace.func import convert
>>> from cutcutcodec.core.colorspace.cst import SYMBS
>>> from cutcutcodec.core.compilation.sympy_to_torch.lambdify import Lambdify
>>> convert("y'pbpr_bt709", "r'g'b'_bt709")[0]
645014*p_r/409605 + y'
>>> trans_symb = convert("y'pbpr_bt709", "y'pbpr_bt2020")
>>> trans_symb = trans_symb.subs(zip(SYMBS["y'pbpr"], sympy.symbols("y u v", real=True)))
>>> trans_func = Lambdify(trans_symb)
>>> yuv_709 = torch.rand(1_000_000), torch.rand(1_000_000)-0.5, torch.rand(1_000_000)-0.5
>>> yuv_2020 = trans_func(y=yuv_709[0], u=yuv_709[1], v=yuv_709[2])
>>>