How to use the colorio.observers 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_illuminants.py View on Github external
def test_spectrum_to_xyz100():
    spectrum = colorio.illuminants.d65()
    observer = colorio.observers.cie_1931_2()
    colorio.illuminants.spectrum_to_xyz100(spectrum, observer)
    return
github nschloe / colorio / test / test_tools.py View on Github external
def test_cone_gamut(colorspace, n=10):
    observer = colorio.observers.cie_1931_2()
    colorspace.save_cone_gamut("cone.vtu", observer, max_Y=1)
github nschloe / colorio / test / test_observers.py View on Github external
    "observer", [colorio.observers.cie_1931_2(), colorio.observers.cie_1964_10()]
)
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
github nschloe / colorio / experiments / curve-fit-observers.py View on Github external
def cv():
    lmbda, data = colorio.observers.cie_1931_2()
    data = data[1]

    # You have to scale the x-data; see
    # .
    lmbda *= 1.0e5

    popt1, _ = scipy.optimize.curve_fit(f, lmbda, data, p0=[1, 0, 1])
    print(popt1)

    popt2, _ = scipy.optimize.curve_fit(g, lmbda, data, p0=[1, 0, 1, 0], maxfev=10000)
    print(popt2)

    popt3, _ = scipy.optimize.curve_fit(
        pade, lmbda, data, p0=[1, 0, 0, 0, 1, 0, 0, 0], maxfev=10000
    )
    print(popt3)
github nschloe / colorio / colorio / illuminants.py View on Github external
def white_point(illuminant, observer=observers.cie_1931_2()):
    """From :
    The white point of an illuminant is the chromaticity of a white object under the
    illuminant.
    """
    values = spectrum_to_xyz100(illuminant, observer)
    # normalize for relative luminance, Y=100
    values /= values[1]
    values *= 100
    return values
github nschloe / colorio / colorio / _tools.py View on Github external
def plot_flat_gamut(
    xy_to_2d=lambda xy: xy,
    axes_labels=("x", "y"),
    plot_rgb_triangle=True,
    fill_horseshoe=True,
    plot_planckian_locus=True,
):
    """Show a flat color gamut, by default xy.  There exists a chroma gamut for
    all color models which transform lines in XYZ to lines, and hence have a
    natural decomposition into lightness and chroma components.  Also, the flat
    gamut is the same for every lightness value. Examples for color models with
    this property are CIELUV and IPT, examples for color models without are
    CIELAB and CIECAM02.
    """
    observer = observers.cie_1931_2()
    # observer = observers.cie_1964_10()

    _plot_monochromatic(observer, xy_to_2d, fill_horseshoe=fill_horseshoe)
    # plt.grid()

    if plot_rgb_triangle:
        _plot_rgb_triangle(xy_to_2d)
    if plot_planckian_locus:
        _plot_planckian_locus(observer, xy_to_2d)

    plt.gca().set_aspect("equal")
    # plt.legend()
    plt.xlabel(axes_labels[0])
    plt.ylabel(axes_labels[1])
    return
github nschloe / colorio / colorio / _tools.py View on Github external
def xy_gamut_mesh(lcar):
    import optimesh
    import pygmsh

    observer = observers.cie_1931_2()

    # Gather all points on the horseshoe outline
    lmbda = 1.0e-9 * numpy.arange(380, 701)
    all_points = numpy.empty((len(lmbda), 2))
    for k in range(len(lmbda)):
        data = numpy.zeros(len(lmbda))
        data[k] = 1.0
        all_points[k] = _xyy_from_xyz100(spectrum_to_xyz100((lmbda, data), observer))[
            :2
        ]

    # Generate gmsh geometry: spline + straight line
    all_points = numpy.column_stack([all_points, numpy.zeros(len(all_points))])
    geom = pygmsh.built_in.Geometry()
    gmsh_points = [geom.add_point(pt, lcar) for pt in all_points]
    s1 = geom.add_spline(gmsh_points)
github nschloe / colorio / colorio / conversions.py View on Github external
def spectrum_to_xyz(spectrum, observer=observers.cie_1931_2()):
    '''Computes the tristimulus values XYZ from a given spectrum for a given
    observer via

    X_i = int_lambda spectrum_i(lambda) * observer_i(lambda) dlambda.

    In section 7, the technical report CIE Standard Illuminants for
    Colorimetry, 1999, gives a recommendation on how to perform the
    computation.
    '''
    lambda_o, data_o = observer
    lambda_s, data_s = spectrum

    # form the union of lambdas
    lmbda = numpy.sort(numpy.unique(numpy.concatenate([lambda_o, lambda_s])))

    # The technical document prescribes that the integration be performed "over