Coverage for models/ragoo2021.py: 8%
25 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-16 22:49 +1300
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-16 22:49 +1300
1"""
2Ragoo and Farup (2021) Optimised IPT Colourspace
3================================================
5Define the *Ragoo and Farup (2021)* *Optimised IPT* colourspace
6transformations.
8- :func:`colour.XYZ_to_IPT_Ragoo2021`
9- :func:`colour.IPT_Ragoo2021_to_XYZ`
11References
12----------
13- :cite:`Ragoo2021` : Ragoo, L., & Farup, I. (2021). Optimising a Euclidean
14 Colour Space Transform for Colour Order and Perceptual Uniformity.
15 Color and Imaging Conference, 29(1), 282-287.
16 doi:10.2352/issn.2169-2629.2021.29.282
17"""
19from __future__ import annotations
21from functools import partial
23import numpy as np
25from colour.algebra import spow
26from colour.hints import ( # noqa: TC001
27 Domain1,
28 NDArrayFloat,
29 Range1,
30)
31from colour.models import Iab_to_XYZ, XYZ_to_Iab
33__author__ = "Colour Developers"
34__copyright__ = "Copyright 2013 Colour Developers"
35__license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"
36__maintainer__ = "Colour Developers"
37__email__ = "colour-developers@colour-science.org"
38__status__ = "Production"
40__all__ = [
41 "MATRIX_IPT_XYZ_TO_LMS",
42 "MATRIX_IPT_LMS_TO_XYZ",
43 "MATRIX_IPT_LMS_P_TO_IPT",
44 "MATRIX_IPT_IPT_TO_LMS_P",
45 "XYZ_to_IPT_Ragoo2021",
46 "IPT_Ragoo2021_to_XYZ",
47]
49MATRIX_IPT_XYZ_TO_LMS: NDArrayFloat = np.array(
50 [
51 [0.4321, 0.6906, -0.0930],
52 [-0.1793, 1.1458, 0.0226],
53 [0.0631, 0.1532, 0.7226],
54 ]
55)
56"""*CIE XYZ* tristimulus values to normalised cone responses matrix."""
58MATRIX_IPT_LMS_TO_XYZ: NDArrayFloat = np.linalg.inv(MATRIX_IPT_XYZ_TO_LMS)
59"""Normalised cone responses to *CIE XYZ* tristimulus values matrix."""
61MATRIX_IPT_LMS_P_TO_IPT: NDArrayFloat = np.array(
62 [
63 [0.3037, 0.6688, 0.0276],
64 [3.9247, -4.7339, 0.8093],
65 [1.5932, -0.5205, -1.0727],
66 ]
67)
68"""
69Normalised non-linear cone responses to *Ragoo and Farup (2021)*
70*Optimised IPT* colourspace matrix.
71"""
73MATRIX_IPT_IPT_TO_LMS_P: NDArrayFloat = np.linalg.inv(MATRIX_IPT_LMS_P_TO_IPT)
74"""
75*Ragoo and Farup (2021)* *Optimised IPT* colourspace to normalised
76non-linear cone responses matrix.
77"""
80def XYZ_to_IPT_Ragoo2021(XYZ: Domain1) -> Range1:
81 """
82 Convert from *CIE XYZ* tristimulus values to *Ragoo and Farup (2021)*
83 *Optimised IPT* colourspace.
85 Parameters
86 ----------
87 XYZ
88 *CIE XYZ* tristimulus values.
90 Returns
91 -------
92 :class:`numpy.ndarray`
93 *Ragoo and Farup (2021)* *Optimised IPT* colourspace array.
95 Notes
96 -----
97 +------------+-----------------------+-----------------+
98 | **Domain** | **Scale - Reference** | **Scale - 1** |
99 +============+=======================+=================+
100 | ``XYZ`` | 1 | 1 |
101 +------------+-----------------------+-----------------+
103 +------------+-----------------------+-----------------+
104 | **Range** | **Scale - Reference** | **Scale - 1** |
105 +============+=======================+=================+
106 | ``IPT`` | 1 | 1 |
107 +------------+-----------------------+-----------------+
109 - Input *CIE XYZ* tristimulus values must be adapted to
110 *CIE Standard Illuminant D Series* *D65*.
112 References
113 ----------
114 :cite:`Ragoo2021`
116 Examples
117 --------
118 >>> XYZ = np.array([0.20654008, 0.12197225, 0.05136952])
119 >>> XYZ_to_IPT_Ragoo2021(XYZ) # doctest: +ELLIPSIS
120 array([ 0.4224824..., 0.2910514..., 0.2041066...])
121 """
123 return XYZ_to_Iab(
124 XYZ,
125 partial(spow, p=0.4071),
126 MATRIX_IPT_XYZ_TO_LMS,
127 MATRIX_IPT_LMS_P_TO_IPT,
128 )
131def IPT_Ragoo2021_to_XYZ(
132 IPT: Domain1,
133) -> Range1:
134 """
135 Convert from *Ragoo and Farup (2021)* *Optimised IPT* colourspace to
136 *CIE XYZ* tristimulus values.
138 Parameters
139 ----------
140 IPT
141 *Ragoo and Farup (2021)* *Optimised IPT* colourspace array.
143 Returns
144 -------
145 :class:`numpy.ndarray`
146 *CIE XYZ* tristimulus values.
148 Notes
149 -----
150 +------------+-----------------------+-----------------+
151 | **Domain** | **Scale - Reference** | **Scale - 1** |
152 +============+=======================+=================+
153 | ``IPT`` | 1 | 1 |
154 +------------+-----------------------+-----------------+
156 +------------+-----------------------+-----------------+
157 | **Range** | **Scale - Reference** | **Scale - 1** |
158 +============+=======================+=================+
159 | ``XYZ`` | 1 | 1 |
160 +------------+-----------------------+-----------------+
162 References
163 ----------
164 :cite:`Ragoo2021`
166 Examples
167 --------
168 >>> IPT = np.array([0.42248243, 0.2910514, 0.20410663])
169 >>> IPT_Ragoo2021_to_XYZ(IPT) # doctest: +ELLIPSIS
170 array([ 0.2065400..., 0.1219722..., 0.0513695...])
171 """
173 return Iab_to_XYZ(
174 IPT,
175 partial(spow, p=1 / 0.4071),
176 MATRIX_IPT_IPT_TO_LMS_P,
177 MATRIX_IPT_LMS_TO_XYZ,
178 )