Check Images for Color Constraints

Description

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

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

Requires the Python modules matplotlib and imageio to be installed.

Usage

cvd_image(image='DEMO',
cvd='desaturate', severity=1.0,
output=None, dropalpha=False)

Arguments

imagestr
Name of the figure which should be converted (png/jpg/jpeg). If image = "DEMO" the package demo figure is used.
cvdstr, list
Color vision deficiency or deficiencies. Allowed types are "deutan", "protan", "tritan", "desaturated", and "original" (unmodified).
severityfloat
How severe the color vision deficiency is ([0.,1.]). Also used as the amount of desaturation if cvd includes "desaturate".
outputNone, str
If None an interactive plotting window will be opened. A str (file name/path) can be given to write the result to disc.
dropalphabool
Drop alpha channel, defaults to False. Only useful for png figures having an alpha channel.

Return

Returns a matplotlib.figure.Figure object if output = None, else the return of the function is identical to output; the figure which has just been created.

Examples

from colorspace import cvd_image
cvd_image("DEMO", "deutan", 0.5);

cvd_image("DEMO", "desaturate", 1.0, "output.png");

cvd_image("DEMO", ["original", "deutan", "protan"],
             0.5, dropalpha = True);

Raises

  • ValueError: If cvd is empty.
  • ValueError: If no valid cvd method is provided.
  • FileNotFounderror: If the file specified on image does not exist.
  • ImportError: When Python module 'imageio' cannot be imported (not installed).
  • IOError: If file image cannot be read using imageio.imread.
  • ImportError: If matplotlib.pyplot cannot be imported (matplotlib not installed?).