Coverage for colour/utilities/tests/test_metrics.py: 100%
27 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-15 19:01 +1300
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-15 19:01 +1300
1"""Define the unit tests for the :mod:`colour.utilities.metrics` module."""
3from __future__ import annotations
5import numpy as np
7from colour.constants import TOLERANCE_ABSOLUTE_TESTS
8from colour.utilities import metric_mse, metric_psnr
10__author__ = "Colour Developers"
11__copyright__ = "Copyright 2013 Colour Developers"
12__license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"
13__maintainer__ = "Colour Developers"
14__email__ = "colour-developers@colour-science.org"
15__status__ = "Production"
17__all__ = [
18 "TestMetricMse",
19 "TestMetricPsnr",
20]
23class TestMetricMse:
24 """
25 Define :func:`colour.utilities.metrics.metric_mse` definition unit tests
26 methods.
27 """
29 def test_metric_mse(self) -> None:
30 """Test :func:`colour.utilities.metrics.metric_mse` definition."""
32 a = np.array([0.48222001, 0.31654775, 0.22070353])
33 assert metric_mse(a, a) == 0
35 b = a * 0.9
36 np.testing.assert_allclose(
37 metric_mse(a, b),
38 0.0012714955474297446,
39 atol=TOLERANCE_ABSOLUTE_TESTS,
40 )
42 b = a * 1.1
43 np.testing.assert_allclose(
44 metric_mse(a, b),
45 0.0012714955474297446,
46 atol=TOLERANCE_ABSOLUTE_TESTS,
47 )
50class TestMetricPsnr:
51 """
52 Define :func:`colour.utilities.metrics.metric_psnr` definition unit tests
53 methods.
54 """
56 def test_metric_psnr(self) -> None:
57 """Test :func:`colour.utilities.metrics.metric_psnr` definition."""
59 a = np.array([0.48222001, 0.31654775, 0.22070353])
60 assert metric_psnr(a, a) == 0
62 b = a * 0.9
63 np.testing.assert_allclose(
64 metric_psnr(a, b),
65 28.956851563141299,
66 atol=TOLERANCE_ABSOLUTE_TESTS,
67 )
69 b = a * 1.1
70 np.testing.assert_allclose(
71 metric_psnr(a, b),
72 28.956851563141296,
73 atol=TOLERANCE_ABSOLUTE_TESTS,
74 )