Coverage for plotting/blindness.py: 21%
19 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-16 22:49 +1300
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-16 22:49 +1300
1"""
2Colour Blindness Plotting
3=========================
5Define the colour blindness plotting objects.
7- :func:`colour.plotting.plot_cvd_simulation_Machado2009`
8"""
10from __future__ import annotations
12import typing
14if typing.TYPE_CHECKING:
15 from matplotlib.figure import Figure
16 from matplotlib.axes import Axes
18from colour.algebra import vecmul
19from colour.blindness import matrix_cvd_Machado2009
21if typing.TYPE_CHECKING:
22 from colour.hints import (
23 Any,
24 ArrayLike,
25 Dict,
26 Literal,
27 Tuple,
28 )
30from colour.plotting import CONSTANTS_COLOUR_STYLE, override_style, plot_image
31from colour.utilities import optional
33__author__ = "Colour Developers"
34__copyright__ = "Copyright 2013 Colour Developers"
35__license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"
36__maintainer__ = "Colour Developers"
37__email__ = "colour-developers@colour-science.org"
38__status__ = "Production"
40__all__ = [
41 "plot_cvd_simulation_Machado2009",
42]
45@override_style()
46def plot_cvd_simulation_Machado2009(
47 RGB: ArrayLike,
48 deficiency: (
49 Literal["Deuteranomaly", "Protanomaly", "Tritanomaly"] | str
50 ) = "Protanomaly",
51 severity: float = 0.5,
52 M_a: ArrayLike | None = None,
53 **kwargs: Any,
54) -> Tuple[Figure, Axes]:
55 """
56 Perform colour vision deficiency simulation on the specified *RGB*
57 colourspace array using the *Machado et al. (2009)* model.
59 Parameters
60 ----------
61 RGB
62 *RGB* colourspace array.
63 deficiency
64 Colour blindness / vision deficiency type.
65 severity
66 Severity of the colour vision deficiency in domain [0, 1].
67 M_a
68 Anomalous trichromacy matrix to use instead of the Machado (2010)
69 pre-computed matrix.
71 Other Parameters
72 ----------------
73 kwargs
74 {:func:`colour.plotting.artist`, :func:`colour.plotting.plot_image`,
75 :func:`colour.plotting.render`},
76 See the documentation of the previously listed definitions.
78 Notes
79 -----
80 - Input *RGB* array is expected to be linearly encoded.
82 Returns
83 -------
84 :class:`tuple`
85 Current figure and axes.
87 Examples
88 --------
89 >>> import numpy as np
90 >>> RGB = np.random.rand(32, 32, 3)
91 >>> plot_cvd_simulation_Machado2009(RGB) # doctest: +ELLIPSIS
92 (<Figure size ... with 1 Axes>, <...Axes...>)
94 .. image:: ../_static/Plotting_Plot_CVD_Simulation_Machado2009.png
95 :align: center
96 :alt: plot_cvd_simulation_Machado2009
97 """
99 M_a = optional(M_a, matrix_cvd_Machado2009(deficiency, severity))
101 settings: Dict[str, Any] = {
102 "text_kwargs": {"text": f"Deficiency: {deficiency} - Severity: {severity}"}
103 }
104 settings.update(kwargs)
106 return plot_image(
107 CONSTANTS_COLOUR_STYLE.colour.colourspace.cctf_encoding(vecmul(M_a, RGB)),
108 **settings,
109 )