def YCbCr2100Const(xyz, saturation, white_point): wp = np.array(white_point) bt2020 = colour.RGB_COLOURSPACES['ITU-R BT.2020'] data = 100 * colour.XYZ_to_RGB(xyz, wp, bt2020.whitepoint, bt2020.XYZ_to_RGB_matrix, 'CAT02', cctf_encoding=None) data = colour.RGB_to_ICTCP(data) data[..., 1] = saturation * data[..., 1] data[..., 2] = saturation * data[..., 2] data = colour.ICTCP_to_RGB(data) return 0.01 * colour.RGB_to_XYZ(data, bt2020.whitepoint, wp, bt2020.RGB_to_XYZ_matrix, 'CAT02', cctf_encoding=None)
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)
def AscCdl(xyz, saturation, white_point): wp = np.array(white_point) bt709 = colour.RGB_COLOURSPACES['ITU-R BT.709'] data = colour.XYZ_to_RGB(xyz, wp, bt709.whitepoint, bt709.XYZ_to_RGB_matrix, cctf_encoding=None) data[data < 0.0] = 0.0 data = colour.models.rgb.transfer_functions.eotf_inverse_BT1886(data) outdata = np.zeros(data.shape) lum = 0.2126 * data[..., 0] + 0.7152 * data[..., 1] + 0.0722 * data[..., 1] for i in range(3): outdata[..., i] = lum + saturation * (data[..., i] - lum) data = None outdata[outdata < 0] = 0.0 return colour.RGB_to_XYZ( outdata, bt709.whitepoint, wp, bt709.RGB_to_XYZ_matrix, cctf_decoding=colour.models.rgb.transfer_functions.eotf_BT1886)
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 = '.' def lineStyle(cnt): # line_point_marker not shown! c = cnt % len(colors)
'\n\t{0}'.format(XYZ))) D50 = colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D50'] print( colour.XYZ_to_RGB(XYZ, D50, colour.sRGB_COLOURSPACE.whitepoint, colour.sRGB_COLOURSPACE.XYZ_to_RGB_matrix, 'Bradford', colour.sRGB_COLOURSPACE.encoding_cctf)) print('\n') RGB = (1.26651054, 0.91394181, 0.76936593) message_box(('Converting to "CIE XYZ" tristimulus values from given "RGB" ' 'colourspace values:\n' '\n\t{0}'.format(RGB))) print( colour.RGB_to_XYZ(RGB, colour.sRGB_COLOURSPACE.whitepoint, D50, colour.sRGB_COLOURSPACE.RGB_to_XYZ_matrix, 'Bradford', colour.sRGB_COLOURSPACE.decoding_cctf)) print('\n') message_box(('Converting to "sRGB" colourspace from given "CIE XYZ" ' 'tristimulus values using convenient definition:\n' '\n\t{0}'.format(XYZ))) print(colour.XYZ_to_sRGB(XYZ, D50)) print('\n') message_box(('Converting to "CIE UCS" colourspace from given "CIE XYZ" ' 'tristimulus values:\n' '\n\t{0}'.format(XYZ))) print(colour.XYZ_to_UCS(XYZ))
# measurement between the colors) as a value in the lists; doing this # with manual nested for loops because itertools returns tuples (and other reasons that # may not be valid) ; # Conditional print: only print this information if we're overwriting original palette file (because if we aren't overwriting it, the user may be piping output to a new palette file that they wouldn't want cluttered with other information that breaks the file format: if overwriteOriginalList == True: print('Input file is ', hexpltFileNamePassedToScript) print('Getting deltaE for all color combinations . . .') for i in range(len(colors_list)): for j in range(i + 1, len(colors_list)): i_RGB = tuple(int(colors_list[i][x:x+2], 16) for x in (0, 2, 4)) j_RGB = tuple(int(colors_list[j][x:x+2], 16) for x in (0, 2, 4)) # convert those to percent (0 to 1) per colour-science expectation: percent_i_RGB = [(i_RGB[0] / 255), (i_RGB[1] / 255), (i_RGB[2] / 255)] percent_j_RGB = [(j_RGB[0] / 255), (j_RGB[1] / 255), (j_RGB[2] / 255)] # RGB to XYZ: RGB_i_as_XYZ = colour.RGB_to_XYZ(percent_i_RGB, illuminant_RGB, illuminant_XYZ, RGB_to_XYZ_matrix, chromatic_adaptation_transform) RGB_j_as_XYZ = colour.RGB_to_XYZ(percent_j_RGB, illuminant_RGB, illuminant_XYZ, RGB_to_XYZ_matrix, chromatic_adaptation_transform) # color comparison from XYZ through a delta function in another color space: # CAM16 boneyard: # RGB_i_as_CAM16 = colour.XYZ_to_CAM16(RGB_i_as_XYZ, XYZ_w, L_A, Y_b, CAM16_SURROUND, 0) # RGB_i_as_CAM16 = colour.XYZ_to_CAM16(RGB_j_as_XYZ, XYZ_w, L_A, Y_b, CAM16_SURROUND, 0) # CAM16_Specification(J=14.25387410524929, C=26.098284643489645, h=32.022241090829169, s=148.81680522210502, Q=8.1330918133918981, M=18.011904219372205, H=15.205855285709777, HC=None) # re: https://colour.readthedocs.io/en/develop/generated/colour.difference.delta_E_CAM16UCS.html # distance = colour.difference.delta_E_CAM16UCS(RGB_i_as_Jab, RGB_i_as_CAM16) # colour.delta_E(RGB_i_as_Jab, RGB_i_as_CAM16, method='CAM16-UCS') # NOPE -- that ran into a brickwall when I searched for a delta_E function that would take that result. # IS NONE FOUND. And no compare functions I find will use Jch from that. # INSTEAD; going with defaults because I don't understand the second constants param given here: # https://colour.readthedocs.io/en/develop/generated/colour.XYZ_to_JzAzBz.html RGB_i_as_JzAzBz = colour.XYZ_to_JzAzBz(RGB_i_as_XYZ) RGB_j_as_JzAzBz = colour.XYZ_to_JzAzBz(RGB_j_as_XYZ)
colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D50'], colour.sRGB_COLOURSPACE.whitepoint, colour.sRGB_COLOURSPACE.to_RGB, 'Bradford', colour.sRGB_COLOURSPACE.transfer_function)) print('\n') RGB = [1.26651054, 0.91394181, 0.76936593] message_box(('Converting to "CIE XYZ" colourspace from given "RGB" ' 'colourspace values:\n' '\n\t{0}'.format(RGB))) print(colour.RGB_to_XYZ( RGB, colour.sRGB_COLOURSPACE.whitepoint, colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D50'], colour.sRGB_COLOURSPACE.to_XYZ, 'Bradford', colour.sRGB_COLOURSPACE.inverse_transfer_function)) print('\n') message_box(('Converting to "sRGB" colourspace from given "CIE XYZ" ' 'colourspace values using convenient definition:\n' '\n\t{0}'.format(XYZ))) print(colour.XYZ_to_sRGB( XYZ, colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D50'])) print('\n')
colour.RGB_COLOURSPACES['sRGB'].XYZ_to_RGB_matrix, 'Bradford', colour.RGB_COLOURSPACES['sRGB'].cctf_encoding, )) print('\n') RGB = np.array([0.45620519, 0.03081071, 0.04091952]) message_box(('Converting to "CIE XYZ" tristimulus values from given "RGB" ' 'colourspace values:\n' '\n\t{0}'.format(RGB))) print( colour.RGB_to_XYZ( RGB, colour.RGB_COLOURSPACES['sRGB'].whitepoint, D65, colour.RGB_COLOURSPACES['sRGB'].RGB_to_XYZ_matrix, 'Bradford', colour.RGB_COLOURSPACES['sRGB'].cctf_decoding, )) print('\n') message_box(('Converting to "sRGB" colourspace from given "CIE XYZ" ' 'tristimulus values using convenient definition:\n' '\n\t{0}'.format(XYZ))) print(colour.XYZ_to_sRGB(XYZ, D65)) print('\n') message_box(('Converting to "CIE 1960 UCS" colourspace from given "CIE XYZ" ' 'tristimulus values:\n'
def RGB_to_Lab(space, pt): XYZ = colour.RGB_to_XYZ(pt, space.whitepoint, D50, space.RGB_to_XYZ_matrix) return colour.XYZ_to_Lab(XYZ)
colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D50'], colour.sRGB_COLOURSPACE.whitepoint, colour.sRGB_COLOURSPACE.XYZ_to_RGB_matrix, 'Bradford', colour.sRGB_COLOURSPACE.encoding_cctf)) print('\n') RGB = (1.26651054, 0.91394181, 0.76936593) message_box(('Converting to "CIE XYZ" tristimulus values from given "RGB" ' 'colourspace values:\n' '\n\t{0}'.format(RGB))) print(colour.RGB_to_XYZ( RGB, colour.sRGB_COLOURSPACE.whitepoint, colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D50'], colour.sRGB_COLOURSPACE.RGB_to_XYZ_matrix, 'Bradford', colour.sRGB_COLOURSPACE.decoding_cctf)) print('\n') message_box(('Converting to "sRGB" colourspace from given "CIE XYZ" ' 'tristimulus values using convenient definition:\n' '\n\t{0}'.format(XYZ))) print(colour.XYZ_to_sRGB( XYZ, colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D50'])) print('\n')
colour.RGB_COLOURSPACES["sRGB"].matrix_XYZ_to_RGB, "Bradford", colour.RGB_COLOURSPACES["sRGB"].cctf_encoding, )) print("\n") RGB = np.array([0.45620519, 0.03081071, 0.04091952]) message_box( f'Converting to "CIE XYZ" tristimulus values from given "RGB" colourspace ' f"values:\n\n\t{RGB}") print( colour.RGB_to_XYZ( RGB, colour.RGB_COLOURSPACES["sRGB"].whitepoint, D65, colour.RGB_COLOURSPACES["sRGB"].matrix_RGB_to_XYZ, "Bradford", colour.RGB_COLOURSPACES["sRGB"].cctf_decoding, )) print("\n") message_box( f'Converting to "sRGB" colourspace from given "CIE XYZ" tristimulus ' f"values using convenient definition:\n\n\t{XYZ}") print(colour.XYZ_to_sRGB(XYZ, D65)) print("\n") message_box(f'Converting to "CIE 1960 UCS" colourspace from given "CIE XYZ" ' f"tristimulus values:\n\n\t{XYZ}")
D50, colour.RGB_COLOURSPACES['sRGB'].whitepoint, colour.RGB_COLOURSPACES['sRGB'].XYZ_to_RGB_matrix, 'Bradford', colour.RGB_COLOURSPACES['sRGB'].encoding_cctf, )) print('\n') RGB = np.array([1.26651054, 0.91394181, 0.76936593]) message_box(('Converting to "CIE XYZ" tristimulus values from given "RGB" ' 'colourspace values:\n' '\n\t{0}'.format(RGB))) print(colour.RGB_to_XYZ( RGB, colour.RGB_COLOURSPACES['sRGB'].whitepoint, D50, colour.RGB_COLOURSPACES['sRGB'].RGB_to_XYZ_matrix, 'Bradford', colour.RGB_COLOURSPACES['sRGB'].decoding_cctf, )) print('\n') message_box(('Converting to "sRGB" colourspace from given "CIE XYZ" ' 'tristimulus values using convenient definition:\n' '\n\t{0}'.format(XYZ))) print(colour.XYZ_to_sRGB(XYZ, D50)) print('\n') message_box(('Converting to "CIE UCS" colourspace from given "CIE XYZ" ' 'tristimulus values:\n'