def test_least_square_mapping_MoorePenrose(self):
        """
        Test :func:`colour.algebra.regression.\
least_square_mapping_MoorePenrose` definition.
        """

        prng = np.random.RandomState(2)
        y = prng.random_sample((24, 3))
        x = y + (prng.random_sample((24, 3)) - 0.5) * 0.5

        np.testing.assert_almost_equal(
            least_square_mapping_MoorePenrose(y, x),
            np.array([
                [1.05263767, 0.13780789, -0.22763399],
                [0.07395843, 1.02939945, -0.10601150],
                [0.05725508, -0.20526336, 1.10151945],
            ]),
            decimal=7,
        )

        y = prng.random_sample((4, 3, 2))
        x = y + (prng.random_sample((4, 3, 2)) - 0.5) * 0.5
        np.testing.assert_almost_equal(
            least_square_mapping_MoorePenrose(y, x),
            np.array([
                [
                    [
                        [1.05968114, -0.0896093, -0.02923021],
                        [3.77254737, 0.06682885, -2.78161763],
                    ],
                    [
                        [-0.77388532, 1.78761209, -0.44050114],
                        [-4.1282882, 0.55185528, 5.049136],
                    ],
                    [
                        [0.36246422, -0.56421525, 1.4208154],
                        [2.07589501, 0.40261387, -1.47059455],
                    ],
                ],
                [
                    [
                        [0.237067, 0.4794514, 0.04004058],
                        [0.67778963, 0.15901967, 0.23854131],
                    ],
                    [
                        [-0.4225357, 0.99316309, -0.14598921],
                        [-3.46789045, 1.09102153, 3.31051434],
                    ],
                    [
                        [-0.91661817, 1.49060435, -0.45074387],
                        [-4.18896905, 0.25487186, 4.75951391],
                    ],
                ],
            ]),
            decimal=7,
        )
    def test_least_square_mapping_MoorePenrose(self):
        """
        Tests :func:`colour.algebra.regression.\
least_square_mapping_MoorePenrose` definition.
        """

        prng = np.random.RandomState(2)
        y = prng.random_sample((24, 3))
        x = y + (prng.random_sample((24, 3)) - 0.5) * 0.5

        np.testing.assert_almost_equal(
            least_square_mapping_MoorePenrose(y, x),
            np.array([
                [1.05263767, 0.13780789, -0.22763399],
                [0.07395843, 1.02939945, -0.10601150],
                [0.05725508, -0.20526336, 1.10151945],
            ]),
            decimal=7)

        y = prng.random_sample((4, 3, 2))
        x = y + (prng.random_sample((4, 3, 2)) - 0.5) * 0.5
        np.testing.assert_almost_equal(
            least_square_mapping_MoorePenrose(y, x),
            np.array([
                [
                    [[1.05968114, -0.0896093, -0.02923021],
                     [3.77254737, 0.06682885, -2.78161763]],
                    [[-0.77388532, 1.78761209, -0.44050114],
                     [-4.1282882, 0.55185528, 5.049136]],
                    [[0.36246422, -0.56421525, 1.4208154],
                     [2.07589501, 0.40261387, -1.47059455]],
                ],
                [
                    [[0.237067, 0.4794514, 0.04004058],
                     [0.67778963, 0.15901967, 0.23854131]],
                    [[-0.4225357, 0.99316309, -0.14598921],
                     [-3.46789045, 1.09102153, 3.31051434]],
                    [[-0.91661817, 1.49060435, -0.45074387],
                     [-4.18896905, 0.25487186, 4.75951391]],
                ],
            ]),
            decimal=7)
Exemple #3
0
def matrix_colour_correction_Finlayson2015(
    M_T: ArrayLike,
    M_R: ArrayLike,
    degree: Literal[1, 2, 3, 4] = 1,
    root_polynomial_expansion: Boolean = True,
) -> NDArray:
    """
    Compute a colour correction matrix from given :math:`M_T` colour array to
    :math:`M_R` colour array using *Finlayson et al. (2015)* method.

    Parameters
    ----------
    M_T
        Test array :math:`M_T` to fit onto array :math:`M_R`.
    M_R
        Reference array the array :math:`M_T` will be colour fitted against.
    degree
        Expanded polynomial degree.
    root_polynomial_expansion
        Whether to use the root-polynomials set for the expansion.

    Returns
    -------
    :class:`numpy.ndarray`
        Colour correction matrix.

    References
    ----------
    :cite:`Finlayson2015`

    Examples
    --------
    >>> prng = np.random.RandomState(2)
    >>> M_T = prng.random_sample((24, 3))
    >>> M_R = M_T + (prng.random_sample((24, 3)) - 0.5) * 0.5
    >>> matrix_colour_correction_Finlayson2015(M_T, M_R)  # doctest: +ELLIPSIS
    array([[ 1.0526376...,  0.1378078..., -0.2276339...],
           [ 0.0739584...,  1.0293994..., -0.1060115...],
           [ 0.0572550..., -0.2052633...,  1.1015194...]])
    """

    return least_square_mapping_MoorePenrose(
        polynomial_expansion_Finlayson2015(M_T, degree,
                                           root_polynomial_expansion),
        M_R,
    )
Exemple #4
0
def colour_correction_matrix_Finlayson2015(M_T,
                                           M_R,
                                           degree=1,
                                           root_polynomial_expansion=True):
    """
    Computes a colour correction matrix from given :math:`M_T` colour array to
    :math:`M_R` colour array using *Finlayson et al. (2015)* method.

    Parameters
    ----------
    M_T : array_like, (n, 3)
        Test array :math:`M_T` to fit onto array :math:`M_R`.
    M_R : array_like, (n, 3)
        Reference array the array :math:`M_T` will be colour fitted against.
    degree : int, optional
        Expanded polynomial degree.
    root_polynomial_expansion : bool
        Whether to use the root-polynomials set for the expansion.

    Returns
    -------
    ndarray, (n, 3)
        Colour correction matrix.

    References
    ----------
    :cite:`Finlayson2015`

    Examples
    --------
    >>> prng = np.random.RandomState(2)
    >>> M_T = prng.random_sample((24, 3))
    >>> M_R = M_T + (prng.random_sample((24, 3)) - 0.5) * 0.5
    >>> colour_correction_matrix(M_T, M_R)  # doctest: +ELLIPSIS
    array([[ 1.0526376...,  0.1378078..., -0.2276339...],
           [ 0.0739584...,  1.0293994..., -0.1060115...],
           [ 0.0572550..., -0.2052633...,  1.1015194...]])
    """

    return least_square_mapping_MoorePenrose(
        polynomial_expansion_Finlayson2015(M_T, degree,
                                           root_polynomial_expansion), M_R)
Exemple #5
0
def colour_correction_matrix_Finlayson2015(M_T,
                                           M_R,
                                           degree=1,
                                           root_polynomial_expansion=True):
    """
    Computes a colour correction matrix from given :math:`M_T` colour array to
    :math:`M_R` colour array using *Finlayson et al. (2015)* method.

    Parameters
    ----------
    M_T : array_like, (3, n)
        Test array :math:`M_T` to fit onto array :math:`M_R`.
    M_R : array_like, (3, n)
        Reference array the array :math:`M_T` will be colour fitted against.
    degree : int, optional
        Expanded polynomial degree.
    root_polynomial_expansion : bool
        Whether to use the root-polynomials set for the expansion.

    Returns
    -------
    ndarray, (3, n)
        Colour correction matrix.

    References
    ----------
    :cite:`Finlayson2015`

    Examples
    --------
    >>> prng = np.random.RandomState(2)
    >>> M_T = prng.random_sample((24, 3))
    >>> M_R = M_T + (prng.random_sample((24, 3)) - 0.5) * 0.5
    >>> colour_correction_matrix(M_T, M_R)  # doctest: +ELLIPSIS
    array([[ 1.0526376...,  0.1378078..., -0.2276339...],
           [ 0.0739584...,  1.0293994..., -0.1060115...],
           [ 0.0572550..., -0.2052633...,  1.1015194...]])
    """

    return least_square_mapping_MoorePenrose(
        polynomial_expansion_Finlayson2015(M_T, degree,
                                           root_polynomial_expansion), M_R)
Exemple #6
0
def matrix_colour_correction_Cheung2004(
    M_T: ArrayLike,
    M_R: ArrayLike,
    terms: Literal[3, 5, 7, 8, 10, 11, 14, 16, 17, 19, 20, 22] = 3,
) -> NDArray:
    """
    Compute a colour correction matrix from given :math:`M_T` colour array to
    :math:`M_R` colour array using *Cheung et al. (2004)* method.

    Parameters
    ----------
    M_T
        Test array :math:`M_T` to fit onto array :math:`M_R`.
    M_R
        Reference array the array :math:`M_T` will be colour fitted against.
    terms
        Number of terms of the expanded polynomial.

    Returns
    -------
    :class:`numpy.ndarray`
        Colour correction matrix.

    References
    ----------
    :cite:`Cheung2004`, :cite:`Westland2004`

    Examples
    --------
    >>> prng = np.random.RandomState(2)
    >>> M_T = prng.random_sample((24, 3))
    >>> M_R = M_T + (prng.random_sample((24, 3)) - 0.5) * 0.5
    >>> matrix_colour_correction_Cheung2004(M_T, M_R)  # doctest: +ELLIPSIS
    array([[ 1.0526376...,  0.1378078..., -0.2276339...],
           [ 0.0739584...,  1.0293994..., -0.1060115...],
           [ 0.0572550..., -0.2052633...,  1.1015194...]])
    """

    return least_square_mapping_MoorePenrose(
        matrix_augmented_Cheung2004(M_T, terms), M_R)
Exemple #7
0
def matrix_colour_correction_Vandermonde(M_T: ArrayLike,
                                         M_R: ArrayLike,
                                         degree: Integer = 1) -> NDArray:
    """
    Compute a colour correction matrix from given :math:`M_T` colour array to
    :math:`M_R` colour array using *Vandermonde* method.

    Parameters
    ----------
    M_T
        Test array :math:`M_T` to fit onto array :math:`M_R`.
    M_R
        Reference array the array :math:`M_T` will be colour fitted against.
    degree
        Expanded polynomial degree.

    Returns
    -------
    :class:`numpy.ndarray`
        Colour correction matrix.

    References
    ----------
    :cite:`Wikipedia2003e`

    Examples
    --------
    >>> prng = np.random.RandomState(2)
    >>> M_T = prng.random_sample((24, 3))
    >>> M_R = M_T + (prng.random_sample((24, 3)) - 0.5) * 0.5
    >>> matrix_colour_correction_Vandermonde(M_T, M_R)  # doctest: +ELLIPSIS
    array([[ 1.0300256...,  0.1141770..., -0.2621816...,  0.0418022...],
           [ 0.0670209...,  1.0221494..., -0.1166108...,  0.0128250...],
           [ 0.0744612..., -0.1872819...,  1.1278078..., -0.0318085...]])
    """

    return least_square_mapping_MoorePenrose(
        polynomial_expansion_Vandermonde(M_T, degree), M_R)
Exemple #8
0
def colour_correction_matrix_Cheung2004(M_T, M_R, terms=3):
    """
    Computes a colour correction from given :math:`M_T` colour array to
    :math:`M_R` colour array using *Cheung et al. (2004)* method.

    Parameters
    ----------
    M_T : array_like, (3, n)
        Test array :math:`M_T` to fit onto array :math:`M_R`.
    M_R : array_like, (3, n)
        Reference array the array :math:`M_T` will be colour fitted against.
    terms : int, optional
        Number of terms of the expanded polynomial, must be one of
        *[3, 5, 7, 8, 10, 11, 14, 16, 17, 19, 20, 22]*.

    Returns
    -------
    ndarray, (3, n)
        Colour correction matrix.

    References
    ----------
    :cite:`Cheung2004`, :cite:`Westland2004`

    Examples
    --------
    >>> prng = np.random.RandomState(2)
    >>> M_T = prng.random_sample((24, 3))
    >>> M_R = M_T + (prng.random_sample((24, 3)) - 0.5) * 0.5
    >>> colour_correction_matrix(M_T, M_R)  # doctest: +ELLIPSIS
    array([[ 1.0526376...,  0.1378078..., -0.2276339...],
           [ 0.0739584...,  1.0293994..., -0.1060115...],
           [ 0.0572550..., -0.2052633...,  1.1015194...]])
    """

    return least_square_mapping_MoorePenrose(
        augmented_matrix_Cheung2004(M_T, terms), M_R)
Exemple #9
0
def colour_correction_matrix_Cheung2004(M_T, M_R, terms=3):
    """
    Computes a colour correction from given :math:`M_T` colour array to
    :math:`M_R` colour array using *Cheung et al. (2004)* method.

    Parameters
    ----------
    M_T : array_like, (3, n)
        Test array :math:`M_T` to fit onto array :math:`M_R`.
    M_R : array_like, (3, n)
        Reference array the array :math:`M_T` will be colour fitted against.
    terms : int, optional
        Number of terms of the expanded polynomial, must be one of
        *[3, 5, 7, 8, 10, 11, 14, 16, 17, 19, 20, 22]*.

    Returns
    -------
    ndarray, (3, n)
        Colour correction matrix.

    References
    ----------
    :cite:`Cheung2004`, :cite:`Westland2004`

    Examples
    --------
    >>> prng = np.random.RandomState(2)
    >>> M_T = prng.random_sample((24, 3))
    >>> M_R = M_T + (prng.random_sample((24, 3)) - 0.5) * 0.5
    >>> colour_correction_matrix(M_T, M_R)  # doctest: +ELLIPSIS
    array([[ 1.0526376...,  0.1378078..., -0.2276339...],
           [ 0.0739584...,  1.0293994..., -0.1060115...],
           [ 0.0572550..., -0.2052633...,  1.1015194...]])
    """

    return least_square_mapping_MoorePenrose(
        augmented_matrix_Cheung2004(M_T, terms), M_R)
Exemple #10
0
def colour_correction_matrix_Vandermonde(M_T, M_R, degree=1):
    """
    Computes a colour correction matrix from given :math:`M_T` colour array to
    :math:`M_R` colour array using *Vandermonde* method.

    Parameters
    ----------
    M_T : array_like, (3, n)
        Test array :math:`M_T` to fit onto array :math:`M_R`.
    M_R : array_like, (3, n)
        Reference array the array :math:`M_T` will be colour fitted against.
    degree : int, optional
        Expanded polynomial degree.

    Returns
    -------
    ndarray, (3, n)
        Colour correction matrix.

    References
    ----------
    :cite:`Wikipedia2003e`

    Examples
    --------
    >>> prng = np.random.RandomState(2)
    >>> M_T = prng.random_sample((24, 3))
    >>> M_R = M_T + (prng.random_sample((24, 3)) - 0.5) * 0.5
    >>> colour_correction_matrix(M_T, M_R)  # doctest: +ELLIPSIS
    array([[ 1.0526376...,  0.1378078..., -0.2276339...],
           [ 0.0739584...,  1.0293994..., -0.1060115...],
           [ 0.0572550..., -0.2052633...,  1.1015194...]])
    """

    return least_square_mapping_MoorePenrose(
        polynomial_expansion_Vandermonde(M_T, degree), M_R)