Skip to content

Commit

Permalink
Add more tests for "IPT" colourspace model.
Browse files Browse the repository at this point in the history
  • Loading branch information
KelSolaar committed Sep 9, 2014
1 parent 3e2348f commit bf58f87
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
14 changes: 8 additions & 6 deletions colour/models/ipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ def XYZ_to_IPT(XYZ):
Examples
--------
>>> XYZ_to_IPT(np.array([0.5, 0.5, 0.5])) # doctest: +ELLIPSIS
array([ 0.738192 , 0.0536732..., 0.0359856...])
>>> XYZ = np.array([0.96907232, 1, 1.12179215])
>>> XYZ_to_IPT(XYZ) # doctest: +ELLIPSIS
array([ 1.0030082..., 0.0190691..., -0.0136929...])
"""

LMS = np.dot(IPT_XYZ_TO_LMS_MATRIX, XYZ)
Expand All @@ -137,8 +138,9 @@ def IPT_to_XYZ(IPT):
Examples
--------
>>> IPT_to_XYZ(np.array([0.5, 0.5, 0.5])) # doctest: +ELLIPSIS
array([ 0.4497109..., 0.2694691..., 0.0196303...])
>>> IPT = np.array([1.00300825, 0.01906918, -0.01369292])
>>> IPT_to_XYZ(IPT) # doctest: +ELLIPSIS
array([ 0.9689994..., 0.9999576..., 1.1218432...])
"""

LMS = np.dot(IPT_IPT_TO_LMS_MATRIX, IPT)
Expand All @@ -164,8 +166,8 @@ def IPT_hue_angle(IPT):
Examples
--------
>>> IPT_hue_angle(([0.5, 0.5, 0.5])) # doctest: +ELLIPSIS
0.7853981...
>>> IPT_hue_angle(([0.96907232, 1, 1.12179215])) # doctest: +ELLIPSIS
0.8427358...
"""

return np.arctan2(IPT[2], IPT[1])
36 changes: 30 additions & 6 deletions colour/models/tests/tests_ipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,16 @@ def test_XYZ_to_IPT(self):
"""

np.testing.assert_almost_equal(
XYZ_to_IPT(np.array([0.5, 0.5, 0.5])),
np.array([0.738192, 0.0536732, 0.0359856]),
XYZ_to_IPT(np.array([0.96907232, 1, 1.12179215])),
np.array([1.00300825, 0.01906918, -0.01369292]),
decimal=7)
np.testing.assert_almost_equal(
XYZ_to_IPT(np.array([1.92001986, 1, -0.1241347])),
np.array([0.73974548, 0.95333412, 1.71951212]),
decimal=7)
np.testing.assert_almost_equal(
XYZ_to_IPT(np.array([1.0131677, 1, 2.11217686])),
np.array([1.06406598, -0.08075812, -0.39625384]),
decimal=7)


Expand All @@ -58,8 +66,16 @@ def test_IPT_to_XYZ(self):
"""

np.testing.assert_almost_equal(
IPT_to_XYZ(np.array([0.5, 0.5, 0.5])),
np.array([0.4497109, 0.2694691, 0.0196303]),
IPT_to_XYZ(np.array([1.00300825, 0.01906918, -0.01369292])),
np.array([0.9689994, 0.99995764, 1.1218432]),
decimal=7)
np.testing.assert_almost_equal(
IPT_to_XYZ(np.array([0.73974548, 0.95333412, 1.71951212])),
np.array([1.91998253, 0.99988784, -0.12416715]),
decimal=7)
np.testing.assert_almost_equal(
IPT_to_XYZ(np.array([1.06406598, -0.08075812, -0.39625384])),
np.array([1.0130757, 0.9999554, 2.11229678]),
decimal=7)


Expand All @@ -75,6 +91,14 @@ def test_IPT_hue_angle(self):
"""

np.testing.assert_almost_equal(
IPT_hue_angle(np.array([0.5, 0.5, 0.5])),
0.78539812,
IPT_hue_angle(np.array([0.96907232, 1, 1.12179215])),
0.84273584954373859,
decimal=7)
np.testing.assert_almost_equal(
IPT_hue_angle(np.array([1.92001986, 1, -0.1241347])),
-0.12350291631562464,
decimal=7)
np.testing.assert_almost_equal(
IPT_hue_angle(np.array([1.0131677, 1, 2.11217686])),
1.1286173302440385,
decimal=7)

0 comments on commit bf58f87

Please sign in to comment.