How to use the colorio.SrgbLinear function in colorio

To help you get started, we’ve selected a few colorio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nschloe / colorio / test / test_srgb.py View on Github external
def test_conversion(vals):
    srgb_linear = colorio.SrgbLinear()

    out = srgb_linear.to_xyz100(srgb_linear.from_xyz100(vals))
    assert numpy.all(abs(vals - out) < 1.0e-14)

    out = srgb_linear.to_srgb1(srgb_linear.from_srgb1(vals))
    assert numpy.all(abs(vals - out) < 1.0e-14)

    out = srgb_linear.to_srgb255(srgb_linear.from_srgb255(vals))
    assert numpy.all(abs(vals - out) < 1.0e-14)
    return
github nschloe / colorio / test / test_srgb.py View on Github external
def test_reference_srgb(vals, ref):
    srgb_linear = colorio.SrgbLinear()
    assert numpy.all(
        abs(srgb_linear.from_srgb1(vals) - ref) < 1.0e-14 * numpy.array(ref)
    )
    return
github nschloe / colorio / test / test_srgb.py View on Github external
def test_reference_xyz(vals, ref):
    srgb_linear = colorio.SrgbLinear()
    assert numpy.all(abs(srgb_linear.to_xyz100(vals) - ref) < 1.0e-3 * numpy.array(ref))
    return
github nschloe / colorio / test / test_observers.py View on Github external
def test_observers(observer):
    lmbda, data = observer

    # For plot colors, take the SRGB approximation of the color that the
    # observer would perceive if a light spectrum hits its eye that corresponds
    # to the sensitivity spectrum.
    colors = []
    for k in range(3):
        out = colorio.illuminants.spectrum_to_xyz100(
            (lmbda, data[k]), observer=observer
        )
        out *= 100 / out[1]
        srgb = colorio.SrgbLinear()
        rgb_vals = srgb.from_xyz100(out)
        rgb_vals[rgb_vals < 0] = 0
        # project down to proper rgb
        rgb_vals /= max(rgb_vals)
        colors.append(srgb.to_srgb1(rgb_vals))

    plt.plot(lmbda, data[0], color=colors[0])
    plt.plot(lmbda, data[1], color=colors[1])
    plt.plot(lmbda, data[2], color=colors[2])

    plt.xlabel("wavelength (nm)")
    plt.grid()
    plt.xlim(lmbda[0], lmbda[-1])
    plt.ylim(ymin=0)

    plt.show()
github nschloe / colorio / test / test_srgb.py View on Github external
def test_whitepoint():
    srgb_linear = colorio.SrgbLinear()
    val = srgb_linear.to_xyz100([1.0, 1.0, 1.0])
    d65_whitepoint = colorio.illuminants.whitepoints_cie1931["D65"]
    assert numpy.all(numpy.abs(val - d65_whitepoint) < 1.0e-12)
    return
github nschloe / cplot / cplot / main.py View on Github external
# 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,
                rd * numpy.cos(angle + offset),
github nschloe / cplot / cplot / create.py View on Github external
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
github nschloe / cplot / cplot / main.py View on Github external
cam_pts = numpy.array(
            [
                100 * absval_scaled,
                rd * numpy.cos(angle + offset),
                rd * numpy.sin(angle + offset),
            ]
        )
        # now just translate to srgb
        srgb_vals = srgb.to_srgb1(srgb.from_xyz100(cam.to_xyz100(cam_pts)))
        # Cut off the outliers. This restriction makes the representation less perfect,
        # but that's what it is with the SRGB color space.
        srgb_vals[srgb_vals > 1] = 1.0
        srgb_vals[srgb_vals < 0] = 0.0
    elif colorspace.upper() == "CIELAB":
        cielab = colorio.CIELAB()
        srgb = colorio.SrgbLinear()
        # The max radius is about 29.5, 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(cielab, srgb, L=50)
        # r0 = 29.488203674554825
        r0 = 45.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.893_686_8 * 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)
        lab_pts = numpy.array(
            [
                100 * absval_scaled,
                rd * numpy.cos(angle + offset),