color_tools.color_deficiency
Color vision deficiency simulation and correction.
This module provides functions to simulate how colors appear to individuals with various types of color blindness (color vision deficiency, CVD) and to apply corrections that can improve color discriminability for CVD individuals.
Supported deficiency types: - Protanopia: Red-blind (missing L-cones, ~1% of males) - Deuteranopia: Green-blind (missing M-cones, ~1% of males) - Tritanopia: Blue-blind (missing S-cones, ~0.001% of population)
- Example usage:
>>> # Simulate how red appears to someone with protanopia >>> simulated = simulate_protanopia((255, 0, 0)) >>> # Result will be darker, yellowish
>>> # Correct colors to improve discriminability for deuteranopia >>> corrected = correct_deuteranopia((0, 255, 0)) >>> # Result shifts green to be more distinguishable
- color_tools.color_deficiency.simulate_cvd(rgb, deficiency_type)[source]
Simulate how a color appears to someone with color vision deficiency.
This transforms colors to show how they would appear to individuals with various types of color blindness. Useful for testing color schemes for accessibility.
- Parameters:
- Return type:
- Returns:
RGB color as it would appear to someone with the deficiency (0-255)
Example
>>> # See how red appears to someone with protanopia >>> simulate_cvd((255, 0, 0), 'protanopia') (145, 110, 0) # Appears darker, yellowish-brown
>>> # Test if two colors are distinguishable for deuteranopia >>> red_sim = simulate_cvd((255, 0, 0), 'deuteranopia') >>> green_sim = simulate_cvd((0, 255, 0), 'deuteranopia') >>> # If these are too similar, the colors may be confusing
- color_tools.color_deficiency.simulate_protanopia(rgb)[source]
Simulate protanopia (red-blindness).
Protanopia is the absence of red cones (L-cones), affecting ~1% of males. Individuals with protanopia have difficulty distinguishing red from green, and red colors appear significantly darker.
- Parameters:
- Return type:
- Returns:
RGB color as it appears to someone with protanopia (0-255)
Example
>>> simulate_protanopia((255, 0, 0)) # Pure red (145, 110, 0) # Appears dark yellow-brown
- color_tools.color_deficiency.simulate_deuteranopia(rgb)[source]
Simulate deuteranopia (green-blindness).
Deuteranopia is the absence of green cones (M-cones), affecting ~1% of males. This is the most common form of color blindness. Individuals have difficulty distinguishing red from green, but unlike protanopia, reds don’t appear darker.
- Parameters:
- Return type:
- Returns:
RGB color as it appears to someone with deuteranopia (0-255)
Example
>>> simulate_deuteranopia((0, 255, 0)) # Pure green (159, 178, 0) # Appears yellowish
- color_tools.color_deficiency.simulate_tritanopia(rgb)[source]
Simulate tritanopia (blue-blindness).
Tritanopia is the absence of blue cones (S-cones), affecting ~0.001% of the population. This is very rare. Individuals have difficulty distinguishing blue from yellow/green.
- Parameters:
- Return type:
- Returns:
RGB color as it appears to someone with tritanopia (0-255)
Example
>>> simulate_tritanopia((0, 0, 255)) # Pure blue (0, 172, 133) # Appears cyan/turquoise
- color_tools.color_deficiency.correct_cvd(rgb, deficiency_type)[source]
Apply color correction for color vision deficiency.
This transforms colors to improve discriminability for individuals with color blindness. The correction cannot restore missing color information, but can shift colors to utilize the remaining functional cone types more effectively.
Note: Corrected images should be viewed by individuals with the specific deficiency - they will not look “correct” to people with normal color vision.
- Parameters:
- Return type:
- Returns:
RGB color corrected for the deficiency (0-255)
Example
>>> # Correct red for protanopia viewers >>> correct_cvd((255, 0, 0), 'protanopia') (178, 178, 191) # Shifted to be more visible
>>> # Improve green discriminability for deuteranopia >>> correct_cvd((0, 255, 0), 'deuteranopia') (178, 0, 178) # Shifted toward magenta
- color_tools.color_deficiency.correct_protanopia(rgb)[source]
Correct colors for protanopia (red-blindness).
Shifts reds toward orange/yellow to increase visibility and improve discrimination between red and green for red-blind individuals.
- Parameters:
- Return type:
- Returns:
RGB color corrected for protanopia (0-255)
Example
>>> correct_protanopia((255, 0, 0)) # Pure red (178, 178, 191) # Shifted to be distinguishable
- color_tools.color_deficiency.correct_deuteranopia(rgb)[source]
Correct colors for deuteranopia (green-blindness).
Adjusts greens and reds to be more distinguishable for green-blind individuals by utilizing blue channel contrast.
- Parameters:
- Return type:
- Returns:
RGB color corrected for deuteranopia (0-255)
Example
>>> correct_deuteranopia((0, 255, 0)) # Pure green (178, 0, 178) # Shifted toward magenta
- color_tools.color_deficiency.correct_tritanopia(rgb)[source]
Correct colors for tritanopia (blue-blindness).
Modifies blues and yellows to increase contrast for blue-blind individuals by enhancing red/green channel differences.
- Parameters:
- Return type:
- Returns:
RGB color corrected for tritanopia (0-255)
Example
>>> correct_tritanopia((0, 0, 255)) # Pure blue (178, 178, 0) # Shifted toward yellow for contrast