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.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.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:
- 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- 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- 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