Skip to content

Commit

Permalink
Refactor "colour.first_order_colour_fit" definition.
Browse files Browse the repository at this point in the history
  • Loading branch information
KelSolaar committed May 2, 2015
1 parent d5e8bf8 commit a63d7f8
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 254 deletions.
2 changes: 0 additions & 2 deletions colour/algebra/__init__.py
Expand Up @@ -11,7 +11,6 @@
SpragueInterpolator)
from .matrix import is_identity
from .random import random_triplet_generator
from .regression import linear_regression

__all__ = []
__all__ += coordinates.__all__
Expand All @@ -21,4 +20,3 @@
'SpragueInterpolator']
__all__ += ['is_identity']
__all__ += ['random_triplet_generator']
__all__ += ['linear_regression']
113 changes: 0 additions & 113 deletions colour/algebra/regression.py

This file was deleted.

117 changes: 0 additions & 117 deletions colour/algebra/tests/tests_regression.py

This file was deleted.

27 changes: 8 additions & 19 deletions colour/characterisation/fitting.py
Expand Up @@ -17,8 +17,6 @@

import numpy as np

from colour.algebra import linear_regression

__author__ = 'Colour Developers'
__copyright__ = 'Copyright (C) 2013 - 2015 - Colour Developers'
__license__ = 'New BSD License - http://opensource.org/licenses/BSD-3-Clause'
Expand All @@ -31,8 +29,8 @@

def first_order_colour_fit(m1, m2):
"""
Performs a first order colour fit from given :math:`m2` colour matrix to
:math:`m1` colour matrix. The resulting colour matrix is calculated using
Performs a first order colour fit from given :math:`m1` colour matrix to
:math:`m2` colour matrix. The resulting colour matrix is calculated using
multiple linear regression.
The purpose of that object is for example matching of two *ColorChecker*
Expand All @@ -41,9 +39,9 @@ def first_order_colour_fit(m1, m2):
Parameters
----------
m1 : array_like, (3, n)
Reference matrix the matrix :math:`m2` will be colour fitted against.
Test matrix :math:`m1` to fit onto matrix :math:`m2`.
m2 : array_like, (3, n)
Matrix to fit.
Reference matrix the matrix :math:`m1` will be colour fitted against.
Returns
-------
Expand Down Expand Up @@ -103,18 +101,9 @@ def first_order_colour_fit(m1, m2):
... [0.10283975, 0.10424680, 0.10384975],
... [0.04742204, 0.04772203, 0.04914226]])
>>> first_order_colour_fit(m1, m2) # doctest: +ELLIPSIS
array([[ 1.4043128..., 0.0112806..., -0.2029710...],
[-0.0998911..., 1.5012214..., -0.1856479...],
[ 0.2248369..., -0.0767236..., 1.0496013...]])
array([[ 0.6982266..., 0.0307162..., 0.1621042...],
[ 0.0689349..., 0.6757961..., 0.1643038...],
[-0.0631495..., 0.0921247..., 0.9713415...]])
"""

m1 = np.asarray(m1)
m2 = np.asarray(m2)

x_coefficients = linear_regression(m1[..., 0], m2)
y_coefficients = linear_regression(m1[..., 1], m2)
z_coefficients = linear_regression(m1[..., 2], m2)

return np.array([x_coefficients[:3],
y_coefficients[:3],
z_coefficients[:3]]).reshape((3, 3))
return np.transpose(np.linalg.lstsq(m1, m2)[0])
6 changes: 3 additions & 3 deletions colour/characterisation/tests/tests_fitting.py
Expand Up @@ -95,9 +95,9 @@ def test_first_order_colour_fit(self):

np.testing.assert_almost_equal(
first_order_colour_fit(M1, M2),
np.array([[1.40431285, 0.01128059, -0.20297103],
[-0.09989111, 1.50122142, -0.18564796],
[0.22483693, -0.07672362, 1.04960133]]),
np.array([[0.69822661, 0.03071629, 0.16210422],
[0.06893499, 0.67579611, 0.16430385],
[-0.06314955, 0.0921247, 0.97134152]]),
decimal=7)

@ignore_numpy_errors
Expand Down

0 comments on commit a63d7f8

Please sign in to comment.