---
title: "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

<pre><code class='language-python'>cvd_image(image=&#x27;DEMO&#x27;,<br/>          cvd=&#x27;desaturate&#x27;, severity=1.0,<br/>          output=None, dropalpha=False)</code></pre>

### Arguments

<dl class="pyp-list param-list">
  <dt style = "white-space: nowrap; font-family: monospace; vertical-align: top">
   <code id="colorspace.cvd_image.cvd_image:image">image</code><code class="argument-class">str</code>
  </dt>
 <dd>Name of the figure which should be converted
(png/jpg/jpeg). If `image = "DEMO"` the package demo figure is used.</dd>
  <dt style = "white-space: nowrap; font-family: monospace; vertical-align: top">
   <code id="colorspace.cvd_image.cvd_image:cvd">cvd</code><code class="argument-class">str, list</code>
  </dt>
 <dd>Color vision deficiency or deficiencies. Allowed types are
`"deutan"`, `"protan"`, `"tritan"`, `"desaturated"`,
and `"original"` (unmodified).</dd>
  <dt style = "white-space: nowrap; font-family: monospace; vertical-align: top">
   <code id="colorspace.cvd_image.cvd_image:severity">severity</code><code class="argument-class">float</code>
  </dt>
 <dd>How severe the color vision deficiency is
(`[0.,1.]`).  Also used as the amount of desaturation if `cvd`
includes `"desaturate"`.</dd>
  <dt style = "white-space: nowrap; font-family: monospace; vertical-align: top">
   <code id="colorspace.cvd_image.cvd_image:output">output</code><code class="argument-class">None, str</code>
  </dt>
 <dd>If `None` an interactive plotting window will
be opened. A str (file name/path) can be given to write the result
to disc.</dd>
  <dt style = "white-space: nowrap; font-family: monospace; vertical-align: top">
   <code id="colorspace.cvd_image.cvd_image:dropalpha">dropalpha</code><code class="argument-class">bool</code>
  </dt>
 <dd>Drop alpha channel, defaults to `False`.  Only
useful for png figures having an alpha channel.</dd>
</dl>

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

```{python}
#| echo: true
#| warning: true
#| error: true
from colorspace import cvd_image
cvd_image("DEMO", "deutan", 0.5);
```

```{python}
#| echo: true
#| warning: true
#| error: true
cvd_image("DEMO", "desaturate", 1.0, "output.png");
```

```{python}
#| echo: true
#| warning: true
#| error: true
cvd_image("DEMO", ["original", "deutan", "protan"],
             0.5, dropalpha = True);
```




### Raises

<ul class="python-raises">
<li><code class="text-warning">ValueError</code>: If `cvd` is empty.
<li><code class="text-warning">ValueError</code>: If no valid `cvd` method is provided.
<li><code class="text-warning">FileNotFounderror</code>: If the file specified on `image` does not exist.
<li><code class="text-warning">ImportError</code>: When Python module &#x27;imageio&#x27; cannot be imported (not installed).
<li><code class="text-warning">IOError</code>: If file `image` cannot be read using `imageio.imread`.
<li><code class="text-warning">ImportError</code>: If `matplotlib.pyplot` cannot be imported (`matplotlib` not installed?).
</ul>

