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