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)
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]) message_box(('Converting to "ITU-R BT.601" colourspace from given "Y\'CbCr" ' 'values using legal range and integer input:\n' '\n\t{0}'.format(RGB))) print(colour.YCbCr_to_RGB(YCbCr, in_legal=True, in_int=True)) print('\n') RGB = np.array([0.18, 0.18, 0.18]) message_box(('Converting to "Yc\'Cbc\'Crc\'" colour encoding from given ' '"ITU-R BT.2020" values using legal range, integer output on ' 'a 10-bit system:\n\n\t{0}'.format(RGB))) print( colour.RGB_to_YcCbcCrc(RGB, out_bits=10, out_legal=True, out_int=True, is_12_bits_system=False)) print('\n')
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()
def time_4k(self): colour.YCbCr_to_RGB(ycbcr_4k)
def time_hd(self): colour.YCbCr_to_RGB(ycbcr_hd)
def time_sd(self): colour.YCbCr_to_RGB(ycbcr_sd)