coloria-dev / coloria Goto Github PK
View Code? Open in Web Editor NEW:rainbow: Tools for color research
:rainbow: Tools for color research
The Data Readme states, under missing data,
M.R. Luo and B. Rigg, Chromaticity-discrimination ellipses for surface colours, Color Res. Appl. 11(1), 25-42 (1986).
bu there is a Luo-Rigg folder with that data. Or is this another dataset from the same paper?
Basic functions described in the project readme, such as
colorio.show_xy_gamut()
are missing.
Oklab was updated with a new lightness scale. See section "Intermission - a new lightness estimate for Oklab": https://bottosson.github.io/posts/colorpicker/
Does colorio use this rescaled version of oklab or not? This is important, because there is some ambguity now in how "oklab" is defined.
Hi again,
here python3 -m pip install https://github.com/nschloe/colorio/archive/master.zip
Building wheels for collected packages: colorio
Building wheel for colorio (PEP 517) ... done
Created wheel for colorio: filename=colorio-0.6.5-py3-none-any.whl size=136229 sha256=8c36713987a67955aaedc440cfa2ec585745eaaa9898d7ba080ac8de24ba0286
Stored in directory: /private/var/folders/nm/2psc68vd333ffgf21xp05t_40000gn/T/pip-ephem-wheel-cache-q05mo9m2/wheels/ad/9a/3b/ac10b724f443945bae92086cb643df4fa29d7cac7b4dd3ad38
Successfully built colorio
Installing collected packages: colorio
Successfully installed colorio-0.6.5
then simply try:
import colorio
colorspace = colorio.OKLAB()
colorspace.show_ebner_fairchild()
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.9/site-packages/colorio/_color_space.py", line 467, in show_ebner_fairchild
self.plot_ebner_fairchild()
File "/usr/local/lib/python3.9/site-packages/colorio/_color_space.py", line 489, in plot_ebner_fairchild
_plot_color_constancy_data(d, wp, self)
File "/usr/local/lib/python3.9/site-packages/colorio/_color_space.py", line 605, in _plot_color_constancy_data
k0 = colorspace.k0
AttributeError: 'OKLAB' object has no attribute 'k0'
I want to be able to convert from CAM16-UCS to sRGB1, and sRGB1 to CAM16-UCS. This doesn't look like this is directly supported (unless I am missing something?).
Hey Nico, first of all, thank you for your work. Secondly, I am a designer who lacks experience with perceptual uniform colour models (although it seems like designers should, we are rarely trained on colour appearance models). So, please forgive me if this is a stupid question.
You have mentioned the colour difference formulas for CIE76, CIE94, CIEDE2000 and CMC l:c. here but not CAM16-UCS, is there a reason for that?
Could you tell me how I can find the colour difference for the CAM16-UCS model, and the difference in lightness J′, colourfulness M′ and hue h′?
okl.from_xyz100(colorio.illuminants.whitepoints_cie1931["D65"])
gives cbrt(100)
times the expected result.
Indeed, the tests compare okl.from_xyz100(colorio.illuminants.whitepoints_cie1931["D65"] / 100)
to the expected result of [1, 0, 0]
instead.
Why the factor 100? Isn't that at odds with the XYZ100 in the function name?
Not sure what I am doing wrong... Here are the results of a couple things I used in the console. I'm not sure what the "self" arguments it wants should be.
`colorio.cs.OKLAB.from_xyz100(xyz100 = [[1.0497487, 1.0803128, 0.1222619]])
Traceback (most recent call last):
File "", line 1, in
colorio.cs.OKLAB.from_xyz100(xyz100 = [[1.0497487, 1.0803128, 0.1222619]])
TypeError: from_xyz100() missing 1 required positional argument: 'self'
colorio.cs.OKLAB.from_xyz100(xyz100 = [1.0497487, 1.0803128, 0.1222619])
Traceback (most recent call last):
File "", line 1, in
colorio.cs.OKLAB.from_xyz100(xyz100 = [1.0497487, 1.0803128, 0.1222619])
TypeError: from_xyz100() missing 1 required positional argument: 'self'`
We have encountered the following issue, which has been reproduced using a few independent RGB --> JzAzBz implementations (including colorio and https://github.com/quag/JzAzBz/blob/master/python3/srgb255ToJzAzBz.py) ---
The JzAzBz paper (https://doi.org/10.1364/OE.25.015131) seems to suggest that the coordinates should span roughly Jz in (0,1), Az in (-0.5, 0.5), Bz in (-0.5,0.5). However, when we explicitly map all RGB tuples in (0,255) x (0,255) x (0,255) to JzAzBz as follows, we find that (Jz, Az, Bz) span (0,0.167), (-0.09,1.09), (-0.156,0.115).
So we're wondering if the original paper renormalized their coordinates, or if there's a mistake on our end.
Extremely simplified code that demonstrates the basic issue:
import numpy as np
import colorio
colorspace = colorio.SrgbLinear()
colorspace2 = colorio.JzAzBz()
jzazbz_test = np.zeros((256,256,256,3))
for i in range(0,255):
for j in range(0,255):
for k in range(0,255):
jzazbz_test[i][j][k] = colorspace2.from_xyz100(colorspace.to_xyz100(colorspace.from_srgb1((i/255.,j/255.,k/255.))))
print('min Jz={}'.format(np.min(jzazbz_test[:,:,:,0])))
print('max Jz={}'.format(np.max(jzazbz_test[:,:,:,0])))
print('min Az={}'.format(np.min(jzazbz_test[:,:,:,1])))
print('max Az={}'.format(np.max(jzazbz_test[:,:,:,1])))
print('min Bz={}'.format(np.min(jzazbz_test[:,:,:,2])))
print('max Bz={}'.format(np.max(jzazbz_test[:,:,:,2])))
The HSL and HSV colorspaces do not have from_xyz100(xyz)
and to_xyz100(vals)
methods defined on them and can therefore not be used in conversions. Was this intentional?
Some classes (like CAM16) are missing a 'name' attribute. This raises an error when some functions (like the addition function defined in _color_coordinates.py) calls for the 'name' of an instance.
Hello. The README currently has the following line:
The images below all show the SRGB gamut in the respective color space.
… but there are no images below this. Please add the images. (Are they the same under the gh-pages
branch?)
For example, colorio.HSL().to_srgb1([0,0,1.0])
gives [0., 1., 1.], while expected result is [1., 1., 1.].
Hello, I don't know if this is a bug or expected, so forgive me if it's not.
I have this oklab value: array([0.56605844, 0.22076974, 0.10449413])
Turning into RGB gives me:
v = array([0.56605844, 0.22076974, 0.10449413])
oklab = colorio.cs.OKLAB()
oklab.to_rgb1(v)
# Out[8]: array([ 0.88944356, -0.17762959, 0.09417191])
Turning that into HSL gives me:
In [9]: hsl.from_rgb1(oklab.to_rgb1(v))
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
<ipython-input-9-dabd72bc0ca3> in <module>
----> 1 hsl.from_rgb1(oklab.to_rgb1(v))
~/.local/lib/python3.9/site-packages/colorio/cs/_hsl.py in from_rgb1(self, srgb1)
7 orig_shape = srgb.shape
8 srgb = srgb.reshape(3, -1)
----> 9 assert not np.any(srgb < 0.0)
10 assert not np.any(srgb > 1.0)
11
AssertionError:
Playing with OSA colorspace (porting to Clojure) and found that for black OSA colorio returns NaNs
>>> rgb.from_xyz100(osa.to_xyz100(osa.from_xyz100(rgb.to_xyz100([0,0,0]))))
array([nan, nan, nan])
This is caused by this division https://github.com/nschloe/colorio/blob/master/colorio/_osa.py#L38
I'm trying to convert HSV to RGB:
import numpy as np
import colorio
cs = colorio.cs.HSV()
h = np.array(0)
s, v = np.ones_like(h), np.ones_like(h)
cs.to_srgb1((h, s, v))
# array([0., 1., 0.])
With h=0
I was expecting array([1., 0., 0.])
. Thus the title question...
The calculation of the constant "m2" in _ictcp.py on line 20 is wrong:
It should be
self.m2 = 2523 / 4096 * 128
instead of
self.m2 = 2523 / 4096 / 128
>>> import colorio
>>> hsl = colorio.HSL().from_srgb1([1, 1, 1])
/home/user/.local/lib/python3.6/site-packages/colorio/_hsl.py:21: RuntimeWarning: invalid value encountered in true_divide
H[i] = 60 * (0 + (srgb[1][i] - srgb[2][i]) / diff[i])
>>> hsl
array([nan, 0., 1.0])
Is this a feature or a bug? It's true that hue is undefined if R=G=B, so returning NaN kind of makes sense. On the other hand, if this is an intentional choice, the warning should be suppressed.
Hi Nico,
First wanted to say thanks for creating and maintaining colorio. I just came across it and I think it will be extremely useful as I write my thesis on extended gamut (7-color ink sets) color stability compared to the typical 4-color (CMYK) ink sets. I opened up the create-readme-plots.py to familiarize myself with some of your tools and I came across a couple of things I'm hoping you can clarify for me.
I'm looking at lines 149-165:
# observer
srgb = colorio.cs.SrgbLinear()
xyz100 = colorio.cs.XYZ100()
cols = [
ColorCoordinates([30.0, 0.0, 0.0], xyz100).get_rgb1("clip"),
ColorCoordinates([0.0, 30.0, 0.0], xyz100).get_rgb1("clip"),
ColorCoordinates([0.0, 0.0, 30.0], xyz100).get_rgb1("clip"),
]
obs = colorio.observers.cie_1931_2()
plt.plot(obs.lmbda_nm, obs.data[0], color=cols[0], label="$\\overline{x}$")
plt.plot(obs.lmbda_nm, obs.data[1], color=cols[1], label="$\\overline{y}$")
plt.plot(obs.lmbda_nm, obs.data[2], color=cols[2], label="$\\overline{z}$")
plt.xlabel("wavelength [nm]")
plt.legend()
plt.savefig("cie-standard-observer-2.svg", transparent=True, bbox_inches="tight")
plt.show()
I believe the second line here should be srgb = colorio.cs.SRGBlinear()
now. It looks like RGB is now capitalized and the L is now lowercase in the src/colorio/cs/_srgb.py
(link to _srgb.py) Is that a correct assumption?
Now for my question. It looks like .get_rgb1()
no longer exists in _color_coordinates.py
(link to _color_coordinates.py). What should I be using here instead? If I look at the History of this file it looks like it once existed, but I can't figure out what I should be using instead now.
Thanks in advance!
Matt
Hi, I previously used _tools.plot_flat_gamut
to draw an (x, y) gamut with the monochromatic edge and sRGB triangle indicated. I see the latter feature was removed in commits de3c7fa and da26e54. It's not immediately obvious to me why this was removed, and whether it was removed outright or simply refactored. I can see that plot_xy_gamut
now does everything except the sRGB triangle.
What steps should I take to recreate the sRGB triangle? Is there a different function for this now, which I have missed?
Hi again,
Fresh install with a colorspace.save_visible_gamut() called need mesh dependency.
ModuleNotFoundError: No module named 'meshio'
Thanks
Fred
It would be great to have cat functions (cat02/cat16) to transform colors between white points. See for example https://ksmet1977.github.io/luxpy/build/html/color.html#luxpy.color.cat.apply.
As of March 18th, it appears that there's only one file in the repository and it's the ReadMe. The commit history also appears to have disappeared (only one commit). Was this intentional? Has this project moved to another location?
when trying to re-implement the model (typos) i couldn't get the reverse model to match input unless
y = (y_ + (self.g - 1) * x) / self.g
is changed to
y = ((z_ * self.b - z_ + x_) * self.g + (y_ - z_) * self.b + z_ - x_) / (self.b * self.g)
for example
XYZ_D65 = [0.4 0.5 0.6]
b = 1.15; g = 0.66
XʹYʹZ_D65 = [
(b * XYZ_D65[:,1] - (b - 1) * XYZ_D65[:,3])
g * XYZ_D65[:,2] - (g - 1) * XYZ_D65[:,1]
XYZ_D65[:,3]
]
output XʹYʹZ_D65
3-element Array{Float64,1}:
0.37
0.46599999999999997
0.6
as in paper
XYZ_D65 = [ #= so that may become horizontal array
=# (XʹYʹZ_D65[1,:] + (b-1)*XʹYʹZ_D65[3,:])/b #=
=# (XʹYʹZ_D65[2,:] + (g-1)*XʹYʹZ_D65[1,:])/g #=
=# XʹYʹZ_D65[3,:]
]
output
1×3 Array{Float64,2}:
0.4 0.515455 0.6
CAS version
XYZ_D65 = [ #= so that may become horizontal array
=# (XʹYʹZ_D65[1,:] + (b-1)*XʹYʹZ_D65[3,:])/b #=
=# ((XʹYʹZ_D65[3,:]*b - XʹYʹZ_D65[3,:] + XʹYʹZ_D65[1,:])*g + (XʹYʹZ_D65[2,:]-XʹYʹZ_D65[3,:])*b + XʹYʹZ_D65[3,:] - XʹYʹZ_D65[1,:])/(b*g) #=
=# XʹYʹZ_D65[3,:]
]
1×3 Array{Float64,2}:
0.4 0.5 0.6
algsys([X′_D₆₅=X_D₆₅*𝑏-Z_D₆₅*(𝑏-1),Y′_D₆₅=Y_D₆₅*𝑔-X_D₆₅*(𝑔-1)],[X_D₆₅,Y_D₆₅]);
outputs
[X_D₆₅=(Z_D₆₅*𝑏-Z_D₆₅+X′_D₆₅)/𝑏,Y_D₆₅=(X′_D₆₅*(𝑔-1)+Z_D₆₅*(1-𝑔)+𝑏*(Z_D₆₅*(𝑔-1)+Y′_D₆₅))/(𝑏*𝑔)]
in their defense i didn't bother to manually solve this, used a program instead
also guess this is a example where subtle things (X′_D₆₅ based on Z_D₆₅ , vs , Y′_D₆₅ based on X_D₆₅) …
I am getting the following errors when I try to install colorio on windows and ubuntu.
ERROR: Could not find a version that satisfies the requirement colorio (from versions: none)
ERROR: No matching distribution found for colorio.
Is the project discontinued? Looking forward to your reply.
With many thanks,
There's a floating-point underflow/rounding error in RGB-to-HSL conversion:
>>> colorio.cs.HSL().from_rgb1([1e-17, 0, 0])
<string>:38: RuntimeWarning: divide by zero encountered in true_divide
array([0.e+00, inf, 5.e-18])
>>> colorio.cs.HSL().from_rgb1([1e-16, 0, 0])
array([0.00000000e+00, 9.00719925e-01, 5.00000000e-17])
Probable cause: At float64 precision, (1.0 - 1e-17) == 1.0
is True, whereas (1.0 - 1e-16) == 1.0
is False.
Possible workaround: mask out not only zeros but also near-zeros before dividing.
Hello. Currently Colorio has support for a large number of colour systems, however support for the Munsell system is missing. To find how to do this I googled for “srgb to munsell” and arrived at the following links which may be useful:
Thanks!
HSL and HSV don't have attributes from_xyz100 causing an error when using with plot_rgb_gamut().
Using CIECAM02 and CAM16 with plot_rgb_gamut() causes a ValueError at line 48 in _rgb_gamut.py. At some point it makes an array with shape (140688,7) when it should be (X,3).
Traceback (most recent call last):
File "<pyshell#19>", line 1, in <module>
p = colorio.plot_rgb_gamut(colorspace, n=51, show_grid=True)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/colorio/_rgb_gamut.py", line 48, in plot_rgb_gamut
grid = pv.UnstructuredGrid(cells.ravel(), celltypes, cs_coords)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyvista/core/pointset.py", line 593, in __init__
self._from_arrays(None, args[0], args[1], args[2], deep)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyvista/core/pointset.py", line 698, in _from_arrays
points = pyvista.vtk_points(points, deep=deep)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyvista/utilities/helpers.py", line 270, in vtk_points
raise ValueError('Points array must contain three values per point. '
ValueError: Points array must contain three values per point. Shape is (140608, 7) and should be (X, 3)
using XYY and CIELUV shows some runtime warnings
Edit, here's the code I used to test it:
import math
import colorio
color_spaces = []
color_spaces.append(colorio.cs.XYZ(100))
color_spaces.append(colorio.cs.XYY(100))
#color_spaces.append(colorio.SrgbLinear()
#AttributeError: module 'colorio' has no attribute 'SrgbLinear'
color_spaces.append(colorio.cs.HSL())
color_spaces.append(colorio.cs.HSV())
color_spaces.append(colorio.cs.OsaUcs())
color_spaces.append(colorio.cs.CIELAB())
color_spaces.append(colorio.cs.CIELUV())
color_spaces.append(colorio.cs.RLAB())
color_spaces.append(colorio.cs.DIN99())
color_spaces.append(colorio.cs.ICtCp())
color_spaces.append(colorio.cs.IPT())
L_A = 64 / math.pi / 5
color_spaces.append(colorio.cs.CIECAM02(0.69, 20, L_A))
color_spaces.append(colorio.cs.CAM02("UCS", 0.69, 20, L_A))
color_spaces.append(colorio.cs.CAM16(0.69, 20, L_A))
color_spaces.append(colorio.cs.CAM16UCS(0.69, 20, L_A))
color_spaces.append(colorio.cs.JzAzBz())
color_spaces.append(colorio.cs.OKLAB())
color_spaces.append(colorio.cs.PROLAB())
for i in range(0,len(color_spaces)):
try:
p = colorio.plot_rgb_gamut(color_spaces[i], n=51, show_grid=True)
p.show()
except Exception as e:
print(color_spaces[i])
print(e)
Hi Nico
all the links to src in README.md like XYZ -> https://github.com/nschloe/colorio/blob/main/src/colorio/cs/_xyz.py are dead;
https://github.com/nschloe/colorio has only the README and articles/, no blob/
?
cheers
Hi,
If you do a simple:
import colorio
colorspace = colorio.OKLAB()
colorspace.show_ebner_fairchild()
you will get an error:
AttributeError: 'OKLAB' object has no attribute 'k0'
Hope it's help.
Fred
The README says:
The data can be written in all formats supported by
[meshio](https://github.com/nschloe/meshio).
However, since it is not clear that all formats are immediately supported by just doing pip install colorio
, I did some further testing:
#! /usr/bin/env python3
from meshio.helpers import _extension_to_filetype
extensions = tuple(_extension_to_filetype.keys())
dependenciesForExtensions = {}
extensionsWithOtherProblems = {}
extensionsWithoutProblems = []
import colorio
cielab = colorio.CIELAB()
for ext in extensions:
try:
colorio.show_srgb_gamut(cielab, "out" + ext)
except ModuleNotFoundError as e:
moduleName = str(e).split("'")[1]
if moduleName not in dependenciesForExtensions:
dependenciesForExtensions[moduleName] = []
dependenciesForExtensions[moduleName].append(ext)
except Exception as e:
extensionsWithOtherProblems[ext] = str(e)
else:
extensionsWithoutProblems.append(ext)
print("\nExtensions without problems:\n{}".format(extensionsWithoutProblems))
print("\nExtensions with dependency problems:\n{}̣".format(dependenciesForExtensions))
print("\nExtensions with other problems:\n{}".format(extensionsWithOtherProblems))
and got the output:
WARNING:root:Writing MSH4.1 unimplemented, falling back on MSH2
WARNING:root:Binary Gmsh needs 32-bit integers (got int64). Converting.
WARNING:root:Dolfin's XML is a legacy format. Consider using XDMF instead.
Extensions without problems:
['.mesh', '.msh', '.post', '.post.gz', '.dato', '.dato.gz', '.vtk', '.inp']
Extensions with dependency problems:
{'netCDF4': ['.e', '.ex2', '.exo'], 'h5py': ['.med', '.h5m'], 'lxml': ['.xml', '.vtu', '.xdmf', '.xmf', '.svg']}̣
Extensions with other problems:
{'.off': 'Can only deal with triangular faces', '.stl': 'STL can only write triangle cells.', '.mdpa': 'must be str, not bytes'}
Even after installing the extra module dependencies, trying to use SVG for output format produces the error SVG can only handle flat 2D meshes (shape: (125000, 3))
Thus the above statement in the README requires change. Specifically it would seem that:
.off
, .stl
, .mdpa
and .svg
formats aren't feasible for use with colorio (but I may be wrong), and:pip install colorio
So I suggest the following replacement wording:
The data can be written in most formats supported by
[meshio](https://github.com/nschloe/meshio) (with the exception of `.off`,
`.stl`, `.mdpa` and `.svg`). However, some formats may require packages
such as LXML to be installed in addition.
Hello,
Importing colorio in python now gives me a warning:
Warning: Unable to find valid license in
- environment variable COLORIO_LICENSE_KEY (env var not found), or
- config file .../colorio/colorio.toml (file not found)
Is this software not open source anymore?
When I run import coloria
in python, I get an error saying AttributeError: module 'lib' has no attribute 'OpenSSL_add_all_algorithms'
and the python program exits unexpectedly.
Hi,
On fresh system the Meshzoo is not installed and not in dependency.
Here the output.
import colorio
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.9/site-packages/colorio/init.py", line 3, in
from ._cam16 import CAM16, CAM16UCS
File "/usr/local/lib/python3.9/site-packages/colorio/_cam16.py", line 3, in
from ._ciecam02 import compute_from, compute_to
File "/usr/local/lib/python3.9/site-packages/colorio/_ciecam02.py", line 3, in
from ._color_space import ColorSpace
File "/usr/local/lib/python3.9/site-packages/colorio/_color_space.py", line 11, in
from ._tools import get_mono_outline_xy, get_munsell_data, spectrum_to_xyz100
File "/usr/local/lib/python3.9/site-packages/colorio/_tools.py", line 5, in
import meshzoo
ModuleNotFoundError: No module named 'meshzoo'
Could not find color space oklch
. Try one of cam02lcd, cam02scd, cam02ucs, cam16ucs, cielab, cieluv, ciehcl, cielch, din99, din99b, din99c, din99d, hdrlinear, ictcp, igpgtg, ipt, jzazbz, oklab, osaucs, prolab, rlab, srgblinear, srgb1, srgb255, srgbhex, srlab2, xyy1, xyy100, xyz1, xyz100.
Please support oklch. This will be more perfect
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.