color_tools.matrices

Color transformation matrices for various operations.

This module contains transformation matrices used throughout the color_tools package for operations like color deficiency simulation/correction, chromatic adaptation, etc.

All matrices are documented with their sources and intended use.

⚠️ WARNING: These matrices are from peer-reviewed scientific research and should

NOT be modified. Integrity verification is available via ColorConstants class.

color_tools.matrices.PROTANOPIA_SIMULATION: Tuple[Tuple[float, float, float], Tuple[float, float, float], Tuple[float, float, float]] = ((0.56667, 0.43333, 0.0), (0.55833, 0.44167, 0.0), (0.0, 0.24167, 0.75833))

Protanopia simulation matrix — Red-blind (missing L-cones, ~1% of males). Difficulty distinguishing red from green; red appears darker. Source: Viénot, Brettel, and Mollon (1999)

color_tools.matrices.DEUTERANOPIA_SIMULATION: Tuple[Tuple[float, float, float], Tuple[float, float, float], Tuple[float, float, float]] = ((0.625, 0.375, 0.0), (0.7, 0.3, 0.0), (0.0, 0.3, 0.7))

Deuteranopia simulation matrix — Green-blind (missing M-cones, ~1% of males). Most common form of color vision deficiency. Source: Viénot, Brettel, and Mollon (1999)

color_tools.matrices.TRITANOPIA_SIMULATION: Tuple[Tuple[float, float, float], Tuple[float, float, float], Tuple[float, float, float]] = ((0.95, 0.05, 0.0), (0.0, 0.43333, 0.56667), (0.0, 0.475, 0.525))

Tritanopia simulation matrix — Blue-blind (missing S-cones, ~0.001% of population). Difficulty distinguishing blue from yellow; very rare. Source: Viénot, Brettel, and Mollon (1999)

color_tools.matrices.ALL_SIMULATION: Tuple[Tuple[float, float, float], Tuple[float, float, float], Tuple[float, float, float]] = ((0.71389, 0.28611, 0.0), (0.41944, 0.39167, 0.18889), (0.0, 0.33889, 0.66111))

Combined (all-types) simulation matrix — element-wise average of the three deficiency simulation matrices. Each row still sums to 1.0, so it remains a valid color projection. Useful as a “worst-case” accessibility diagnostic: colors that appear similar after this transform are confusable to at least one of the three major CVD types simultaneously. Computed as: (PROTANOPIA_SIMULATION + DEUTERANOPIA_SIMULATION + TRITANOPIA_SIMULATION) / 3

color_tools.matrices.PROTANOPIA_CORRECTION: Tuple[Tuple[float, float, float], Tuple[float, float, float], Tuple[float, float, float]] = ((0.0, 0.0, 0.0), (0.7, 1.0, 0.0), (0.7, 0.0, 1.0))

Protanopia correction matrix — shifts reds toward orange/yellow to increase visibility for red-blind individuals. Source: Fidaner et al. (2005) daltonization algorithm

color_tools.matrices.DEUTERANOPIA_CORRECTION: Tuple[Tuple[float, float, float], Tuple[float, float, float], Tuple[float, float, float]] = ((1.0, 0.7, 0.0), (0.0, 0.0, 0.0), (0.0, 0.7, 1.0))

Deuteranopia correction matrix — adjusts greens to be more distinguishable for green-blind individuals. Source: Fidaner et al. (2005) daltonization algorithm

color_tools.matrices.TRITANOPIA_CORRECTION: Tuple[Tuple[float, float, float], Tuple[float, float, float], Tuple[float, float, float]] = ((1.0, 0.0, 0.7), (0.0, 1.0, 0.7), (0.0, 0.0, 0.0))

Tritanopia correction matrix — modifies blues and yellows to increase contrast for blue-blind individuals. Source: Fidaner et al. (2005) daltonization algorithm

color_tools.matrices.ALL_CORRECTION: Tuple[Tuple[float, float, float], Tuple[float, float, float], Tuple[float, float, float]] = ((0.66667, 0.23333, 0.23333), (0.23333, 0.66667, 0.23333), (0.23333, 0.23333, 0.66667))

Combined (all-types) correction matrix — element-wise average of the three deficiency correction matrices. Redistributes the error signal equally across all three channels, improving discriminability for all CVD types simultaneously. Neutral colors (white, grey, black) are always preserved because the correction is applied to the error signal (original − simulated), not to the original. Computed as: (PROTANOPIA_CORRECTION + DEUTERANOPIA_CORRECTION + TRITANOPIA_CORRECTION) / 3

color_tools.matrices.multiply_matrix_vector(matrix, vector)[source]

Multiply a 3x3 matrix by a 3D vector.

This is a helper function for applying transformation matrices to RGB values.

Parameters:
Return type:

Tuple[float, float, float]

Returns:

Transformed 3D vector

Example

>>> matrix = ((1, 0, 0), (0, 1, 0), (0, 0, 1))  # Identity matrix
>>> vector = (0.5, 0.3, 0.8)
>>> multiply_matrix_vector(matrix, vector)
(0.5, 0.3, 0.8)
color_tools.matrices.get_simulation_matrix(deficiency_type)[source]

Get the simulation matrix for a specific color deficiency type.

Parameters:

deficiency_type (str) – Type of color deficiency - ‘protanopia’ or ‘protan’: Red-blind - ‘deuteranopia’ or ‘deutan’: Green-blind - ‘tritanopia’ or ‘tritan’: Blue-blind - ‘all’: Combined average of all three deficiency types

Return type:

Tuple[Tuple[float, float, float], Tuple[float, float, float], Tuple[float, float, float]]

Returns:

3x3 transformation matrix for simulating the deficiency

Raises:

ValueError – If deficiency_type is not recognized

Example

>>> matrix = get_simulation_matrix('protanopia')
>>> # Use matrix to transform colors
color_tools.matrices.get_correction_matrix(deficiency_type)[source]

Get the correction matrix for a specific color deficiency type.

Parameters:

deficiency_type (str) – Type of color deficiency - ‘protanopia’ or ‘protan’: Red-blind - ‘deuteranopia’ or ‘deutan’: Green-blind - ‘tritanopia’ or ‘tritan’: Blue-blind - ‘all’: Combined average of all three deficiency types

Return type:

Tuple[Tuple[float, float, float], Tuple[float, float, float], Tuple[float, float, float]]

Returns:

3x3 transformation matrix for correcting colors for the deficiency

Raises:

ValueError – If deficiency_type is not recognized

Example

>>> matrix = get_correction_matrix('deuteranopia')
>>> # Use matrix to transform colors for better discriminability