Color Vision Deficiency Emulator

A function called cvd_emulator allows to …

The cvd_emulator function provides a simple way to simulate color vision deficiencies. For an existing pixel image (jpg/png/jpeg) simulations for deuteranope, protanope, and tritanope color vision can be performed with different severity levels.

The following plot shows a colorful figure on the left (original image) followed by deuteranope sight and monochromatic sight.

from colorspace import cvd_emulator
cvd_emulator(cvd = ['original','deutan','desaturate'], severity = 1)

The additional parameter allows to adjust the severity of the color vision deficiency ([0.-1.]), here shown for an 80 percent deficiency and deuteranope, protanope, and tritanope color vision.

from colorspace.hcl_converter import hcl_converter
cvd_emulator(cvd = ['deutan', 'protan', 'tritan'], severity = .8)
## /home/retos/Software/python-colorspace/venv/lib/python2.7/site-packages/matplotlib/cbook/deprecation.py:107: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance.  In a future version, a new instance will always be created and returned.  Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
##   warnings.warn(message, mplDeprecation, stacklevel=1)

Thanks to [@mariogogh](https://unsplash.com/@mariogogh) on unsplash.com for the colorful picture. By the way, the bird is used to trace the handling of RGBA values.

Function Reference

cvd_emulator.cvd_emulator(image = "DEMO", cvd = "desaturate", severity = 1.0, output = None, dropalpha = False)[source]

Simulate color deficiencies on png/jpg/jpeg figures. Takes an existing pixel image and simulates different color vision deficiencies.

The function displays a matplotlib figure if output is set to None. If the parameter output is set, the converted figure will be stored. If only one color vision deficiency is defined (e.g., cvd = "desaturate") a figure of the same type and size as the input figure will be saved to the disc. If multiple cvd’s are specified a multi-panel plot will be stored under output.

Parameters:
  • image (str) – name of the figure which should be converted (png/jpg/jpeg). If image = "DEMO" the package demo figure will be used.
  • cvd (str, list) – the color vision deficiency. Allowed types are deutanope, protanope, tritanope, and desaturated. Input is either a single string or a list of strings which define the cvd’s which should be simulated.
  • severity (float) – how severe the color vision deficiency is ([0.,1.]). Also used as the amount of desaturation if cvd = "desaturate".
  • output (string) – optional. It None an interactive plotting window will be opened. If a string is given the figure will be written to output.
  • dropalpha (bool) – whether or not to drop the alpha channel. Only useful for figures having an alpha channel (png w/ alpha).

Examples

>>> from colorspace.cvd_emulator import cvd_emulator
>>> cvd_emulator("DEMO", "deutan", 0.5)
>>> cvd_emulator("DEMO", "desaturate", 1.0, "output.png")
>>> cvd_emulator("DEMO", ["original", "deutan", "protan"], 0.5, dropalpha = True)

Note

Requires the modules matplotlib and imageio.