示例#1
0
from colour.plotting import *  # noqa
from colour.utilities.verbose import message_box

message_box('Colour Models Plots')

message_box('Plotting "RGB" colourspaces in "CIE 1931 Chromaticity Diagram".')
pprint(sorted(colour.RGB_COLOURSPACES.keys()))
colourspaces_CIE_1931_chromaticity_diagram_plot(
    ['sRGB', 'ACES RGB', 'Adobe RGB 1998'])

print('\n')

message_box(('Plotting a single custom "RGB" colourspace in '
             '"CIE 1931 Chromaticity Diagram".'))
colour.RGB_COLOURSPACES['Awful RGB'] = colour.RGB_Colourspace(
    'Awful RGB',
    primaries=array([[0.1, 0.2], [0.3, 0.15], [0.05, 0.6]]),
    whitepoint=(1 / 3, 1 / 3))
pprint(sorted(colour.RGB_COLOURSPACES.keys()))
colourspaces_CIE_1931_chromaticity_diagram_plot(['sRGB', 'Awful RGB'])

print('\n')

message_box('Plotting a single "RGB" colourspace transfer function.')
single_transfer_function_plot('sRGB')

print('\n')

message_box('Plotting multiple "RGB" colourspaces transfer functions.')
multi_transfer_function_plot(['sRGB', 'Rec. 709'])
示例#2
0
    if bg == 'dark':
        return DARK_BG
    if bg == 'light':
        return LIGHT_BG
    return NEUTRAL_BG


def apow(x, power):
    """Raises x to the given power, treating negative numbers in a mirrored fashion."""
    return np.abs(x)**power * np.sign(x)


WEB_CS = colour.RGB_Colourspace('web',
                                colour.sRGB_COLOURSPACE.primaries,
                                colour.sRGB_COLOURSPACE.whitepoint,
                                encoding_cctf=partial(apow, power=1 / 2.2),
                                decoding_cctf=partial(apow, power=2.2),
                                use_derived_RGB_to_XYZ_matrix=True,
                                use_derived_XYZ_to_RGB_matrix=True)


def web_to_XYZ(RGB):
    """Converts from the web colorspace to XYZ tristimulus values."""
    return colour.RGB_to_XYZ(RGB,
                             WEB_CS.whitepoint,
                             WEB_CS.whitepoint,
                             WEB_CS.RGB_to_XYZ_matrix,
                             decoding_cctf=WEB_CS.decoding_cctf)


def XYZ_to_web(XYZ):
示例#3
0
print('\n')

message_box('Plotting "RGB" chromaticity coordinates in '
            '"CIE 1976 UCS Chromaticity Diagram".')
RGB_chromaticity_coordinates_CIE_1976_UCS_chromaticity_diagram_plot(
    RGB,
    colour.REC_709_COLOURSPACE,
    colourspaces=['ACEScg', 'S-Gamut', 'Pointer Gamut'])

print('\n')

message_box(('Plotting a single custom "RGB" colourspace in '
             '"CIE 1931 Chromaticity Diagram".'))
colour.RGB_COLOURSPACES['Awful RGB'] = colour.RGB_Colourspace(
    'Awful RGB',
    primaries=np.array([[0.10, 0.20], [0.30, 0.15], [0.05, 0.60]]),
    whitepoint=(1 / 3, 1 / 3))
pprint(sorted(colour.RGB_COLOURSPACES.keys()))
RGB_colourspaces_CIE_1931_chromaticity_diagram_plot(['Rec. 709', 'Awful RGB'])

print('\n')

message_box(('Plotting a single "RGB" '
             'colourspace opto-electronic conversion function.'))
single_conversion_function_plot('Rec. 709')

print('\n')

message_box(('Plotting multiple "RGB" colourspaces '
             'opto-electronic conversion functions.'))
multi_conversion_function_plot(['Rec. 709', 'sRGB'])
示例#4
0
message_box('Plotting "RGB" chromaticity coordinates in '
            '"CIE 1976 UCS Chromaticity Diagram".')
plot_RGB_chromaticities_in_chromaticity_diagram_CIE1976UCS(
    RGB,
    'ITU-R BT.709',
    colourspaces=['ACEScg', 'S-Gamut'],
    show_pointer_gamut=True)

print('\n')

message_box(('Plotting a single custom "RGB" colourspace in '
             '"CIE 1931 Chromaticity Diagram".'))
colour.RGB_COLOURSPACES['Awful RGB'] = colour.RGB_Colourspace(
    'Awful RGB',
    primaries=np.array([
        [0.10, 0.20],
        [0.30, 0.15],
        [0.05, 0.60],
    ]),
    whitepoint=np.array([1.0 / 3.0, 1.0 / 3.0]))
pprint(sorted(colour.RGB_COLOURSPACES.keys()))
plot_RGB_colourspaces_in_chromaticity_diagram_CIE1931(
    ['ITU-R BT.709', 'Awful RGB'])

print('\n')

message_box(('Plotting a single "RGB" colourspace encoding colour component '
             'transfer function.'))
plot_single_cctf('ITU-R BT.709')

print('\n')
def get_display_colorspaces(family=""):
    colour.RGB_COLOURSPACES["CIE-XYZ (D65)"] = colour.RGB_Colourspace(
        name="CIE-XYZ (D65)",
        primaries=np.array([[1.0, 0.0], [0.0, 1.0], [0.0, 0.0]]),
        whitepoint=np.array([0.3127, 0.329]),
        whitepoint_name="D65",
        use_derived_matrix_RGB_to_XYZ=True,
        use_derived_matrix_XYZ_to_RGB=True,
        cctf_decoding=colour.models.linear_function,
        cctf_encoding=colour.models.linear_function,
    )

    xyzd65_to_rec709 = _simplify_transform(
        ocio.GroupTransform(
            [
                ocio.BuiltinTransform(
                    "ACES-AP1_to_CIE-XYZ-D65_BFD", ocio.TRANSFORM_DIR_INVERSE
                ),
                ocio.BuiltinTransform("ACES-AP1_to_LINEAR-REC709_BFD"),
            ]
        )
    )

    # xyzd65_to_rec709 = _convert_numpy_matrix33_to_matrix_transform(
    #     colour.matrix_RGB_to_RGB(
    #         input_colourspace=colour.RGB_COLOURSPACES['CIE-XYZ (D65)'],
    #         output_colourspace=colour.RGB_COLOURSPACES['ITU-R BT.709'],
    #         chromatic_adaptation_transform=None
    #     )
    # )

    xyzd65_to_p3d65 = _convert_numpy_matrix33_to_matrix_transform(
        colour.matrix_RGB_to_RGB(
            input_colourspace=colour.RGB_COLOURSPACES["CIE-XYZ (D65)"],
            output_colourspace=colour.RGB_COLOURSPACES["P3-D65"],
            chromatic_adaptation_transform=None,
        )
    )

    xyzd65_to_p3 = _convert_numpy_matrix33_to_matrix_transform(
        colour.matrix_RGB_to_RGB(
            input_colourspace=colour.RGB_COLOURSPACES["CIE-XYZ (D65)"],
            output_colourspace=colour.RGB_COLOURSPACES["DCI-P3"],
            chromatic_adaptation_transform="Bradford",
        )
    )

    # check
    xyzd65_to_p3_d60_sim_bfd = ocio.GroupTransform(
        [
            ocio.BuiltinTransform(
                "ACES-AP0_to_CIE-XYZ-D65_BFD", ocio.TRANSFORM_DIR_INVERSE
            ),
            _convert_numpy_matrix33_to_matrix_transform(
                colour.matrix_RGB_to_RGB(
                    input_colourspace=colour.RGB_COLOURSPACES["ACES2065-1"],
                    output_colourspace=colour.RGB_COLOURSPACES["DCI-P3"],
                    chromatic_adaptation_transform="Bradford",
                )
            ),
        ]
    )

    # Shapers
    acescct_cctf = ocio.BuiltinTransform("ACEScct-LOG_to_LIN")

    sRGB_g22 = ocio.ColorSpace(
        referenceSpace=ocio.REFERENCE_SPACE_DISPLAY,
        name="sRGB (Gamma ~2.2)",
        description="sRGB (Gamma ~2.2) with Rec.709 primaries",
        encoding="sdr-video",
        family=family,
        bitDepth=ocio.BIT_DEPTH_UINT10,
        fromReference=ocio.GroupTransform(
            [
                xyzd65_to_rec709,
                display_cctf(
                    gamma=2.4, offset=0.055, direction=ocio.TRANSFORM_DIR_INVERSE
                ),
                ocio.RangeTransform(
                    minInValue=0, minOutValue=0, maxInValue=1, maxOutValue=1
                ),
            ]
        ),
    )

    sRGB = ocio.ColorSpace(
        referenceSpace=ocio.REFERENCE_SPACE_DISPLAY,
        name="sRGB",
        description="sRGB with Rec.709 primaries",
        encoding="sdr-video",
        family=family,
        bitDepth=ocio.BIT_DEPTH_UINT10,
        fromReference=ocio.GroupTransform(
            [
                xyzd65_to_rec709,
                display_cctf(gamma=2.2, direction=ocio.TRANSFORM_DIR_INVERSE),
                ocio.RangeTransform(
                    minInValue=0, minOutValue=0, maxInValue=1, maxOutValue=1
                ),
            ]
        ),
    )
    Rec709_display = ocio.ColorSpace(
        referenceSpace=ocio.REFERENCE_SPACE_DISPLAY,
        name="Rec.709 (legacy)",
        description="ITU-R BT.709 inverse camera CCTF with BT.709 primaries",
        encoding="sdr-video",
        family=family,
        bitDepth=ocio.BIT_DEPTH_UINT10,
        fromReference=ocio.GroupTransform(
            [
                xyzd65_to_rec709,
                display_cctf(
                    gamma=1 / 0.45, offset=0.099, direction=ocio.TRANSFORM_DIR_INVERSE
                ),
                ocio.RangeTransform(
                    minInValue=0, minOutValue=0, maxInValue=1, maxOutValue=1
                ),
            ]
        ),
    )

    Rec1886 = ocio.ColorSpace(
        referenceSpace=ocio.REFERENCE_SPACE_DISPLAY,
        name="Rec.1886",
        description="ITU-R BT.1886 with BT.709 primaries and D65 whitepoint",
        encoding="sdr-video",
        family=family,
        bitDepth=ocio.BIT_DEPTH_UINT10,
        fromReference=ocio.GroupTransform(
            [
                xyzd65_to_rec709,
                display_cctf(gamma=2.4, direction=ocio.TRANSFORM_DIR_INVERSE),
                ocio.RangeTransform(
                    minInValue=0, minOutValue=0, maxInValue=1, maxOutValue=1
                ),
            ]
        ),
    )

    DCI_P3 = ocio.ColorSpace(
        referenceSpace=ocio.REFERENCE_SPACE_DISPLAY,
        name="DCI-P3",
        description="Gamma 2.6 with DCI primaries",
        encoding="sdr-video",
        family=family,
        bitDepth=ocio.BIT_DEPTH_UINT10,
        fromReference=ocio.GroupTransform(
            [
                xyzd65_to_p3,
                display_cctf(gamma=2.6, direction=ocio.TRANSFORM_DIR_INVERSE),
                ocio.RangeTransform(
                    minInValue=0, minOutValue=0, maxInValue=1, maxOutValue=1
                ),
            ]
        ),
    )

    P3_D65 = ocio.ColorSpace(
        referenceSpace=ocio.REFERENCE_SPACE_DISPLAY,
        name="P3-D65",
        description="Gamma 2.6 with DCI primaries and D65 whitepoint",
        encoding="sdr-video",
        family=family,
        bitDepth=ocio.BIT_DEPTH_UINT10,
        fromReference=ocio.GroupTransform(
            [
                xyzd65_to_p3d65,
                display_cctf(gamma=2.6, direction=ocio.TRANSFORM_DIR_INVERSE),
                ocio.RangeTransform(
                    minInValue=0, minOutValue=0, maxInValue=1, maxOutValue=1
                ),
            ]
        ),
    )
    # TODO: D60 sim; hdr colorspaces

    return [
        sRGB,
        Rec1886,
        DCI_P3,
        P3_D65,
    ]
plot_RGB_chromaticities_in_chromaticity_diagram_CIE1976UCS(
    RGB,
    "ITU-R BT.709",
    colourspaces=["ACEScg", "S-Gamut"],
    show_pointer_gamut=True,
)

print("\n")

message_box('Plotting a single custom "RGB" colourspace in the '
            '"CIE 1931 Chromaticity Diagram".')
AWFUL_RGB = colour.RGB_Colourspace(
    "Awful RGB",
    primaries=np.array([
        [0.10, 0.20],
        [0.30, 0.15],
        [0.05, 0.60],
    ]),
    whitepoint=np.array([1.0 / 3.0, 1.0 / 3.0]),
)
pprint(sorted(colour.RGB_COLOURSPACES.keys()))
plot_RGB_colourspaces_in_chromaticity_diagram_CIE1931(
    ["ITU-R BT.709", AWFUL_RGB])

print("\n")

message_box(
    'Plotting a single "RGB" colourspace encoding colour component transfer '
    "function.")
plot_single_cctf("ITU-R BT.709")