color.py
Sub-module providing color functions.
References,
Measuring Colour by R.W.G. Hunt and M.R. Pointer
- rgb_to_xyz(red: int, green: int, blue: int) Tuple[float, float, float][source]
Convert standard RGB color to XYZ color.
D65/2° standard illuminant.
- xyz_to_lab(x_val: float, y_val: float, z_val: float) Tuple[float, float, float][source]
Convert XYZ color to CIE-Lab color.
- rgb_to_lab(red: int, green: int, blue: int) Tuple[float, float, float][source]
Convert RGB color to CIE-Lab color.
- dist_rgb(rgb1: Tuple[int, int, int], rgb2: Tuple[int, int, int]) float[source]
Determine distance between two rgb colors.
- Parameters:
- Returns:
Square of the distance between provided colors
- Return type:
This works by treating RGB colors as coordinates in three dimensional space and finding the closest point within the configured color range using the formula:
d^2 = (r2 - r1)^2 + (g2 - g1)^2 + (b2 - b1)^2
For efficiency, the square of the distance is returned which is sufficient for comparisons
- dist_rgb_weighted(rgb1: Tuple[int, int, int], rgb2: Tuple[int, int, int]) float[source]
Determine the weighted distance between two rgb colors.
- Parameters:
- Returns:
Square of the distance between provided colors
- Return type:
float Similar to a standard distance formula, the values are weighted to approximate human perception of color differences For efficiency, the square of the distance is returned which is sufficient for comparisons
- dist_cie76(rgb1: Tuple[int, int, int], rgb2: Tuple[int, int, int]) float[source]
Determine distance between two rgb colors using the CIE76 algorithm.
- dist_cie94(rgb1: Tuple[int, int, int], rgb2: Tuple[int, int, int]) float[source]
Determine distance between two rgb colors using the CIE94 algorithm.
- dist_cie2000(rgb1: Tuple[int, int, int], rgb2: Tuple[int, int, int]) float[source]
Determine distance between two rgb colors using the CIE2000 algorithm.
- xterm256color_from_rgb(red: int, green: int, blue: int) Tuple[int, Tuple[int, int, int]][source]
Convert RGB values to xterm 256-color cube index and RGB approximation.
Uses the 6x6x6 color cube (indices 16-231) with levels [0,95,135,175,215,255].