def temperature_convert( rgb_in, src_temperature=6500, dst_temperature=5000, chromatic_adaptation="CAT02", color_space=cs.RGB_COLOURSPACES[cs.SRTB]): """ ColorCheckerの色温度を変更する。 rgb_in は linear data とする。 """ src_xy = make_xy_value_from_temperature(src_temperature) dst_xy = make_xy_value_from_temperature(dst_temperature) rgb_to_xyz_matrix = color_space.RGB_to_XYZ_matrix xyz_to_rgb_matrix = color_space.XYZ_to_RGB_matrix large_xyz = RGB_to_XYZ(rgb_in, src_xy, src_xy, rgb_to_xyz_matrix, chromatic_adaptation) rgb_out = XYZ_to_RGB(large_xyz, src_xy, dst_xy, xyz_to_rgb_matrix, chromatic_adaptation) # under flow check if np.min(rgb_out) < 0: print("under flow has occured, at temperature_convert.") rgb_out[rgb_out < 0] = 0 # over flow check if np.max(rgb_out) > 1: print("over flow has occured, at temperature_convert.") rgb_out = rgb_out / np.max(rgb_out) return rgb_out
def color_checker_large_xyz_to_rgb(large_xyz): illuminant_XYZ = D65_WHITE illuminant_RGB = illuminant_XYZ chromatic_adaptation_transform = 'CAT02' xyz_to_rgb_matrix = make_xyz_to_rgb_mtx_2015() rgb = XYZ_to_RGB(large_xyz, illuminant_XYZ, illuminant_RGB, xyz_to_rgb_matrix, chromatic_adaptation_transform) return rgb
def xyY_to_rgb_with_illuminant_c(xyY): """ C光源のXYZ値をD65光源のRGB値に変換する """ large_xyz = xyY_to_XYZ(xyY) illuminant_XYZ = C_WHITE illuminant_RGB = D65_WHITE chromatic_adaptation_transform = 'CAT02' xyz_to_rgb_matrix = sRGB_COLOURSPACE.XYZ_to_RGB_matrix rgb = XYZ_to_RGB(large_xyz, illuminant_XYZ, illuminant_RGB, xyz_to_rgb_matrix, chromatic_adaptation_transform) return rgb
def spectral_locus_visual(colourspace=PRIMARY_COLOURSPACE, colourspace_model=COLOURSPACE_MODEL, cmfs='CIE 1931 2 Degree Standard Observer'): """ Returns the spectral locus visual geometry formatted as *JSON*. Parameters ---------- colourspace : unicode, optional RGB colourspace used to generate the visual geometry. colourspace_model : unicode, optional Colourspace model used to generate the visual geometry. cmfs : unicode, optional Standard observer colour matching functions used to draw the spectral locus. Returns ------- unicode Spectral locus visual geometry formatted as *JSON*. """ colourspace = first_item( filter_RGB_colourspaces(re.escape(colourspace)).values()) cmfs = first_item(filter_cmfs(cmfs).values()) XYZ = cmfs.values XYZ = np.vstack([XYZ, XYZ[0, ...]]) vertices = colourspace_model_axis_reorder( XYZ_to_colourspace_model( XYZ, colourspace.whitepoint, colourspace_model, ), colourspace_model) RGB = normalise_maximum(XYZ_to_RGB( XYZ, colourspace.whitepoint, colourspace.whitepoint, colourspace.matrix_XYZ_to_RGB, ), axis=-1) return buffer_geometry(position=vertices, color=RGB)
def temperature_convert(rgb_in, src_temperature=6500, dst_temperature=5000, chromatic_adaptation="CAT02"): """ ColorCheckerの色温度を変更するぞい """ src_xy = make_xy_value_from_temperature(src_temperature) dst_xy = make_xy_value_from_temperature(dst_temperature) rgb_to_xyz_matrix = sRGB_COLOURSPACE.RGB_to_XYZ_matrix xyz_to_rgb_matrix = sRGB_COLOURSPACE.XYZ_to_RGB_matrix large_xyz = RGB_to_XYZ(rgb_in, src_xy, src_xy, rgb_to_xyz_matrix, chromatic_adaptation) rgb_out = XYZ_to_RGB(large_xyz, src_xy, dst_xy, xyz_to_rgb_matrix, chromatic_adaptation) rgb_out[rgb_out < 0] = 0 # rgb_out[rgb_out > 1] = 1 return rgb_out
def color_checker_large_xyz_to_rgb( large_xyz, color_space=cs.RGB_COLOURSPACES[cs.SRTB]): illuminant_XYZ = D65_WHITE illuminant_RGB = D65_WHITE chromatic_adaptation_transform = None xyz_to_rgb_matrix = color_space.XYZ_to_RGB_matrix rgb = XYZ_to_RGB(large_xyz, illuminant_XYZ, illuminant_RGB, xyz_to_rgb_matrix, chromatic_adaptation_transform) # under flow check if np.min(rgb) < 0: print("under flow has occured, at color_checker_large_xyz_to_rgb.") rgb[rgb < 0] = 0 # over flow check if np.max(rgb) > 1: print("over flow has occured, at color_checker_large_xyz_to_rgb.") rgb = rgb / np.max(rgb) return rgb
def get_normalize_rgb_value_from_small_xy(small_xy, name=cs.BT709): """ Examples -------- >>> xy = calc_xy_from_white_to_primary_n_step(name=cs.BT709, step=5, color='green') >>> print(xy) [[0.3127, 0.3290], [0.3095, 0.3968], [0.3064, 0.4645], [0.3032, 0.5323], [0.3000, 0.6000]] >>> get_normalize_rgb_value_from_small_xy(xy) [[ 1.00000000e+00 1.00000000e+00 1.00000000e+00] [ 5.40536717e-01 1.00000000e+00 5.40536717e-01] [ 2.81687026e-01 1.00000000e+00 2.81687026e-01] [ 1.15605362e-01 1.00000000e+00 1.15605362e-01] [ 1.58799347e-16 1.00000000e+00 4.73916800e-16]] """ large_xyz = xy_to_XYZ(small_xy) xyz_to_rgb_mtx = RGB_COLOURSPACES[name].XYZ_to_RGB_matrix rgb_linear = XYZ_to_RGB(large_xyz, D65_WHITE, D65_WHITE, xyz_to_rgb_mtx) normalize_val = np.max(rgb_linear, axis=-1) rgb_linear /= normalize_val.reshape((rgb_linear.shape[0], 1)) return rgb_linear