# color.py¶

Sub-module providing color functions.

References,

rgb_to_xyz(red, green, blue)[source]

Convert standard RGB color to XYZ color.

D65/2° standard illuminant.

Parameters
• red (int) – RGB value of Red.

• green (int) – RGB value of Green.

• blue (int) – RGB value of Blue.

Returns

Tuple (X, Y, Z) representing XYZ color

Return type

tuple

xyz_to_lab(x_val, y_val, z_val)[source]

Convert XYZ color to CIE-Lab color.

Parameters
• x_val (float) – XYZ value of X.

• y_val (float) – XYZ value of Y.

• z_val (float) – XYZ value of Z.

Returns

Tuple (L, a, b) representing CIE-Lab color

Return type

tuple D65/2° standard illuminant

rgb_to_lab(red, green, blue)[source]

Convert RGB color to CIE-Lab color.

Parameters
• red (int) – RGB value of Red.

• green (int) – RGB value of Green.

• blue (int) – RGB value of Blue.

Returns

Tuple (L, a, b) representing CIE-Lab color

Return type

tuple D65/2° standard illuminant

dist_rgb(rgb1, rgb2)[source]

Determine distance between two rgb colors.

Parameters
• rgb1 (tuple) – RGB color definition

• rgb2 (tuple) – RGB color definition

Returns

Square of the distance between provided colors

Return type

float

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
• rgb1 (tuple) – RGB color definition

• rgb2 (tuple) – RGB color definition

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, rgb2)[source]

Determine distance between two rgb colors using the CIE94 algorithm.

Parameters
• rgb1 (tuple) – RGB color definition

• rgb2 (tuple) – RGB color definition

Returns

Square of the distance between provided colors

Return type

float 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
• rgb1 (tuple) – RGB color definition

• rgb2 (tuple) – RGB color definition

Returns

Square of the distance between provided colors

Return type

float For efficiency, the square of the distance is returned which is sufficient for comparisons

dist_cie2000(rgb1, rgb2)[source]

Determine distance between two rgb colors using the CIE2000 algorithm.

Parameters
• rgb1 (tuple) – RGB color definition

• rgb2 (tuple) – RGB color definition

Returns

Square of the distance between provided colors

Return type

float For efficiency, the square of the distance is returned which is sufficient for comparisons