colour
colour copied to clipboard
[FEATURE]: Add "Oklch" colourspace.
Description
Oklab and Oklch has been added to CSS Color Module Level 4. But, only Oklab is available for Colour.
Adding Oklch will be great for convenience.
Hi @dofuuz,
There is already an issue for this here: https://github.com/colour-science/colour/issues/868
Cheers,
Thomas
@KelSolaar Oklch is different from Okhsl or Okhsv. So it's not a duplicate.
Ah yes sorry, my bad! I misread the space name... We probably won't implement this one because it is a simple polar representation that we can perform on any "Jab" like spaces: https://github.com/colour-science/colour/blob/develop/colour/models/common.py#L163
my_oklch = colour.models.Jab_to_JCh(my_oklab)
@KelSolaar Oh, I didn't know that conversion function exists. I searched for 'lab to lch'. 🤣
Anyway, providing 'Oklch' would be nice for convenience. I'll leave the decision to the contributors.
This is a good discussion. If we do it for Oklab or JzAzBz, we might as well do it for IPT, ICtCp, ICaCb, ProLab, etc... we have so much opponent-based spaces that it becomes quite a maintenance burden as we ideally need to write tests, docs, etc.., this is why I rolled the colour.models.Jab_to_JCh
and its inverse definitions.
i agree that there is value in doing this. But I wonder if it can be done by decoration with a "metaclass" or some other meta programming. (please forgive the reference to a very specific C++ concept in a much more general meaning)
Something along those lines would work for example but it gets close to a steam factory rapidly:
import colour
import sys
from colour.models import Jab_to_JCh, JCh_to_Jab
from colour.utilities import copy_definition
__all__ = []
CALLABLES_LCH = {
"Oklab_to_Oklch": (Jab_to_JCh, "The docstring..."),
"Oklch_to_Oklab": (JCh_to_Jab, "The docstring..."),
}
for name, (callable_, docstring) in CALLABLES_LCH.items():
callable_.__doc__ = docstring
_module = sys.modules["colour.models"]
setattr(_module, name, copy_definition(callable_, name))
print(colour.models.JCh_to_Jab)
print(colour.models.JCh_to_Jab.__name__)
print(colour.models.Oklch_to_Oklab)
print(colour.models.Oklch_to_Oklab.__name__)
<function JCh_to_Jab at 0x13c204220>
JCh_to_Jab
<function JCh_to_Jab at 0x11ce60680>
Oklch_to_Oklab
We have something magic like that here actually: https://github.com/colour-science/colour-datasets/blob/develop/colour_datasets/loaders/kuopio.py#L498
I think there is something you could do in the oklab module to automatically define the variable names too. Something like
add_polar_conversion_this_module("Oklab", "Oklch")
i use oklch quite regularly, and if i was provided a full list of spaces that fall under this category i would be willing to add them to the graph manually Oklab, JzAzBz, IPT, ICtCp, ICaCb, ProLab were mentioned so far
This was implemented! :)
Great, can this be expected to appear on the README graph and on PyPi? I tried making a graph with networkx/matplotlib but the nodes overlap, so my guess is another tool was used for it prior. I updated my pyproject to pull the library from github, so no pressure on publishing.
The graph is generated here: https://github.com/colour-science/colour/blob/develop/utilities/generate_plots.py#L166
That being said, I can see that the last build failed on RtD. I will check what is going on.
Note that I will refine some names in a future commit, Oklch
won't change though!