How to convert an array of JMh or Jab values to XYZ? #859
Replies: 3 comments
-
I'm trying to understand the issue here, is the problem that R does not let you create the CAM specifications? We are using some convenience code to do that in the Automatic Colour Conversion Graph: def CIECAM02_to_JMh_CIECAM02(CAM_Specification_CIECAM02):
"""
Converts from *CIECAM02* specification to *CIECAM02* :math:`JMh`
correlates.
Parameters
----------
CAM_Specification_CIECAM02 : CAM_Specification_CIECAM02
*CIECAM02* colour appearance model specification.
Returns
-------
ndarray
*CIECAM02* :math:`JMh` correlates.
Examples
--------
>>> specification = CAM_Specification_CIECAM02(J=41.731091132513917,
... M=0.108842175669226,
... h=219.048432658311780)
>>> CIECAM02_to_JMh_CIECAM02(specification) # doctest: +ELLIPSIS
array([ 4.1731091...e+01, 1.0884217...e-01, 2.1904843...e+02])
"""
return tstack([
CAM_Specification_CIECAM02.J,
CAM_Specification_CIECAM02.M,
CAM_Specification_CIECAM02.h,
])
def JMh_CIECAM02_to_CIECAM02(JMh):
"""
Converts from *CIECAM02* :math:`JMh` correlates to *CIECAM02*
specification.
Parameters
----------
JMh : array_like
*CIECAM02* :math:`JMh` correlates.
Returns
-------
CAM_Specification_CIECAM02
*CIECAM02* colour appearance model specification.
Examples
--------
>>> import numpy as np
>>> JMh = np.array([4.17310911e+01, 1.08842176e-01, 2.19048433e+02])
>>> JMh_CIECAM02_to_CIECAM02(JMh) # doctest: +ELLIPSIS
CAM_Specification_CIECAM02(J=41.7310911..., C=None, h=219.0484329..., \
s=None, Q=None, M=0.1088421..., H=None, HC=None)
"""
J, M, h = tsplit(JMh)
return CAM_Specification_CIECAM02(J=J, M=M, h=h)
def CAM16_to_JMh_CAM16(CAM_Specification_CAM16):
"""
Converts from *CAM16* specification to *CAM16* :math:`JMh` correlates.
Parameters
----------
CAM_Specification_CAM16 : CAM_Specification_CAM16
*CAM16* colour appearance model specification.
Returns
-------
ndarray
*CAM16* :math:`JMh` correlates.
Examples
--------
>>> specification = CAM_Specification_CAM16(J=41.731207905126638,
... M=0.107436772335905,
... h=217.067959767393010)
>>> CAM16_to_JMh_CAM16(specification) # doctest: +ELLIPSIS
array([ 4.1731207...e+01, 1.0743677...e-01, 2.1706796...e+02])
"""
return tstack([
CAM_Specification_CAM16.J,
CAM_Specification_CAM16.M,
CAM_Specification_CAM16.h,
])
def JMh_CAM16_to_CAM16(JMh):
"""
Converts from *CAM6* :math:`JMh` correlates to *CAM6* specification.
Parameters
----------
JMh : array_like
*CAM6* :math:`JMh` correlates.
Returns
-------
CAM6_Specification
*CAM6* colour appearance model specification.
Examples
--------
>>> import numpy as np
>>> JMh = np.array([4.17312079e+01, 1.07436772e-01, 2.17067960e+02])
>>> JMh_CAM16_to_CAM16(JMh) # doctest: +ELLIPSIS
CAM_Specification_CAM16(J=41.7312079..., C=None, h=217.06796..., s=None, \
Q=None, M=0.1074367..., H=None, HC=None)
"""
J, M, h = tsplit(JMh)
return CAM_Specification_CAM16(J=J, M=M, h=h) Would that help? |
Beta Was this translation helpful? Give feedback.
-
What I mean is, you know how the Lab_to_XYZ function takes an array of CIELab values and returns XYZ, and you can feed any Lab values you want to it? The CAM16_to_XYZ only takes the specification and returns the XYZ values originally used to create it. However, I am applying curves and the like to the JMh or Jab (which I am working with depends on what I am doing) as part of creating some custom color LUTs and am unable to do convert my modified values back to XYZ. Likewise, I also discovered that RLab lacks an RLab_to_XYZ function entirely. Is there a way to do that conversion? Figured I'd mention it here instead of opening up another thread. |
Beta Was this translation helpful? Give feedback.
-
The last definition in the code I quoted above should do the conversion, then you can pass the specification to def JMh_CAM16_to_CAM16(JMh):
J, M, h = tsplit(JMh)
return CAM_Specification_CAM16(J=J, M=M, h=h) As for |
Beta Was this translation helpful? Give feedback.
-
I have arrays of JMh & corresponding Jab values that I want to convert to XYZ.
What I am doing is going from an sRGB cube LUT --- > Linear RGB --- > [Insert a colorspace here, in this case, CIECAM16/02] ---> Adjust some values to make manual LUT adjustments by hand (apply curves to specific combinations of J, M, h, etc) -- > XYZ --> Linear RGB --> sRGB.
In the case of working with something like Lab it's simple to do those steps to convert RGB->Lab->Lch->Lab->XYZ->RGB or whatever, but the only XYZ functions related to CIECAM seem to be only capable of taking a specification object and spitting back out the xyz values used to create it.
I am using Python via the Reticulate package in RStudio, so I don't know if there's some odd behavior masking a function capable of doing this or what but from what I can tell it seems like there's no Jab02 or Jab16 conversion to XYZ
Beta Was this translation helpful? Give feedback.
All reactions