Coverage for plotting/blindness.py: 21%

1"""

2 Colour Blindness Plotting

3=========================

4

5 Define the colour blindness plotting objects.

6

7- :func:`colour.plotting.plot_cvd_simulation_Machado2009`

8"""

9

10 from __future__ import annotations

11

12 import typing

13

14 if typing.TYPE_CHECKING:

15 from matplotlib.figure import Figure

16 from matplotlib.axes import Axes

17

18 from colour.algebra import vecmul

19 from colour.blindness import matrix_cvd_Machado2009

20

21 if typing.TYPE_CHECKING:

22 from colour.hints import (

23 Any,

24 ArrayLike,

25 Dict,

26 Literal,

27 Tuple,

28 )

29

30 from colour.plotting import CONSTANTS_COLOUR_STYLE, override_style, plot_image

31 from colour.utilities import optional

32

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"

39

40 __all__ = [

41 "plot_cvd_simulation_Machado2009",

42]

43

44

45@override_style()

46 def 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.

58

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.

70

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.

77

78 Notes

79 -----

80 - Input *RGB* array is expected to be linearly encoded.

81

82 Returns

83 -------

84 :class:`tuple`

85 Current figure and axes.

86

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...>)

93

94 .. image:: ../_static/Plotting_Plot_CVD_Simulation_Machado2009.png

95 :align: center

96 :alt: plot_cvd_simulation_Machado2009

97 """

98

99 M_a = optional(M_a, matrix_cvd_Machado2009(deficiency, severity))

100

101 settings: Dict[str, Any] = {

102 "text_kwargs": {"text": f"Deficiency: {deficiency} - Severity: {severity}"}

103 }

104 settings.update(kwargs)

105

106 return plot_image(

107 CONSTANTS_COLOUR_STYLE.colour.colourspace.cctf_encoding(vecmul(M_a, RGB)),

108 **settings,

109 )