Ejemplo n.º 1
0
    def getBrightnessMeasure(self, rgb):
        Y = colour.RGB_to_YCbCr(rgb)[:, 0]
        lum = colour.RGB_to_HSL(rgb)[:, 2]

        return np.c_[np.mean(Y),
                     np.var(Y),
                     np.min(Y),
                     np.max(Y),
                     np.mean(lum),
                     np.var(lum),
                     np.min(lum),
                     np.max(lum)]
Ejemplo n.º 2
0
def YCbCr2020(xyz, saturation, white_point):
    wp = np.array(white_point)
    bt2020 = colour.RGB_COLOURSPACES['ITU-R BT.2020']
    data = colour.XYZ_to_RGB(xyz,
                             wp,
                             bt2020.whitepoint,
                             bt2020.XYZ_to_RGB_matrix,
                             cctf_encoding=None)
    data[data < 0.0] = 0.0
    data = colour.models.rgb.transfer_functions.eotf_inverse_BT1886(data)
    data = colour.RGB_to_YCbCr(
        data, K=colour.YCBCR_WEIGHTS['ITU-R BT.2020'])  #, out_legal=False)
    data[..., 1] = (data[..., 1] - 0.5) * saturation + 0.5
    data[..., 2] = (data[..., 2] - 0.5) * saturation + 0.5
    data = colour.YCbCr_to_RGB(data, K=colour.YCBCR_WEIGHTS['ITU-R BT.2020'])
    data[data < 0.0] = 0.0
    return colour.RGB_to_XYZ(
        data,
        bt2020.whitepoint,
        wp,
        bt2020.RGB_to_XYZ_matrix,
        cctf_decoding=colour.models.rgb.transfer_functions.eotf_BT1886)
Ejemplo n.º 3
0
def get_ebu_color_rgb_from_XYZ():
    xyz_file = "./doc/ebu_test_colour_value2.csv"
    large_xyz = np.loadtxt(
        xyz_file, delimiter=",", skiprows=1, usecols=(1, 2, 3)) / 100.0
    rgb_val = large_xyz_to_rgb(large_xyz, 'ITU-R BT.2020')
    print(rgb_val)
    rgb_val = rgb_val**(1 / 2.35)
    ycbcr = colour.RGB_to_YCbCr(RGB=rgb_val,
                                K=colour.YCBCR_WEIGHTS['ITU-R BT.2020'],
                                in_bits=10,
                                out_bits=10,
                                out_legal=True,
                                out_int=True)
    print(ycbcr)
    yuv2rgb_mtx = np.array(cc.rgb2yuv_rec2020mtx)
    yuv =\
        cc.color_cvt(rgb_val.reshape((1, rgb_val.shape[0], rgb_val.shape[1])),
                     yuv2rgb_mtx)
    ycbcr = cc.yuv_to_ycbcr(yuv.reshape((yuv.shape[1], yuv.shape[2])),
                            bit_depth=10)
    print(ycbcr)
    # plot_color_patch(rgb_val, v_num=3, h_num=5)
    print(colour.RGB_COLOURSPACES['ITU-R BT.709'].RGB_to_XYZ_matrix)
Ejemplo n.º 4
0
Showcases *Y'CbCr* *colour encoding* computations.
"""

import numpy as np

import colour
from colour.utilities import message_box

message_box('"Y\'CbCr" Colour Encoding Computations')

RGB = np.array([0.35521588, 0.41000000, 0.24177934])
message_box(
    ('Converting to "Y\'CbCr" colour encoding from given "ITU-R BT.709" '
     'colourspace values:\n'
     '\n\t{0}'.format(RGB)))
print(colour.RGB_to_YCbCr(RGB))

print('\n')

message_box(('Converting to "Y\'CbCr" colour encoding from given'
             '"ITU-R BT.601" colourspace values using legal range and integer '
             'output:\n\n\t{0}'.format(RGB)))
print(
    colour.RGB_to_YCbCr(RGB,
                        colour.YCBCR_WEIGHTS['ITU-R BT.601'],
                        out_legal=True,
                        out_int=True))

print('\n')

YCbCr = np.array([101, 111, 124])
Ejemplo n.º 5
0
 def convertData(xyz):
     data = colour.XYZ_to_RGB(xyz, wp, bt709.whitepoint, bt709.XYZ_to_RGB_matrix, 'CAT02', cctf_encoding=colour.models.rgb.transfer_functions.eotf_inverse_BT1886)
     return colour.RGB_to_YCbCr(data, out_legal=False)
Ejemplo n.º 6
0
def createHull(resolution=10, transfer_curve=None):
    output = np.zeros((resolution ** 3, 3))
    divisor = 1.0 / (resolution - 1)
    for r in range(resolution):
        for g in range(resolution):
            for b in range(resolution):
                idx = r * resolution * resolution + g * resolution + b
                output[idx, 0] = r * divisor
                output[idx, 1] = g * divisor
                output[idx, 2] = b * divisor
    if not transfer_curve is None:
        output = transfer_curve(output)
    return output

bt2020 = colour.RGB_COLOURSPACES['ITU-R BT.2020']
itur_bt709_hull = createHull(transfer_curve=lambda x: colour.RGB_to_YCbCr(x, out_legal=False))
ictcp_hull      = createHull(transfer_curve=lambda x: colour.RGB_to_ICTCP(colour.models.rgb.transfer_functions.st_2084.eotf_ST2084(x * colour.models.rgb.transfer_functions.st_2084.eotf_inverse_ST2084(1000))))
jzazbz_hull     = createHull(transfer_curve=lambda x: colour.XYZ_to_JzAzBz(colour.RGB_to_XYZ(colour.models.rgb.transfer_functions.st_2084.eotf_ST2084(x * colour.models.rgb.transfer_functions.st_2084.eotf_inverse_ST2084(1000)),
                             bt2020.whitepoint,
                             bt2020.whitepoint,
                             bt2020.RGB_to_XYZ_matrix,
                             None,
                             None)))

colors            = ['r', 'g', 'b', 'c', 'm', 'y']
line_style        = ['--', '-.']
line_point_marker = '+'
scatter_marker    = ['o', '*', 'x']
hue_line_color    = '0.65'
hue_line_style    = ':'
hue_point_style   = '.'
Ejemplo n.º 7
0
def _check_clip_level(src='ITU-R BT.709', dst='ITU-R BT.709'):
    """
    YUV2RGBのミスマッチが発生した場合に見えなくなるような
    テストパターンを作る。そのための事前調査をするよん☆
    """

    # 単調増加するRGB単色パターンを作成する
    # ------------------------------------
    sample_num = 1024
    max_input_value = sample_num - 1
    gradation = np.arange(sample_num)
    zeros = np.zeros_like(gradation)

    r_grad = np.dstack((gradation, zeros, zeros))
    g_grad = np.dstack((zeros, gradation, zeros))
    b_grad = np.dstack((zeros, zeros, gradation))
    img = np.vstack((r_grad, g_grad, b_grad))

    src_wights = colour.YCBCR_WEIGHTS[src]
    dst_wights = colour.YCBCR_WEIGHTS[dst]
    ycbcr = colour.RGB_to_YCbCr(img,
                                K=src_wights,
                                in_bits=10,
                                in_legal=False,
                                in_int=True,
                                out_bits=10,
                                out_legal=False,
                                out_int=True)
    after_img = colour.YCbCr_to_RGB(ycbcr,
                                    K=dst_wights,
                                    in_bits=10,
                                    in_int=True,
                                    in_legal=False,
                                    out_bits=10,
                                    out_legal=False,
                                    out_int=True)
    after_img = colour.models.eotf_ST2084(after_img / max_input_value)
    after_img[after_img > 1000] = 1000

    title = "src coef = {:s}, dst coef = {:s}".format(src, dst)
    ax1 = pu.plot_1_graph(
        fontsize=20,
        figsize=(10, 8),
        graph_title=title,
        graph_title_size=None,
        xlabel="Input Video Level",
        ylabel="Output Video Level (ST2084)",
        axis_label_size=None,
        legend_size=17,
        xlim=[720, 820],
        ylim=[600, 1050],
        # xtick=[0, 256, 512, 768, 1000, 1023],
        ytick=None,
        xtick_size=None,
        ytick_size=None,
        linewidth=3,
        minor_xtick_num=None,
        minor_ytick_num=None)
    # ax1.plot(gradation, img[0, :, 0], '-r', alpha=0.5, label="red")
    # ax1.plot(gradation, img[1, :, 1], '-g', alpha=0.5, label="green")
    # ax1.plot(gradation, img[2, :, 2], '-b', alpha=0.5, label="blue")
    ax1.plot(gradation, after_img[0, :, 0], '-or', label="red")
    ax1.plot(gradation, after_img[1, :, 1], '-og', label="green")
    ax1.plot(gradation, after_img[2, :, 2], '-ob', label="blue")
    plt.legend(loc='upper left')
    plt.show()
Ejemplo n.º 8
0
"""Showcases *Y'CbCr* *colour encoding* computations."""

import numpy as np

import colour
from colour.utilities import message_box

message_box('"Y\'CbCr" Colour Encoding Computations')

RGB = np.array([0.45620519, 0.03081071, 0.04091952])
message_box(
    f'Converting to the "Y\'CbCr" colour encoding from given "ITU-R BT.709" '
    f"colourspace values:\n\n\t{RGB}")
print(colour.RGB_to_YCbCr(RGB))

print("\n")

message_box(
    f'Converting to the "Y\'CbCr" colour encoding from given"ITU-R BT.601" '
    f"colourspace values using legal range and integer output:\n\n\t{RGB}")
print(
    colour.RGB_to_YCbCr(RGB,
                        colour.WEIGHTS_YCBCR["ITU-R BT.601"],
                        out_legal=True,
                        out_int=True))

print("\n")

YCbCr = np.array([101, 111, 124])
message_box(
    f'Converting to the "ITU-R BT.601" colourspace from given "Y\'CbCr" '
Ejemplo n.º 9
0
 def time_4k(self):
     colour.RGB_to_YCbCr(rgb_4k)
Ejemplo n.º 10
0
 def time_hd(self):
     colour.RGB_to_YCbCr(rgb_hd)
Ejemplo n.º 11
0
 def time_sd(self):
     colour.RGB_to_YCbCr(rgb_sd)
Ejemplo n.º 12
0
import os

input_path = os.path.dirname(__file__)
rgb_sd = colour.read_image(os.path.join(input_path, 'data', 'testImageSD.jpg'))
rgb_hd = colour.read_image(os.path.join(input_path, 'data', 'testImageHD.jpg'))
rgb_4k = colour.read_image(os.path.join(input_path, 'data', 'testImage4K.jpg'))

xyz_sd = colour.sRGB_to_XYZ(rgb_sd)
xyz_hd = colour.sRGB_to_XYZ(rgb_hd)
xyz_4k = colour.sRGB_to_XYZ(rgb_4k)

lab_sd = colour.XYZ_to_Lab(xyz_sd)
lab_hd = colour.XYZ_to_Lab(xyz_hd)
lab_4k = colour.XYZ_to_Lab(xyz_4k)

ycbcr_sd = colour.RGB_to_YCbCr(rgb_sd)
ycbcr_hd = colour.RGB_to_YCbCr(rgb_hd)
ycbcr_4k = colour.RGB_to_YCbCr(rgb_4k)


class sRGBtoXYZ:

    def time_sd(self):
        colour.sRGB_to_XYZ(rgb_sd)

    def time_hd(self):
        colour.sRGB_to_XYZ(rgb_hd)

    def time_4k(self):
        colour.sRGB_to_XYZ(rgb_4k)