def test_rgb_to_rgb_matrix(self):
        """Test rgb to rgb matrix

        """
        ACES_to_proxy_matrix = get_RGB_to_RGB_matrix('ACES', 'ACEScc')
        ref_value = numpy.matrix([[1.4514393161, -0.2365107469, -0.2149285693],
                                  [-0.0765537734,  1.1762296998,  -0.0996759264],
                                  [0.0083161484, -0.0060324498, 0.9977163014]])
        self.assertTrue(numpy.allclose(ACES_to_proxy_matrix, ref_value),
                        "Processed ACES to ACEScc matrix is different from reference ! ")
        ACES_to_Rec2020_matrix = get_RGB_to_RGB_matrix("ACES", 'Rec2020_12bits')
        ref_value = [[1.5128613853114372, -0.2589874063019148, -0.22978603267468098],
                            [-0.079036464595355627, 1.1770668323294038, -0.10075565571179679],
                            [0.0020912324769753847, -0.03114411050570343, 0.95350416068074784]]
        self.assertTrue(numpy.allclose(ACES_to_Rec2020_matrix, ref_value),
                        "Processed ACES to Rec2020 matrix is different from reference ! ")
Exemplo n.º 2
0
def display_matrix(in_colorspace, out_colorspace, matrix_format, primaries_only=False):
    """Display RGB to XYZ matrix corresponding to colorspace and formatting
    as format

    Args:
        colorspace (str): input colorspace.

        matrix_format (str): output format. simple, matrix, spimtx.

    """
    if in_colorspace == XYZ_colorspace:
        if out_colorspace == XYZ_colorspace:
            raise AttributeError("In and out colorspaces can't be both XYZ !")
        matrix = get_colorspace_matrix(out_colorspace, primaries_only, inv=True)
    elif out_colorspace == XYZ_colorspace:
        matrix = get_colorspace_matrix(in_colorspace, primaries_only, inv=False)
    else:
        matrix = get_RGB_to_RGB_matrix(in_colorspace, out_colorspace, primaries_only)

    if matrix_format == 'simple':
        matrix_dump = matrix_to_string(matrix)
    elif matrix_format == 'spimtx':
        matrix_dump = matrix_to_spimtx_string(matrix)
    else:
        matrix_dump = "{0}".format(matrix)

    print "{0} to {1} matrix ({2} {3} output):\n".format(in_colorspace,
                                                         out_colorspace,
                                                         primaries_only and "primaries" or
                                                         "primaries + white point",
                                                         matrix_format)
    print matrix_dump
    def test_aces_proxy(self):
        """Test ACES proxy (matrix + encoding)

        """
        ref_colors = [[0.001184464, 64.0, 0.001185417],
                      [222.875, 940.0, 222.860944204]
                      ]
        ACES_to_proxy_matrix = get_RGB_to_RGB_matrix('ACES', 'ACESproxy_10')
        proxy_to_ACES_matrix = get_RGB_to_RGB_matrix('ACESproxy_10', 'ACES')
        for color in ref_colors:
            aces_proxy_lin = apply_matrix(ACES_to_proxy_matrix, [color[0]]*3)[2]
            aces_proxy = ACESPROXY_10i._encode_gradation(aces_proxy_lin)
            self.assertEqual(aces_proxy, color[1])
            aces_proxy_lin = ACESPROXY_10i._decode_gradation(aces_proxy)
            aces = apply_matrix(proxy_to_ACES_matrix, [aces_proxy_lin]*3)[0]
            message = ("ACESproxy not valid ! "
                       "in: {0} out: {1}").format(aces, color[2])
            self.assertTrue(numpy.isclose(aces, color[2], atol=0.000001), message)
Exemplo n.º 4
0
def display_matrix(in_colorspace,
                   out_colorspace,
                   matrix_format,
                   primaries_only=False):
    """Display RGB to XYZ matrix corresponding to colorspace and formatting
    as format

    Args:
        colorspace (str): input colorspace.

        matrix_format (str): output format. simple, matrix, spimtx.

    """
    if in_colorspace == XYZ_colorspace:
        if out_colorspace == XYZ_colorspace:
            raise AttributeError("In and out colorspaces can't be both XYZ !")
        matrix = get_colorspace_matrix(out_colorspace,
                                       primaries_only,
                                       inv=True)
    elif out_colorspace == XYZ_colorspace:
        matrix = get_colorspace_matrix(in_colorspace,
                                       primaries_only,
                                       inv=False)
    else:
        matrix = get_RGB_to_RGB_matrix(in_colorspace, out_colorspace,
                                       primaries_only)

    if matrix_format == 'simple':
        matrix_dump = matrix_to_string(matrix)
    elif matrix_format == 'spimtx':
        matrix_dump = matrix_to_spimtx_string(matrix)
    else:
        matrix_dump = "{0}".format(matrix)

    print("{0} to {1} matrix ({2} {3} output):\n".format(
        in_colorspace, out_colorspace, primaries_only and "primaries"
        or "primaries + white point", matrix_format))
    print(matrix_dump)