Beispiel #1
0
def test_breakdown():
    bad_xyz = [8.71292997, 2.02183974, 83.26198455]
    L_A = 64 / numpy.pi / 5
    ciecam02 = colorio.CIECAM02(0.69, 20, L_A)
    with pytest.raises(colorio.ciecam02.NegativeAError):
        ciecam02.from_xyz100(bad_xyz)
    return
Beispiel #2
0
def test_speed(N=2):
    numpy.random.seed(1)
    osa = colorio.OsaUcs()
    cielab = colorio.CIELAB()
    # cam16 = colorio.CAM16(0.69, 20, L_A=64 / numpy.pi / 5)
    ciecam02 = colorio.CIECAM02(0.69, 20, L_A=64 / numpy.pi / 5)

    # This close probably means that another figure hasn't been properly closed.
    import matplotlib.pyplot as plt

    plt.close()

    perfplot.show(
        # Don't use numpy.random.rand(3, n) to avoid the CIECAM breakdown
        setup=lambda n: numpy.outer(numpy.random.rand(3), numpy.ones(n)) * 10,
        equality_check=None,
        kernels=[
            osa.to_xyz100,
            cielab.to_xyz100,
            # cam16.to_xyz100,
            lambda Jsh: ciecam02.to_xyz100(Jsh, "Jsh"),
            numpy.cbrt,
        ],
        labels=["OSA-UCS", "CIELAB", "CIECAM02", "cbrt"],
        n_range=[2 ** n for n in range(N)],
        logx=True,
        logy=True,
        # relative_to=3
    )
Beispiel #3
0
def test_from():
    """Compare colorio with colorspacius and colour."""
    xyz = 100 * numpy.random.rand(3)

    Y_b = 20
    whitepoint = colorio.illuminants.whitepoints_cie1931["D65"]
    L_A = 64 / numpy.pi / 5

    c = 0.69  # average
    cs2 = colorio.CIECAM02(c, Y_b, L_A)
    J, C, H, h, M, s, Q = cs2.from_xyz100(xyz)

    # compare with colorspacious
    cs1 = colorspacious.ciecam02.CIECAM02Space(
        whitepoint, Y_b, L_A, surround=colorspacious.CIECAM02Surround.AVERAGE)
    ref1 = cs1.XYZ100_to_CIECAM02(xyz)
    assert abs(ref1.J - J) < 1.0e-14 * J
    assert abs(ref1.C - C) < 1.0e-14 * C
    assert abs(ref1.H - H) < 1.0e-14 * H
    assert abs(ref1.h - h) < 1.0e-14 * h
    assert abs(ref1.M - M) < 1.0e-14 * M
    assert abs(ref1.s - s) < 1.0e-14 * s
    assert abs(ref1.Q - Q) < 1.0e-14 * Q

    # compare with color
    # TODO reinstate once https://github.com/colour-science/colour/issues/467 is fixed
    # ref2 = colour.appearance.ciecam02.XYZ_to_CIECAM02(xyz, whitepoint, L_A, Y_b)
    # assert abs(ref2.J - J) < 1.0e-14 * J
    # assert abs(ref2.C - C) < 1.0e-14 * C
    # # assert abs(ref2.H - H) < 1.0e-14 * H
    # assert abs(ref2.h - h) < 1.0e-14 * h
    # assert abs(ref2.M - M) < 1.0e-14 * M
    # assert abs(ref2.s - s) < 1.0e-14 * s
    # assert abs(ref2.Q - Q) < 1.0e-14 * Q
    return
Beispiel #4
0
def test_conversion(xyz):
    # test with srgb conditions
    L_A = 64 / numpy.pi / 5
    ciecam02 = colorio.CIECAM02(0.69, 20, L_A)
    J, C, H, h, M, s, Q = ciecam02.from_xyz100(xyz)

    out = ciecam02.to_xyz100(numpy.array([J, C, H]), 'JCH')
    assert numpy.all(abs(xyz - out) < 1.0e-13 * abs(xyz))

    out = ciecam02.to_xyz100(numpy.array([Q, M, h]), 'QMh')
    assert numpy.all(abs(xyz - out) < 1.0e-13 * abs(xyz))

    out = ciecam02.to_xyz100(numpy.array([J, s, h]), 'Jsh')
    assert numpy.all(abs(xyz - out) < 1.0e-13 * abs(xyz))
    return
Beispiel #5
0
def test_zero(xyz):
    L_A = 64 / numpy.pi / 5
    cs = colorio.CIECAM02(0.69, 20, L_A)
    J, C, H, h, M, s, Q = cs.from_xyz100(xyz)

    assert numpy.all(J == 0.0)
    assert numpy.all(C == 0.0)
    assert numpy.all(h == 0.0)
    assert numpy.all(M == 0.0)
    assert numpy.all(s == 0.0)
    assert numpy.all(Q == 0.0)

    out = cs.to_xyz100(numpy.array([J, C, H]), 'JCH')
    assert numpy.all(abs(out) < 1.0e-13)

    out = cs.to_xyz100(numpy.array([Q, M, h]), 'QMh')
    assert numpy.all(abs(out) < 1.0e-13)

    out = cs.to_xyz100(numpy.array([J, s, h]), 'Jsh')
    assert numpy.all(abs(out) < 1.0e-13)
    return
Beispiel #6
0
def test_speed(N=2):
    numpy.random.seed(1)
    osa = colorio.OsaUcs()
    cielab = colorio.CIELAB()
    # cam16 = colorio.CAM16(0.69, 20, L_A=64 / numpy.pi / 5)
    ciecam02 = colorio.CIECAM02(0.69, 20, L_A=64 / numpy.pi / 5)

    perfplot.plot(
        # Don't use numpy.random.rand(3, n) to avoid the CIECAM breakdown
        setup=lambda n: numpy.outer(numpy.random.rand(3), numpy.ones(n)) * 10,
        equality_check=None,
        kernels=[
            osa.to_xyz100,
            cielab.to_xyz100,
            # cam16.to_xyz100,
            lambda Jsh: ciecam02.to_xyz100(Jsh, "Jsh"),
            numpy.cbrt,
        ],
        labels=["OSA-UCS", "CIELAB", "CIECAM02", "cbrt"],
        n_range=[2**n for n in range(N)],
        logx=True,
        logy=True,
        # relative_to=3
    )
Beispiel #7
0
def test_gold():
    # See
    # https://github.com/njsmith/colorspacious/blob/master/colorspacious/gold_values.py
    xyz = [19.31, 23.93, 10.14]
    ciecam02 = colorio.CIECAM02(0.69, 18, 200, whitepoint=[98.88, 90, 32.03])
    values = ciecam02.from_xyz100(xyz)
    reference_values = numpy.array([
        # J, C, H, h, M, s, Q
        48.0314,
        38.7789,
        240.8885,
        191.0452,
        38.7789,
        46.0177,
        183.1240
    ])
    assert numpy.all(
        abs(values - reference_values) < 1.0e-6 * reference_values)

    # different L_A
    xyz = [19.31, 23.93, 10.14]
    ciecam02 = colorio.CIECAM02(0.69, 18, 20, whitepoint=[98.88, 90, 32.03])
    values = ciecam02.from_xyz100(xyz)
    reference_values = numpy.array([
        # J, C, H, h, M, s, Q
        47.6856,
        36.0527,
        232.6630,
        185.3445,
        29.7580,
        51.1275,
        113.8401
    ])
    assert numpy.all(
        abs(values - reference_values) < 1.0e-5 * reference_values)

    # gold values from Mark Fairchild's spreadsheet at
    #   http://rit-mcsl.org/fairchild//files/AppModEx.xls
    xyz = [19.01, 20.00, 21.78]
    ciecam02 = colorio.CIECAM02(0.69,
                                20,
                                318.30988618379,
                                whitepoint=[95.05, 100.0, 108.88])
    values = ciecam02.from_xyz100(xyz)
    reference_values = numpy.array([
        # J, C, H, h, M, s, Q
        4.17310911e+01,
        1.04707861e-01,
        2.78060724e+02,
        2.19048423e+02,
        1.08842280e-01,
        2.36030659e+00,
        1.95371311e+02
    ])
    assert numpy.all(
        abs(values - reference_values) < 1.0e-8 * reference_values)

    xyz = [57.06, 43.06, 31.96]
    ciecam02 = colorio.CIECAM02(
        0.69,
        20,
        31.830988618379,
        whitepoint=[95.05, 100.0, 108.88],
    )
    values = ciecam02.from_xyz100(xyz)
    reference_values = numpy.array([
        # J, C, H, h, M, s, Q
        65.95523,
        48.57050,
        399.38837,
        19.55739,
        41.67327,
        52.24549,
        152.67220
    ])
    assert numpy.all(
        abs(values - reference_values) < 1.0e-6 * reference_values)
    return