Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_whitepoint():
# With infinite luminance of the adapting field, the whitepoint is found
# at (100, 0, 0).
L_A = numpy.inf
cam16 = colorio.CAM16UCS(0.69, 20, L_A)
out = cam16.from_xyz100(colorio.illuminants.whitepoints_cie1931["D65"])
assert numpy.all(out == [100, 0, 0])
return
[colorio.CAM16UCS(0.69, 20, 4.074), 0, 50],
],
)
def test_visible_slice(cs, k0, level):
cs.show_visible_slice(k0, level)
# cs.save_visible_slice("visible-slice.png", k0, level)
def test_conversion_variants(xyz):
# test with srgb conditions
L_A = 64 / numpy.pi / 5
cam16 = colorio.CAM16UCS(0.69, 20, L_A)
out = cam16.to_xyz100(cam16.from_xyz100(xyz))
assert numpy.all(abs(xyz - out) < 1.0e-14)
return
def test_reference_values(xyz, ref):
L_A = 64 / numpy.pi / 5
cam16 = colorio.CAM16UCS(0.69, 20, L_A)
out = cam16.from_xyz100(xyz)
ref = numpy.array(ref)
assert numpy.all(abs(ref - out) < 1.0e-14 * ref)
return
# We may have NaNs, so don't be too strict here.
# assert numpy.all(absval_scaled >= 0)
# assert numpy.all(absval_scaled <= 1)
# It'd be lovely if one could claim that the grayscale of the cplot represents
# exactly the absolute value of the complex number. The grayscale is computed as the
# Y component of the XYZ-representation of the color, for linear SRGB values as
#
# 0.2126 * r + 0.7152 * g + 0.722 * b.
#
# Unfortunately, there is no perceptually uniform color space yet that uses
# Y-luminance. CIELAB, CIECAM02, and CAM16 have their own values.
if colorspace.upper() == "CAM16":
L_A = 64 / numpy.pi / 5
cam = colorio.CAM16UCS(0.69, 20, L_A)
srgb = colorio.SrgbLinear()
# The max radius is about 21.7, but crank up colors a little bit to make the
# images more saturated. This leads to SRGB-cut-off of course.
# r0 = find_max_srgb_radius(cam, srgb, L=50)
# r0 = 21.65824845433235
r0 = 25.0
# Rotate the angles such a "green" color represents positive real values. The
# rotation is chosen such that the ratio g/(r+b) (in rgb) is the largest for the
# point 1.0.
offset = 0.916_708 * numpy.pi
# Map (r, angle) to a point in the color space; bicone mapping similar to what
# HSL looks like .
rd = r0 - r0 * 2 * abs(absval_scaled - 0.5)
cam_pts = numpy.array(
[
100 * absval_scaled,
def create_colormap(L=50):
L_A = 64 / numpy.pi / 5
cam = colorio.CAM16UCS(0.69, 20, L_A)
# cam = colorio.CAM02('UCS', 0.69, 20, L_A)
# cam = colorio.CIELAB()
srgb = colorio.SrgbLinear()
r0 = find_max_srgb_radius(cam, srgb, L=L)
n = 256
alpha = numpy.linspace(0, 2 * numpy.pi, n, endpoint=False)
pts = numpy.array([numpy.full(n, L), r0 * numpy.cos(alpha), r0 * numpy.sin(alpha)])
vals = srgb.from_xyz100(cam.to_xyz100(pts))
# show the colors
vals = srgb.to_srgb1(vals)
return vals