def generate_colorchecker_rgb(name, model, t, checker, cmfs, ill): print( 'pub static ref %s_SCENE_REFERRED: HashMap<String, %s> = hashmap! {' % (name, t)) xyz_wp = colour.models.rgb.RGB_COLOURSPACES['sRGB'].whitepoint for swatch_name in checker.keys(): sd = checker[swatch_name] xyz = sd_to_XYZ(sd, cmfs, ill) rgb = colour.XYZ_to_RGB(xyz / 100.0, xyz_wp, model.whitepoint, model.XYZ_to_RGB_matrix) print(' "%s".into() => rgbf(%.24f, %.24f, %.24f),' % (name_map[swatch_name], rgb[0], rgb[1], rgb[2])) print('};\n') print('pub static ref %s_ENCODED: HashMap<String, %s> = hashmap! {' % (name, t)) for swatch_name in checker.keys(): sd = checker[swatch_name] xyz = sd_to_XYZ(sd, cmfs, ill) rgb = colour.XYZ_to_RGB(xyz / 100.0, xyz_wp, model.whitepoint, model.XYZ_to_RGB_matrix) rgb = model.encoding_cctf(rgb) print(' "%s".into() => rgbf(%.24f, %.24f, %.24f),' % (name_map[swatch_name], rgb[0], rgb[1], rgb[2])) print('};\n')
def make_ebu_test_colour_patch(): luv_file = "./doc/ebu_test_colour_value.csv" luv_data = np.loadtxt(luv_file, delimiter=",", skiprows=1, usecols=(5, 6, 7)) # convert from Yu'v' to Yuv luv_data[:, 2] = luv_data[:, 2] * 2 / 3 # Yuv to XYZ xy = colour.UCS_uv_to_xy(luv_data[:, 1:]) xyY = np.stack((xy[:, 0], xy[:, 1], (luv_data[:, 0] / 100.0))).T # print(xyY) large_xyz = colour.xyY_to_XYZ(xyY) # print(large_xyz) rgb_name = 'ITU-R BT.709' illuminant_XYZ = colour.RGB_COLOURSPACES[rgb_name].whitepoint illuminant_RGB = colour.RGB_COLOURSPACES[rgb_name].whitepoint chromatic_adaptation_transform = 'Bradford' xyz_to_rgb_mtx = colour.RGB_COLOURSPACES[rgb_name].XYZ_to_RGB_matrix rgb_val = colour.XYZ_to_RGB(large_xyz, illuminant_XYZ, illuminant_RGB, xyz_to_rgb_mtx, chromatic_adaptation_transform) print(rgb_val) # rgb_val = np.uint16(np.round((rgb_val ** 1/2.35) * 0xFFFF)) # print(rgb_val) # print(rgb_val ** (1/2.2)) rgb_val = np.uint8(np.round((rgb_val**(1 / 2.35)) * 0xFF)) plot_color_patch(rgb_val, v_num=3, h_num=5)
def sRgbToHdr(source: tuple[int, int, int]) -> tuple[int, int, int]: """ 大致思路:先做gamma correction,然后转入XYZ。 在xyY内将Y的极值由sRGB亮度调为输出 亮度,然后转回输出色域的RGB。 args: colour -- (0-255, 0-255, 0-255) """ if source == (0, 0, 0): return (0, 0, 0) args = parse_args() srgb_brightness = args.sub_brightness screen_brightness = args.output_brightness target_colourspace = RGB_COLOURSPACE_BT2020 if args.colourspace == 'dcip3': target_colourspace = RGB_COLOURSPACE_DCI_P3 normalized_source = np.array(source) / 255 linear_source = colour.oetf_inverse(normalized_source, 'ITU-R BT.709') xyz = colour.RGB_to_XYZ(linear_source, RGB_COLOURSPACE_sRGB.whitepoint, D65_ILLUMINANT, RGB_COLOURSPACE_sRGB.matrix_RGB_to_XYZ) xyy = colour.XYZ_to_xyY(xyz) srgb_luma = xyy[2] xyy[2] = xyy[2] * srgb_brightness / screen_brightness xyz = colour.xyY_to_XYZ(xyy) output = colour.XYZ_to_RGB(xyz, D65_ILLUMINANT, target_colourspace.whitepoint, target_colourspace.matrix_XYZ_to_RGB) output = apply_oetf(output, srgb_luma) output = np.trunc(output * 255) return (int(output[0]), int(output[1]), int(output[2]))
def converter(filepath): out_filePath= r'L:\temp\xyz\converted_v2.jpg' in_buf_data = oiio.ImageBuf(filepath) in_buf_roi = oiio.get_roi(in_buf_data.spec()) in_buf_rgb = oiio.ImageBufAlgo.channels(in_buf_data, (0, 1, 2)) # Remove other channels(multi-channels exr) in_array_rgb = in_buf_rgb.get_pixels() colourspace_acescg = colour.RGB_COLOURSPACES['ACEScg'] colourspace_srgb = colour.RGB_COLOURSPACES['sRGB'] # conversion = colour.XYZ_to_sRGB(in_array_rgb) conversion = colour.XYZ_to_RGB(in_array_rgb, colourspace_acescg.whitepoint, colourspace_acescg.whitepoint, colourspace_acescg.XYZ_to_RGB_matrix) conversion_srgb = colour.RGB_to_RGB(conversion, colourspace_acescg, colourspace_srgb, 'Bradford', apply_cctf_encoding= True) converted_array_rgba = conversion_srgb in_buf_rgb.set_pixels(in_buf_roi, converted_array_rgba) # Replace the buffer with the converted pixels if in_buf_data.spec().alpha_channel > 0: # If image has an alpha channel in_buf_alpha = oiio.ImageBufAlgo.channels(in_buf_data, (3,)) # copy the Alpha channel in_buf_rgba = oiio.ImageBufAlgo.channel_append(in_buf_rgb, in_buf_alpha) # Merge the alpha channel back else: in_buf_rgba = in_buf_rgb in_buf_rgba.specmod().attribute("compression", "jpg:100") in_buf_rgba.specmod().attribute("oiio:ColorSpace", 'sRGB') bitdepth = 'uint8' in_buf_rgba.set_write_format(bitdepth) in_buf_rgba.write(out_filePath)
def pixel_processing(self, in_rgb, cctf_decoding=False, cat='Bradford', cctf_encoding=False): """ Args: in_rgb: pixel data (numpy array) cctf_decoding: bool: apply_cctf_decoding cat: chromatic adaptation model cctf_encoding: bool Returns: pixel data converted with odt applied or not """ if self.in_cs: if self.in_cs != self.out_cs or cctf_decoding: output_colourspace = colour.RGB_COLOURSPACES[self.out_cs] cat = cat if self.in_cs == 'XYZ': conversion_rgb = colour.XYZ_to_RGB(in_rgb, output_colourspace.whitepoint, output_colourspace.whitepoint, output_colourspace.XYZ_to_RGB_matrix, chromatic_adaptation_transform=cat) else: print("colorspace conversion") input_colourspace = colour.RGB_COLOURSPACES[self.in_cs] conversion_rgb = colour.RGB_to_RGB(in_rgb, input_colourspace, output_colourspace, chromatic_adaptation_transform=cat, apply_cctf_decoding=cctf_decoding, apply_cctf_encoding=cctf_encoding) else: conversion_rgb = in_rgb else: conversion_rgb = in_rgb odt_result = self.apply_odt(conversion_rgb) return odt_result
def XYZ_to_web(XYZ): """Converts from XYZ tristimulus values to the web colorspace.""" return colour.XYZ_to_RGB(XYZ, WEB_CS.whitepoint, WEB_CS.whitepoint, WEB_CS.XYZ_to_RGB_matrix, encoding_cctf=WEB_CS.encoding_cctf)
def color_correct(image, ref_color_checker, plot=False, method='Cheung 2004', **kwargs): assert method in {'Finlayson 2015', 'Cheung 2004', 'Vandermonde'} # Find the color checker swatches swatches = detect_colour_checkers_segmentation(image)[0][::-1] # define D65 as the standard illuminant we will use D65 = colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D65'] # convert the reference color checker to RGB, by going through XYZ and using the D65 illuminant ref_color_checker_RGB = colour.XYZ_to_RGB( colour.xyY_to_XYZ(list(ref_color_checker.data.values())), ref_color_checker.illuminant, D65, colour.RGB_COLOURSPACES['sRGB'].XYZ_to_RGB_matrix) # plot the color checkers overlapped with the colors extracted from the image if plot: # convert the uncorrected swatches extracted from the image from RGB to xyY by going through XYZ swatches_xyY = colour.XYZ_to_xyY( colour.RGB_to_XYZ( swatches, D65, D65, colour.RGB_COLOURSPACES['sRGB'].RGB_to_XYZ_matrix)) # use the RGB reference color checker to correct just the color checker swatches from the image swatches_corrected = colour.colour_correction(swatches, swatches, ref_color_checker_RGB, method=method, **kwargs) # convert these color corrected swatches from RGB to xyY by going through XYZ swatches_corrected_xyY = colour.XYZ_to_xyY( colour.RGB_to_XYZ( swatches_corrected, D65, D65, colour.RGB_COLOURSPACES['sRGB'].RGB_to_XYZ_matrix)) image_colour_checker = colour.characterisation.ColourChecker( 'Uncorrected Image', OrderedDict(zip(ref_color_checker.data.keys(), swatches_xyY)), D65) image_colour_checker_corrected = colour.characterisation.ColourChecker( 'Corrected Image with {:}'.format(method), OrderedDict( zip(ref_color_checker.data.keys(), swatches_corrected_xyY)), D65) plot_multi_colour_checkers([ref_color_checker, image_colour_checker]) plot_multi_colour_checkers( [ref_color_checker, image_colour_checker_corrected]) return colour.colour_correction(image, swatches, ref_color_checker_RGB, method=method, **kwargs)
def cs_convert_K_to_RGB(colour_temperature): xy = colour.CCT_to_xy(colour_temperature) xyY = np.array([xy[0], xy[1], 1]) XYZ = colour.xyY_to_XYZ(xyY) sRGB = colour.RGB_COLOURSPACES['sRGB'] RGB = colour.XYZ_to_RGB(XYZ, sRGB.whitepoint, sRGB.whitepoint, sRGB.XYZ_to_RGB_matrix) return RGB[0], RGB[1], RGB[2]
def applyHermiteTonemap(xyz, white_point, spline_params=None, rgb_space=colour.RGB_COLOURSPACES['sRGB'], overwrite_params={}): if spline_params is None: spline_params = spline_curve_defaults.copy() spline_params.update(overwrite_params) XYZ_w = colour.xy_to_XYZ(np.array(white_point)) * 100 XYZ_wr = colour.xy_to_XYZ(rgb_space.whitepoint) * 100 xyz_d65 = colour.adaptation.chromatic_adaptation_VonKries( xyz, XYZ_w, XYZ_wr, transform='CAT02') rgb_pure = colour.XYZ_to_RGB(xyz_d65, rgb_space.whitepoint, rgb_space.whitepoint, rgb_space.XYZ_to_RGB_matrix, None, None) rgb_pure = applySplineCurve(rgb_pure, spline_params) ycbcr = np.zeros(xyz_d65.shape) ycbcr[..., 0] = xyz_d65[..., 0] * XYZ_TO_YCbCr_Rec2020[0] + xyz_d65[ ..., 1] * XYZ_TO_YCbCr_Rec2020[1] + xyz_d65[ ..., 2] * XYZ_TO_YCbCr_Rec2020[2] ycbcr[..., 1] = xyz_d65[..., 0] * XYZ_TO_YCbCr_Rec2020[3] + xyz_d65[ ..., 1] * XYZ_TO_YCbCr_Rec2020[4] + xyz_d65[ ..., 2] * XYZ_TO_YCbCr_Rec2020[5] ycbcr[..., 2] = xyz_d65[..., 0] * XYZ_TO_YCbCr_Rec2020[6] + xyz_d65[ ..., 1] * XYZ_TO_YCbCr_Rec2020[7] + xyz_d65[ ..., 2] * XYZ_TO_YCbCr_Rec2020[8] ycbcr[..., 0] = applySplineCurve(ycbcr[..., 0], spline_params) xyz_d65[..., 0] = ycbcr[..., 0] * Rec2020_YCbCr_TO_XYZ[0] + ycbcr[ ..., 1] * Rec2020_YCbCr_TO_XYZ[1] + ycbcr[..., 2] * Rec2020_YCbCr_TO_XYZ[2] xyz_d65[..., 1] = ycbcr[..., 0] * Rec2020_YCbCr_TO_XYZ[3] + ycbcr[ ..., 1] * Rec2020_YCbCr_TO_XYZ[4] + ycbcr[..., 2] * Rec2020_YCbCr_TO_XYZ[5] xyz_d65[..., 2] = ycbcr[..., 0] * Rec2020_YCbCr_TO_XYZ[6] + ycbcr[ ..., 1] * Rec2020_YCbCr_TO_XYZ[7] + ycbcr[..., 2] * Rec2020_YCbCr_TO_XYZ[8] rgb_luma = colour.XYZ_to_RGB(xyz_d65, rgb_space.whitepoint, rgb_space.whitepoint, rgb_space.XYZ_to_RGB_matrix, None, None) return rgb_pure * (1.0 - spline_params['luma_ratio'] ) + rgb_luma * spline_params['luma_ratio']
def simpleSrgb(xyz, white_point=(1.0 / 3, 1.0 / 3)): """ Simple (clipping) sRGB conversion """ srgb = colour.RGB_COLOURSPACES['sRGB'] return colour.XYZ_to_RGB(xyz, np.array(white_point), srgb.whitepoint, srgb.XYZ_to_RGB_matrix, 'CAT02', srgb.encoding_cctf)
def simpleDisplayP3(xyz, white_point=(1.0 / 3, 1.0 / 3)): """ Simple (clipping) DisplayP3 conversion """ disp3 = colour.RGB_COLOURSPACES['Display P3'] return colour.XYZ_to_RGB(xyz, np.array(white_point), disp3.whitepoint, disp3.XYZ_to_RGB_matrix, 'CAT02', disp3.encoding_cctf)
def large_xyz_to_rgb(large_xyz, gamut_str='ITU-R BT.709'): illuminant_XYZ = colour.RGB_COLOURSPACES[gamut_str].whitepoint illuminant_RGB = colour.RGB_COLOURSPACES[gamut_str].whitepoint chromatic_adaptation_transform = 'Bradford' xyz_to_rgb_mtx = colour.RGB_COLOURSPACES[gamut_str].XYZ_to_RGB_matrix rgb_val = colour.XYZ_to_RGB(large_xyz, illuminant_XYZ, illuminant_RGB, xyz_to_rgb_mtx, chromatic_adaptation_transform) return rgb_val
def lab_to_rgb_d65(lab, name='ITU-R BT.2020'): illuminant_XYZ = tpg.D65_WHITE illuminant_RGB = tpg.D65_WHITE chromatic_adaptation_transform = 'CAT02' xyz_to_rgb_matrix = tpg.get_xyz_to_rgb_matrix(name) # Lab to XYZ large_xyz = colour.Lab_to_XYZ(lab, illuminant_XYZ) # XYZ to RGB rgb = colour.XYZ_to_RGB(large_xyz, illuminant_XYZ, illuminant_RGB, xyz_to_rgb_matrix, chromatic_adaptation_transform) return rgb
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)
message_box(('Converting to "CIE XYZ" tristimulus values from given "xy" ' 'chromaticity coordinates:\n' '\n\t{0}'.format(xy))) print(colour.xy_to_XYZ(xy)) print('\n') message_box(('Converting to "RGB" colourspace from given "CIE XYZ" ' 'tristimulus values:\n' '\n\t{0}'.format(XYZ))) D65 = colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D65'] print( colour.XYZ_to_RGB( XYZ, D65, colour.RGB_COLOURSPACES['sRGB'].whitepoint, 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,
xy = (0.43250000, 0.37880000) message_box(('Converting to "CIE XYZ" tristimulus values from given "xy" ' 'chromaticity coordinates:\n' '\n\t{0}'.format(xy))) print(colour.xy_to_XYZ(xy)) print('\n') message_box(('Converting to "RGB" colourspace from given "CIE XYZ" ' 'tristimulus values:\n' '\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')
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)
def convertData(xyz): data = 100 * colour.XYZ_to_RGB(xyz, wp, bt2020.whitepoint, bt2020.XYZ_to_RGB_matrix, 'CAT02', cctf_encoding=None) return colour.RGB_to_ICTCP(data)
xy = np.array([0.43250000, 0.37880000]) message_box(('Converting to "CIE XYZ" tristimulus values from given "xy" ' 'chromaticity coordinates:\n' '\n\t{0}'.format(xy))) print(colour.xy_to_XYZ(xy)) print('\n') message_box(('Converting to "RGB" colourspace from given "CIE XYZ" ' 'tristimulus values:\n' '\n\t{0}'.format(XYZ))) D50 = colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D50'] print(colour.XYZ_to_RGB( 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,
xy = (0.43249999995420696, 0.378800000065942) message_box(('Converting to "CIE XYZ" colourspace from given "xy" ' 'chromaticity coordinates:\n' '\n\t{0}'.format(xy))) print(colour.xy_to_XYZ(xy)) print('\n') message_box(('Converting to "RGB" colourspace from given "CIE XYZ" ' 'colourspace values:\n' '\n\t{0}'.format(XYZ))) print(colour.XYZ_to_RGB( 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,
message_box( f'Converting to "CIE XYZ" tristimulus values from given "xy" chromaticity ' f"coordinates:\n\n\t{xy}") print(colour.xy_to_XYZ(xy)) print("\n") message_box( f'Converting to "RGB" colourspace from given "CIE XYZ" tristimulus ' f"values:\n\n\t{XYZ}") D65 = colour.CCS_ILLUMINANTS["CIE 1931 2 Degree Standard Observer"]["D65"] print( colour.XYZ_to_RGB( XYZ, D65, colour.RGB_COLOURSPACES["sRGB"].whitepoint, 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,
print('\n') message_box('Colour rendition charts spectral power distributions dataset.') pprint(colour.COLOURCHECKERS_SPDS.keys()) print('\n') message_box(('"ColorChecker 2005" colour rendition chart chromaticity ' 'coordinates data:\n' '\n\t("Patch Number", "Patch Name", "x", "y", "Y")')) name, data, illuminant = colour.COLOURCHECKERS['ColorChecker 2005'] for index, name, x, y, Y in data: print(index, name, x, y, Y) print('\n') message_box(('Converting "ColorChecker 2005" colour rendition chart "CIE xyY" ' 'colourspace values to "sRGB" colourspace "RGB" values:\n' '\n\t("Patch Name", ["R", "G", "B"])')) for index, name, x, y, Y in data: RGB = colour.xyY_to_XYZ( colour.XYZ_to_RGB( np.array([[x], [y], [Y]]), illuminant, colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D65'], colour.sRGB_COLOURSPACE.to_RGB, 'Bradford', colour.sRGB_COLOURSPACE.transfer_function)) RGB = [int(round(x * 255)) if x >= 0 else 0 for x in np.ravel(RGB)] print('"{0}": {1}'.format(name, RGB))
print("\n") message_box( '"ColorChecker 2005" colour rendition chart chromaticity coordinates data:\n\n' '\t("Patch Number", "Patch Name", "xyY")' ) name, data, illuminant = colour.CCS_COLOURCHECKERS["ColorChecker 2005"] for name, xyY in data.items(): print(name, xyY) print("\n") message_box( 'Converting the "ColorChecker 2005" colour rendition chart "CIE xyY" ' 'colourspace values to "sRGB" colourspace "RGB" values:\n\n' '\t("Patch Name", ["R", "G", "B"])' ) for name, xyY in data.items(): RGB = colour.XYZ_to_RGB( colour.xyY_to_XYZ(xyY), illuminant, colour.CCS_ILLUMINANTS["CIE 1931 2 Degree Standard Observer"]["D65"], colour.RGB_COLOURSPACES["sRGB"].matrix_XYZ_to_RGB, "Bradford", colour.RGB_COLOURSPACES["sRGB"].cctf_encoding, ) RGB = [int(round(x * 255)) if x >= 0 else 0 for x in np.ravel(RGB)] print(f'"{name}": {RGB}')
xy = (0.43250000, 0.37880000) message_box(('Converting to "CIE XYZ" tristimulus values from given "xy" ' 'chromaticity coordinates:\n' '\n\t{0}'.format(xy))) print(colour.xy_to_XYZ(xy)) print('\n') message_box(('Converting to "RGB" colourspace from given "CIE XYZ" ' 'tristimulus values:\n' '\n\t{0}'.format(XYZ))) print(colour.XYZ_to_RGB( 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,
pprint(sorted(colour.COLOURCHECKERS.keys())) print('\n') message_box('Colour rendition charts spectral power distributions dataset.') pprint(colour.COLOURCHECKERS_SPDS.keys()) print('\n') message_box(('"ColorChecker 2005" colour rendition chart chromaticity ' 'coordinates data:\n' '\n\t("Patch Number", "Patch Name", "x", "y", "Y")')) name, data, illuminant = colour.COLOURCHECKERS['ColorChecker 2005'] for index, name, x, y, Y in data: print(index, name, x, y, Y) print('\n') message_box(('Converting "ColorChecker 2005" colour rendition chart "CIE xyY" ' 'colourspace values to "sRGB" colourspace "RGB" values:\n' '\n\t("Patch Name", ["R", "G", "B"])')) for index, name, x, y, Y in data: RGB = colour.XYZ_to_RGB( colour.xyY_to_XYZ(np.array([x, y, Y])), illuminant, colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D65'], colour.sRGB_COLOURSPACE.XYZ_to_RGB_matrix, 'Bradford', colour.sRGB_COLOURSPACE.encoding_cctf) RGB = [int(round(x * 255)) if x >= 0 else 0 for x in np.ravel(RGB)] print('"{0}": {1}'.format(name, RGB))
pprint(sorted(colour.COLOURCHECKERS.keys())) print('\n') message_box('Colour rendition charts spectral power distributions dataset.') pprint(colour.COLOURCHECKERS_SPDS.keys()) print('\n') message_box(('"ColorChecker 2005" colour rendition chart chromaticity ' 'coordinates data:\n' '\n\t("Patch Number", "Patch Name", "xyY")')) name, data, illuminant = colour.COLOURCHECKERS['ColorChecker 2005'] for index, name, xyY in data: print(index, name, xyY) print('\n') message_box(('Converting "ColorChecker 2005" colour rendition chart "CIE xyY" ' 'colourspace values to "sRGB" colourspace "RGB" values:\n' '\n\t("Patch Name", ["R", "G", "B"])')) for index, name, xyY in data: RGB = colour.XYZ_to_RGB( colour.xyY_to_XYZ(xyY), illuminant, colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D65'], colour.RGB_COLOURSPACES['sRGB'].XYZ_to_RGB_matrix, 'Bradford', colour.RGB_COLOURSPACES['sRGB'].encoding_cctf) RGB = [int(round(x * 255)) if x >= 0 else 0 for x in np.ravel(RGB)] print('"{0}": {1}'.format(name, RGB))
D = row_as_diagonal(D) M_CAT = dot_matrix(np.linalg.inv(M), D) M_CAT = dot_matrix(M_CAT, M) return M_CAT M_cat02 = chromatic_adaptation_matrix_VonKries(wp_srgb_xyz, wp_aces_xyz) print(M_cat02) model_src = colour.models.rgb.RGB_COLOURSPACES['sRGB'] model_dst = colour.models.rgb.RGB_COLOURSPACES['aces'] print('pub static ref ACES_FROM_SRGB: HashMap<String, RGBf64> = hashmap! {') xyz_wp = colour.models.rgb.RGB_COLOURSPACES['sRGB'].whitepoint for swatch_name in colour.COLOURCHECKERS_SDS['BabelColor Average'].keys(): sd = colour.COLOURCHECKERS_SDS['BabelColor Average'][swatch_name] xyz = sd_to_XYZ(sd, cmfs, ill_d65) rgb_srgb = colour.XYZ_to_RGB(xyz / 100.0, xyz_wp, model_src.whitepoint, model_src.XYZ_to_RGB_matrix) rgb_aces = colour.RGB_to_RGB(rgb_srgb, model_src, model_dst) print(' "%s".into() => rgbf(%.24f, %.24f, %.24f),' % (name_map[swatch_name], rgb_aces[0], rgb_aces[1], rgb_aces[2])) print('};\n') # Whitepoints d65_xyz = xy_to_XYZ([0.31270, 0.32900]) print('d65_xyz: ', d65_xyz)