color.py¶
Sub-module providing color functions.
References,
Measuring Colour by R.W.G. Hunt and M.R. Pointer
-
rgb_to_xyz
(red, green, blue)[source]¶ Convert standard RGB color to XYZ color.
- Parameters
- Returns
Tuple (X, Y, Z) representing XYZ color
- Return type
D65/2° standard illuminant
-
xyz_to_lab
(x_val, y_val, z_val)[source]¶ Convert XYZ color to CIE-Lab color.
- Parameters
- Returns
Tuple (L, a, b) representing CIE-Lab color
- Return type
D65/2° standard illuminant
-
rgb_to_lab
(red, green, blue)[source]¶ Convert RGB color to CIE-Lab color.
- Parameters
- Returns
Tuple (L, a, b) representing CIE-Lab color
- Return type
D65/2° standard illuminant
-
dist_rgb
(rgb1, rgb2)[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, rgb2)[source]¶ Determine the weighted distance between two rgb colors.
- Parameters
- Returns
Square of the distance between provided colors
- Return type
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, rgb2)[source]¶ Determine distance between two rgb colors using the CIE94 algorithm.
- Parameters
- Returns
Square of the distance between provided colors
- Return type
For efficiency, the square of the distance is returned which is sufficient for comparisons
-
dist_cie94
(rgb1, rgb2)[source]¶ Determine distance between two rgb colors using the CIE94 algorithm.
- Parameters
- Returns
Square of the distance between provided colors
- Return type
For efficiency, the square of the distance is returned which is sufficient for comparisons