Color Vision Deficiency

class CVD.CVD(cols, type_, severity = 1.)[source]

Object to simulate color vision deficiencies (CVD) for protanope, deteranope, and tritanope visual constraints. There are wrapper functions to provide simple access for the users, see deutan(), protan(), and tritan().

No return values, initializes a new CVD object which provides functions to manipulate the colors acording to the color deficiency (type_).

Parameters:
  • cols (list of str or colorobject) – a colorobject (such as RGB, HCL, CIEXYZ) or a list of hex colors
  • type (str) – type of the deficiency which should be simulated. Currently allowed are deutan, protan, and tritan
  • severity (float) – severity in [0., 1.]. Zero means no deficiency, one maximum deficiency

Examples

>>> from colorspace import rainbow_hcl
>>> cols = rainbow_hcl()(10)
>>> from colorspace.CVD import CVD
>>> deut = CVD(cols, "deutan")
>>> prot = CVD(cols, "protan")
>>> trit = CVD(cols, "tritan")
>>> from colorspace import specplot
>>> specplot(deut.colors())
>>> specplot(prot.colors())
>>> specplot(trit.colors())
colors()[source]
Returns:Returns the colors of the object with simulated colors for the color vision deficiency as specified when initializing the object.
Return type:colorobject
deutan_cvd_matrizes(s)[source]

Returns the transformation matrix to simpulate deuteranope color vision deficiency.

Parameters:s (int) – an integer in [0, 11] to specify which matrix sould be returned
Returns:Returns a numpy float matrix of shape 3 x 3. The color deficiency transformation or rotation matrix.
Return type:numpy.ndarray
protan_cvd_matrizes(s)[source]

Returns the transformation matrix to simpulate protanope color vision deficiency.

Parameters:s (int) – an integer in [0, 11] to specify which matrix sould be returned
Returns:Returns a numpy float matrix of shape 3 x 3. The color deficiency transformation or rotation matrix.
Return type:numpy.ndarray
tritan_cvd_matrizes(s)[source]

Returns the transformation matrix to simpulate tritanope color vision deficiency.

Parameters:s (int) – an integer in [0, 11] to specify which matrix sould be returned
Returns:Returns a numpy float matrix of shape 3 x 3. The color deficiency transformation or rotation matrix.
Return type:numpy.ndarray
CVD.desaturate(col, amount = 1.)[source]

Transform a vector of given colors to the corresponding colors with chroma reduced (by a tunable amount) in HCL space.

The colors of the color object col are transformed to the HCL color space. In HCL, In HCL, chroma is reduced and then the color is transformed back to a colorobject of the same class as the input.

Parameters:
  • col (colorobject) – a colorspace color object such as RGB, hexcols, CIELUV, …
  • amount (float) –
    a value in [0.,1.] defining the degree of desaturation.
    amount = 1. removes all color, amount = 0. none
Returns:

Returns a list of modified hex colors.

Return type:

list

Examples

>>> from colorspace import diverging_hcl
>>> from colorspace.colorlib import hexcols
>>> cols = hexcols(diverging_hcl()(10))
>>> from colorspace import specplot
>>> specplot(desaturate(cols))
>>> specplot(desaturate(cols, 0.5))

Todo

Handling of alpha values. And, in addition, add support for hex colors. Currently a list of hex colors as input is not allowed (fix it).

CVD.deutan(cols, severity = 1.)[source]

Transformation of R colors by simulating color vision deficiencies, based on a CVD transform matrix. This function is a interface to the CVD object and returns simulated colors for deuteranope vision (green-yellow-red weakness).

Parameters:
  • cols (list of str or colorobject) – a colorobject (such as RGB, HCL, CIEXYZ) or a list of hex colors
  • severity (float) – severity in [0., 1.]. Zero means no deficiency, one maximum deficiency
Returns:

Returns an object of the same type as the input object cols with modified colors as people with deuteranomaly see these colors (simulated).

Return type:

colorobject

Examples

>>> from colorspace import rainbow_hcl, specplot
>>> cols = rainbow_hcl()(100)
>>> specplot(cols)
>>> specplot(deutan(cols))
>>> specplot(deutan(cols, 0.5))
CVD.protan(cols, severity = 1.)[source]

Transformation of R colors by simulating color vision deficiencies, based on a CVD transform matrix. This function is a interface to the CVD object and returns simulated colors for protanope vision.

Parameters:
  • cols (list of str or colorobject) – a colorobject (such as RGB, HCL, CIEXYZ) or a list of hex colors
  • severity (float) – severity in [0., 1.]. Zero means no deficiency, one maximum deficiency
Returns:

Returns an object of the same type as the input object cols with modified colors as people with protanope color vision might see the colors (simulated).

Return type:

colorobject

Examples

>>> from colorspace import rainbow_hcl, specplot
>>> cols = rainbow_hcl()(100)
>>> specplot(cols)
>>> specplot(protan(cols))
>>> specplot(protan(cols, 0.5))
CVD.tritan(cols, severity = 1.)[source]

Transformation of R colors by simulating color vision deficiencies, based on a CVD transform matrix. This function is a interface to the CVD object and returns simulated colors for tritanope vision.

Parameters:
  • cols (list of str or colorobject) – a colorobject (such as RGB, HCL, CIEXYZ) or a list of hex colors
  • severity (float) – severity in [0., 1.]. Zero means no deficiency, one maximum deficiency
Returns:

Returns an object of the same type as the input object cols with modified colors as people with tritanomaly see these colors (simulated).

Return type:

colorobject

Examples

>>> from colorspace import rainbow_hcl, specplot
>>> cols = rainbow_hcl()(100)
>>> specplot(cols)
>>> specplot(tritan(cols))
>>> specplot(tritan(cols, 0.5))