from colorspace import cvd_image
"DEMO", "deutan", 0.5); cvd_image(
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
-
image
str
-
Name of the figure which should be converted (png/jpg/jpeg). If
image = "DEMO"
the package demo figure is used. -
cvd
str, list
-
Color vision deficiency or deficiencies. Allowed types are
"deutan"
,"protan"
,"tritan"
,"desaturated"
, and"original"
(unmodified). -
severity
float
-
How severe the color vision deficiency is (
[0.,1.]
). Also used as the amount of desaturation ifcvd
includes"desaturate"
. -
output
None, str
-
If
None
an interactive plotting window will be opened. A str (file name/path) can be given to write the result to disc. -
dropalpha
bool
-
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
"DEMO", "desaturate", 1.0, "output.png"); cvd_image(
"DEMO", ["original", "deutan", "protan"],
cvd_image(0.5, dropalpha = True);
Raises
-
ValueError
: Ifcvd
is empty. -
ValueError
: If no validcvd
method is provided. -
FileNotFounderror
: If the file specified onimage
does not exist. -
ImportError
: When Python module 'imageio' cannot be imported (not installed). -
IOError
: If fileimage
cannot be read usingimageio.imread
. -
ImportError
: Ifmatplotlib.pyplot
cannot be imported (matplotlib
not installed?).