Skip to content

Commit

Permalink
Add colour.XYZ_to_CIE1976UCS and colour.CIE1976UCS_to_XYZ definit…
Browse files Browse the repository at this point in the history
…ions.
  • Loading branch information
KelSolaar committed May 13, 2024
1 parent 3b2803b commit 2e17f12
Show file tree
Hide file tree
Showing 7 changed files with 369 additions and 10 deletions.
20 changes: 12 additions & 8 deletions colour/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@
CAM16SCD_to_XYZ,
CAM16UCS_to_JMh_CAM16,
CAM16UCS_to_XYZ,
CIE1976UCS_to_XYZ,
CMY_to_CMYK,
CMY_to_RGB,
CMYK_to_CMY,
Expand Down Expand Up @@ -362,6 +363,7 @@
XYZ_to_CAM16LCD,
XYZ_to_CAM16SCD,
XYZ_to_CAM16UCS,
XYZ_to_CIE1976UCS,
XYZ_to_DIN99,
XYZ_to_hdr_CIELab,
XYZ_to_hdr_IPT,
Expand Down Expand Up @@ -648,19 +650,20 @@
]
__all__ += [
"CAM02LCD_to_JMh_CIECAM02",
"CAM02SCD_to_JMh_CIECAM02",
"CAM02UCS_to_JMh_CIECAM02",
"CAM02LCD_to_XYZ",
"CAM02SCD_to_JMh_CIECAM02",
"CAM02SCD_to_XYZ",
"CAM02UCS_to_JMh_CIECAM02",
"CAM02UCS_to_XYZ",
"CAM16LCD_to_JMh_CAM16",
"CAM16SCD_to_JMh_CAM16",
"CAM16UCS_to_JMh_CAM16",
"CAM16LCD_to_XYZ",
"CAM16SCD_to_JMh_CAM16",
"CAM16SCD_to_XYZ",
"CAM16UCS_to_JMh_CAM16",
"CAM16UCS_to_XYZ",
"CCTF_DECODINGS",
"CCTF_ENCODINGS",
"CIE1976UCS_to_XYZ",
"CMYK_to_CMY",
"CMY_to_CMYK",
"CMY_to_RGB",
Expand All @@ -683,10 +686,10 @@
"ICtCp_to_RGB",
"ICtCp_to_XYZ",
"IHLS_to_RGB",
"IgPgTg_to_XYZ",
"IPT_Ragoo2021_to_XYZ",
"IPT_hue_angle",
"IPT_to_XYZ",
"IPT_Ragoo2021_to_XYZ",
"IgPgTg_to_XYZ",
"JMh_CAM16_to_CAM16LCD",
"JMh_CAM16_to_CAM16SCD",
"JMh_CAM16_to_CAM16UCS",
Expand Down Expand Up @@ -742,14 +745,15 @@
"XYZ_to_CAM16LCD",
"XYZ_to_CAM16SCD",
"XYZ_to_CAM16UCS",
"XYZ_to_CIE1976UCS",
"XYZ_to_DIN99",
"XYZ_to_Hunter_Lab",
"XYZ_to_Hunter_Rdab",
"XYZ_to_ICaCb",
"XYZ_to_ICtCp",
"XYZ_to_IgPgTg",
"XYZ_to_IPT",
"XYZ_to_IPT_Ragoo2021",
"XYZ_to_IgPgTg",
"XYZ_to_Jzazbz",
"XYZ_to_K_ab_HunterLab1966",
"XYZ_to_Lab",
Expand All @@ -760,12 +764,12 @@
"XYZ_to_RGB",
"XYZ_to_UCS",
"XYZ_to_UVW",
"XYZ_to_Yrg",
"XYZ_to_hdr_CIELab",
"XYZ_to_hdr_IPT",
"XYZ_to_sRGB",
"XYZ_to_xy",
"XYZ_to_xyY",
"XYZ_to_Yrg",
"YCbCr_to_RGB",
"YCoCg_to_RGB",
"YcCbcCrc_to_RGB",
Expand Down
4 changes: 4 additions & 0 deletions colour/graph/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
CAM16LCD_to_JMh_CAM16,
CAM16SCD_to_JMh_CAM16,
CAM16UCS_to_JMh_CAM16,
CIE1976UCS_to_XYZ,
CMY_to_CMYK,
CMY_to_RGB,
CMYK_to_CMY,
Expand Down Expand Up @@ -129,6 +130,7 @@
UCS_to_XYZ,
UCS_uv_to_xy,
UVW_to_XYZ,
XYZ_to_CIE1976UCS,
XYZ_to_DIN99,
XYZ_to_hdr_CIELab,
XYZ_to_hdr_IPT,
Expand Down Expand Up @@ -672,6 +674,8 @@ def mired_to_CCT_D_uv(mired: ArrayLike) -> NDArrayFloat:
("CIE xy", "CIE Luv uv", xy_to_Luv_uv),
("CIE Luv", "CIE LCHuv", Luv_to_LCHuv),
("CIE LCHuv", "CIE Luv", LCHuv_to_Luv),
("CIE 1976 UCS", "CIE XYZ", CIE1976UCS_to_XYZ),
("CIE XYZ", "CIE 1976 UCS", XYZ_to_CIE1976UCS),
("CIE XYZ", "CIE UCS", XYZ_to_UCS),
("CIE UCS", "CIE XYZ", UCS_to_XYZ),
("CIE UCS", "CIE UCS uv", UCS_to_uv),
Expand Down
4 changes: 4 additions & 0 deletions colour/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
xy_to_Luv_uv,
Luv_to_LCHuv,
LCHuv_to_Luv,
XYZ_to_CIE1976UCS,
CIE1976UCS_to_XYZ,
)
from .cie_ucs import (
XYZ_to_UCS,
Expand Down Expand Up @@ -429,6 +431,8 @@
"xy_to_Luv_uv",
"Luv_to_LCHuv",
"LCHuv_to_Luv",
"XYZ_to_CIE1976UCS",
"CIE1976UCS_to_XYZ",
]
__all__ += [
"XYZ_to_UCS",
Expand Down
112 changes: 112 additions & 0 deletions colour/models/cie_luv.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
- :func:`colour.xy_to_Luv_uv`
- :func:`colour.Luv_to_LCHuv`
- :func:`colour.LCHuv_to_Luv`
- :func:`colour.XYZ_to_CIE1976UCS`
- :func:`colour.CIE1976UCS_to_XYZ`
References
----------
Expand Down Expand Up @@ -66,6 +68,8 @@
"xy_to_Luv_uv",
"Luv_to_LCHuv",
"LCHuv_to_Luv",
"XYZ_to_CIE1976UCS",
"CIE1976UCS_to_XYZ",
]


Expand Down Expand Up @@ -534,3 +538,111 @@ def LCHuv_to_Luv(LCHuv: ArrayLike) -> NDArrayFloat:
"""

return JCh_to_Jab(LCHuv)


def XYZ_to_CIE1976UCS(
XYZ: ArrayLike,
illuminant: ArrayLike = CCS_ILLUMINANTS["CIE 1931 2 Degree Standard Observer"][
"D65"
],
) -> NDArrayFloat:
"""
Convert from *CIE XYZ* tristimulus values to :math:`uv^pL\\*` colourspace.
This colourspace combines the :math:`uv^p` chromaticity coordinates with
the *Lightness* :math:`L\\*` from the *CIE L\\*u\\*v\\** colourspace.
It is a convenient definition to use with the
*CIE 1976 UCS Chromaticity Diagram*.
Parameters
----------
XYZ
*CIE XYZ* tristimulus values.
illuminant
Reference *illuminant* *CIE xy* chromaticity coordinates or *CIE xyY*
colourspace array.
Returns
-------
:class:`numpy.ndarray`
:math:`uv^pL\\*` colourspace array.
Notes
-----
+----------------+-----------------------+-----------------+
| **Domain** | **Scale - Reference** | **Scale - 1** |
+================+=======================+=================+
| ``XYZ`` | [0, 1] | [0, 1] |
+----------------+-----------------------+-----------------+
| ``illuminant`` | [0, 1] | [0, 1] |
+----------------+-----------------------+-----------------+
Examples
--------
>>> import numpy as np
>>> XYZ = np.array([0.20654008, 0.12197225, 0.05136952])
>>> XYZ_to_CIE1976UCS(XYZ) # doctest: +ELLIPSIS
array([ 0.3772021..., 0.5012026..., 41.5278752...])
"""

Luv = XYZ_to_Luv(XYZ, illuminant)

L, _u, _v = tsplit(Luv)

u, v = tsplit(Luv_to_uv(Luv, illuminant))

return tstack([u, v, L])


def CIE1976UCS_to_XYZ(
uvL: ArrayLike,
illuminant: ArrayLike = CCS_ILLUMINANTS["CIE 1931 2 Degree Standard Observer"][
"D65"
],
) -> NDArrayFloat:
"""
Convert from *CIE XYZ* tristimulus values to :math:`uv^pL\\*` colourspace.
This colourspace combines the :math:`uv^p` chromaticity coordinates with
the *Lightness* :math:`L\\*` from the *CIE L\\*u\\*v\\** colourspace.
It is a convenient definition to use with the
*CIE 1976 UCS Chromaticity Diagram*.
Parameters
----------
uvL
:math:`uv^pL\\*` colourspace array.
illuminant
Reference *illuminant* *CIE xy* chromaticity coordinates or *CIE xyY*
colourspace array.
Returns
-------
:class:`numpy.ndarray`
:math:`uv^pL\\*` colourspace array.
Notes
-----
+----------------+-----------------------+-----------------+
| **Domain** | **Scale - Reference** | **Scale - 1** |
+================+=======================+=================+
| ``XYZ`` | [0, 1] | [0, 1] |
+----------------+-----------------------+-----------------+
| ``illuminant`` | [0, 1] | [0, 1] |
+----------------+-----------------------+-----------------+
Examples
--------
>>> import numpy as np
>>> uvL = np.array([0.37720213, 0.50120264, 41.52787529])
>>> CIE1976UCS_to_XYZ(uvL) # doctest: +ELLIPSIS
array([ 0.2065400..., 0.1219722..., 0.0513695...])
"""

u, v, L = tsplit(uvL)

_L, u, v = tsplit(uv_to_Luv(tstack([u, v]), illuminant, L))

return Luv_to_XYZ(tstack([L, u, v]), illuminant)
3 changes: 3 additions & 0 deletions colour/models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"CAM16LCD",
"CAM16SCD",
"CAM16UCS",
"CIE 1976 UCS",
"CIE Lab",
"CIE Luv",
"CIE UCS",
Expand Down Expand Up @@ -106,6 +107,7 @@
"CAM16LCD": ("$J^'$", "$a^'$", "$b^'$"),
"CAM16SCD": ("$J^'$", "$a^'$", "$b^'$"),
"CAM16UCS": ("$J^'$", "$a^'$", "$b^'$"),
"CIE 1976 UCS": ("$u^'$", "$v^'$", "$L^*$"),
"CIE Lab": ("$L^*$", "$a^*$", "$b^*$"),
"CIE Luv": ("$L^*$", "$u^'$", "$v^'$"),
"CIE UCS": ("U", "V", "W"),
Expand Down Expand Up @@ -148,6 +150,7 @@
"CAM16LCD": np.array([100, 100, 100]),
"CAM16SCD": np.array([100, 100, 100]),
"CAM16UCS": np.array([100, 100, 100]),
"CIE 1976 UCS": np.array([1, 1, 100]),
"CIE Lab": np.array([100, 100, 100]),
"CIE Luv": np.array([100, 100, 100]),
"CIE UCS": np.array([1, 1, 1]),
Expand Down
Loading

0 comments on commit 2e17f12

Please sign in to comment.