Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import numpy
from ._color_space import ColorSpace
from ._linalg import dot
from .illuminants import whitepoints_cie1931
class OsaUcs(ColorSpace):
"""
David L. MacAdam,
Uniform color scales,
Journal of the Optical Society of America,
Volume 64, Number 12, December 1974,
,
.
Nico Schlömer,
On the conversion from OSA-UCS to CIEXYZ,
.
"""
def __init__(self, whitepoint=whitepoints_cie1931["D65"]):
self.labels = ["L", "g", "j"]
import numpy
from ._color_space import ColorSpace
from ._linalg import dot, solve
class ICtCp(ColorSpace):
"""
ICtCp color model.
"""
def __init__(self):
self.M1 = (
numpy.array([[1688, 2146, 262], [683, 2951, 462], [99, 309, 3688]]) / 4096
)
# From
self.m1 = 2610 / 4096 / 4
self.m2 = 2523 / 4096 * 128
self.c1 = 3424 / 4096
self.c2 = 2413 / 4096 * 32
self.c3 = 2392 / 4096 * 32
import numpy
from ._color_space import ColorSpace
from ._linalg import dot, solve
from .illuminants import whitepoints_cie1931
class JzAzBz(ColorSpace):
"""
Muhammad Safdar, Guihua Cui, Youn Jin Kim, and Ming Ronnier Luo,
Perceptually uniform color space for image signals including high dynamic range and
wide gamut,
Optics Express Vol. 25, Issue 13, pp. 15131-15151 (2017),
.
"""
def __init__(self, whitepoint=whitepoints_cie1931["D65"]):
self.whitepoint = whitepoint
self.b = 1.15
self.g = 0.66
self.c1 = 3424 / 2 ** 12
self.c2 = 2413 / 2 ** 7
self.c3 = 2392 / 2 ** 7
import numpy
from ._color_space import ColorSpace
from .illuminants import whitepoints_cie1931
class CIELUV(ColorSpace):
def __init__(self, whitepoint=whitepoints_cie1931["D65"]):
self.whitepoint = whitepoint
self.labels = ["L*", "u*", "v*"]
self.k0 = 0 # the index that corresponds to luminosity
return
def from_xyz100(self, xyz):
def f(t):
delta = 6.0 / 29.0
out = numpy.array(t, dtype=float)
is_greater = out > delta ** 3
out[is_greater] = 116 * numpy.cbrt(out[is_greater]) - 16
out[~is_greater] = out[~is_greater] / (delta / 2) ** 3
return out
L = f(xyz[1] / self.whitepoint[1])
import numpy
from ._cielab import CIELAB
from ._color_space import ColorSpace
from .illuminants import whitepoints_cie1931
class CIELCH(ColorSpace):
def __init__(self, whitepoint=whitepoints_cie1931["D65"]):
self.cielab = CIELAB(whitepoint=whitepoint)
self.labels = ["L", "C", "h"]
self.k0 = 0 # the index that corresponds to luminosity
return
def from_xyz100(self, xyz):
L, u, v = self.cielab.from_xyz100(xyz)
C = numpy.hypot(u, v)
h = numpy.mod(numpy.arctan2(v, u), 2 * numpy.pi) / numpy.pi * 180
return numpy.array([L, C, h])
def to_xyz100(self, lch):
L, C, h = lch
h_ = h * numpy.pi / 180
lab = numpy.array([L, C * numpy.cos(h_), C * numpy.sin(h_)])
import numpy
from ._color_space import ColorSpace
from ._linalg import dot, solve
class IPT(ColorSpace):
"""
IPT color model.
"""
def __init__(self):
self.M1 = numpy.array(
[
[0.4002, 0.7075, -0.0807],
[-0.2280, 1.1500, 0.0612],
[0.0000, 0.0000, 0.9184],
]
)
self.M2 = numpy.array(
[
[0.4000, 0.4000, 0.2000],
[4.4550, -4.8510, 0.3960],
import numpy
from ._color_space import ColorSpace
from .illuminants import whitepoints_cie1931
class CIELAB(ColorSpace):
def __init__(self, whitepoint=whitepoints_cie1931["D65"]):
self.whitepoint = whitepoint
self.labels = ["L*", "a*", "b*"]
self.k0 = 0 # the index that corresponds to luminosity
return
def from_xyz100(self, xyz):
def f(t):
delta = 6 / 29
out = numpy.array(t, dtype=float)
is_greater = out > delta ** 3
out[is_greater] = 116 * numpy.cbrt(out[is_greater]) - 16
out[~is_greater] = out[~is_greater] / (delta / 2) ** 3
return out
fx, fy, fz = f((xyz.T / self.whitepoint).T)
from ._color_space import ColorSpace
class XYZ(ColorSpace):
def __init__(self):
self.labels = ["X", "Y", "Z"]
return
def from_xyz100(self, xyz):
return xyz / 100
def to_xyz100(self, xyz):
return xyz * 100
"""
# Steps 1-5
rgb_ = compute_to(data, description, self)
# Step 6: Calculate RC, GC and BC
# rgb_c = dot(self.M_cat02, solve(self.M_hpe, rgb_))
#
# Step 7: Calculate R, G and B
# rgb = (rgb_c.T / self.D_RGB).T
#
# Step 8: Calculate X, Y and Z
# xyz = solve(self.M_cat02, rgb)
return dot(self.invM_, rgb_)
class CAM02(ColorSpace):
def __init__(self, variant, c, Y_b, L_A, whitepoint=whitepoints_cie1931["D65"]):
params = {
"LCD": (0.77, 0.007, 0.0053),
"SCD": (1.24, 0.007, 0.0363),
"UCS": (1.00, 0.007, 0.0228),
}
self.K_L, self.c1, self.c2 = params[variant]
self.ciecam02 = CIECAM02(c, Y_b, L_A, whitepoint)
self.labels = ["J'", "a'", "b'"]
self.k0 = 0 # the index that corresponds to luminosity
return
def from_xyz100(self, xyz):
J, _, _, h, M, _, _ = self.ciecam02.from_xyz100(xyz)
J_ = (1 + 100 * self.c1) * J / (1 + self.c1 * J)
M_ = 1 / self.c2 * numpy.log(1 + self.c2 * M)
import numpy
from ._color_space import ColorSpace
class XYY(ColorSpace):
def __init__(self):
self.labels = ["x", "y", "Y"]
self.k0 = 2 # which index corresponds to luminosity
return
def from_xyz100(self, xyz100):
xyz = xyz100 / 100
sum_xyz = numpy.sum(xyz, axis=0)
x = xyz[0]
y = xyz[1]
return numpy.array([x / sum_xyz, y / sum_xyz, y])
def to_xyz100(self, xyy):
x, y, Y = xyy
return numpy.array([Y / y * x, Y, Y / y * (1 - x - y)]) * 100