Skip to content

Commit

Permalink
Rename "to_RGB" and "to_XYZ" parameters and methods to respectively "…
Browse files Browse the repository at this point in the history
…XYZ_to_RGB_matrix" and "RGB_to_XYZ_matrix".
  • Loading branch information
KelSolaar committed Sep 17, 2014
1 parent c1345d1 commit f151633
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
illuminant,
colour.ILLUMINANTS[
'CIE 1931 2 Degree Standard Observer']['D65'],
colour.sRGB_COLOURSPACE.to_RGB,
colour.sRGB_COLOURSPACE.XYZ_to_RGB_matrix,
'Bradford',
colour.sRGB_COLOURSPACE.transfer_function)

Expand Down
4 changes: 2 additions & 2 deletions colour/examples/models/examples_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
XYZ,
colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D50'],
colour.sRGB_COLOURSPACE.whitepoint,
colour.sRGB_COLOURSPACE.to_RGB,
colour.sRGB_COLOURSPACE.XYZ_to_RGB_matrix,
'Bradford',
colour.sRGB_COLOURSPACE.transfer_function))

Expand All @@ -75,7 +75,7 @@
RGB,
colour.sRGB_COLOURSPACE.whitepoint,
colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D50'],
colour.sRGB_COLOURSPACE.to_XYZ,
colour.sRGB_COLOURSPACE.RGB_to_XYZ_matrix,
'Bradford',
colour.sRGB_COLOURSPACE.inverse_transfer_function))

Expand Down
8 changes: 4 additions & 4 deletions colour/examples/models/examples_rgb_colourspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
print('Name:\n"{0}"'.format(colourspace.name))
print('\nPrimaries:\n{0}'.format(colourspace.primaries))
print('\nNormalised primary matrix to "CIE XYZ":\n{0}'.format(
colourspace.to_XYZ))
colourspace.RGB_to_XYZ_matrix))
print('\nNormalised primary matrix to "ACES RGB":\n{0}'.format(
colourspace.to_RGB))
colourspace.XYZ_to_RGB_matrix))
print('\nTransfer function from linear to colourspace:\n{0}'.format(
colourspace.transfer_function))
print('\nInverse transfer function from colourspace to linear:\n{0}'.format(
Expand All @@ -37,8 +37,8 @@
cat = colour.chromatic_adaptation_matrix(
colour.xy_to_XYZ(colour.RGB_COLOURSPACES['ACES RGB'].whitepoint),
colour.xy_to_XYZ(colour.RGB_COLOURSPACES['sRGB'].whitepoint))
print(np.dot(colour.RGB_COLOURSPACES['sRGB'].to_RGB,
np.dot(cat, colour.RGB_COLOURSPACES['ACES RGB'].to_XYZ)))
print(np.dot(colour.RGB_COLOURSPACES['sRGB'].XYZ_to_RGB_matrix,
np.dot(cat, colour.RGB_COLOURSPACES['ACES RGB'].RGB_to_XYZ_matrix)))

print('\n')

Expand Down
2 changes: 1 addition & 1 deletion colour/models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ def XYZ_to_sRGB(XYZ,
return XYZ_to_RGB(XYZ,
illuminant,
sRGB.whitepoint,
sRGB.to_RGB,
sRGB.XYZ_to_RGB_matrix,
chromatic_adaptation_method,
sRGB.transfer_function if transfer_function else None)
25 changes: 13 additions & 12 deletions colour/models/rgb.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
def XYZ_to_RGB(XYZ,
illuminant_XYZ,
illuminant_RGB,
to_RGB,
XYZ_to_RGB_matrix,
chromatic_adaptation_method='CAT02',
transfer_function=None):
"""
Expand All @@ -55,7 +55,7 @@ def XYZ_to_RGB(XYZ,
*CIE XYZ* colourspace *illuminant* *xy* chromaticity coordinates.
illuminant_RGB : array_like
*RGB* colourspace *illuminant* *xy* chromaticity coordinates.
to_RGB : array_like, (3, 3)
XYZ_to_RGB_matrix : array_like, (3, 3)
*Normalised primary matrix*.
chromatic_adaptation_method : unicode, optional
{'CAT02', 'XYZ Scaling', 'Von Kries', 'Bradford', 'Sharp', 'Fairchild,
Expand Down Expand Up @@ -84,15 +84,15 @@ def XYZ_to_RGB(XYZ,
>>> illuminant_XYZ = (0.34567, 0.35850)
>>> illuminant_RGB = (0.31271, 0.32902)
>>> chromatic_adaptation_method = 'Bradford'
>>> to_RGB = np.array([
>>> XYZ_to_RGB_matrix = np.array([
... [3.24100326, -1.53739899, -0.49861587],
... [-0.96922426, 1.87592999, 0.04155422],
... [0.05563942, -0.2040112, 1.05714897]])
>>> XYZ_to_RGB(
... XYZ,
... illuminant_XYZ,
... illuminant_RGB,
... to_RGB,
... XYZ_to_RGB_matrix,
... chromatic_adaptation_method) # doctest: +ELLIPSIS
array([ 0.0110360..., 0.1273446..., 0.1163103...])
"""
Expand All @@ -107,7 +107,8 @@ def XYZ_to_RGB(XYZ,

adapted_XYZ = np.dot(cat, XYZ)

RGB = np.dot(to_RGB.reshape((3, 3)), adapted_XYZ.reshape((3, 1)))
RGB = np.dot(XYZ_to_RGB_matrix.reshape((3, 3)),
adapted_XYZ.reshape((3, 1)))

if transfer_function is not None:
RGB = np.array([transfer_function(x) for x in np.ravel(RGB)])
Expand All @@ -118,7 +119,7 @@ def XYZ_to_RGB(XYZ,
def RGB_to_XYZ(RGB,
illuminant_RGB,
illuminant_XYZ,
to_XYZ,
RGB_to_XYZ_matrix,
chromatic_adaptation_method='CAT02',
inverse_transfer_function=None):
"""
Expand All @@ -134,7 +135,7 @@ def RGB_to_XYZ(RGB,
*RGB* colourspace *illuminant* chromaticity coordinates.
illuminant_XYZ : array_like
*CIE XYZ* colourspace *illuminant* chromaticity coordinates.
to_XYZ : array_like, (3, 3)
RGB_to_XYZ_matrix : array_like, (3, 3)
*Normalised primary matrix*.
chromatic_adaptation_method : unicode, optional
{'CAT02', 'XYZ Scaling', 'Von Kries', 'Bradford', 'Sharp', 'Fairchild,
Expand Down Expand Up @@ -163,15 +164,15 @@ def RGB_to_XYZ(RGB,
>>> illuminant_RGB = (0.31271, 0.32902)
>>> illuminant_XYZ = (0.34567, 0.35850)
>>> chromatic_adaptation_method = 'Bradford'
>>> to_XYZ = np.array([
>>> RGB_to_XYZ_matrix = np.array([
... [0.41238656, 0.35759149, 0.18045049],
... [0.21263682, 0.71518298, 0.0721802],
... [0.01933062, 0.11919716, 0.95037259]])
>>> RGB_to_XYZ(
... RGB,
... illuminant_RGB,
... illuminant_XYZ,
... to_XYZ,
... RGB_to_XYZ_matrix,
... chromatic_adaptation_method) # doctest: +ELLIPSIS
array([ 0.0704953..., 0.1008 , 0.0955831...])
"""
Expand All @@ -180,7 +181,7 @@ def RGB_to_XYZ(RGB,
RGB = np.array([inverse_transfer_function(x)
for x in np.ravel(RGB)])

XYZ = np.dot(to_XYZ.reshape((3, 3)), RGB.reshape((3, 1)))
XYZ = np.dot(RGB_to_XYZ_matrix.reshape((3, 3)), RGB.reshape((3, 1)))

cat = chromatic_adaptation_matrix(
xy_to_XYZ(illuminant_RGB),
Expand Down Expand Up @@ -236,7 +237,7 @@ def RGB_to_RGB(RGB,
xy_to_XYZ(output_colourspace.whitepoint),
chromatic_adaptation_method)

trs_matrix = np.dot(output_colourspace.to_RGB,
np.dot(cat, input_colourspace.to_XYZ))
trs_matrix = np.dot(output_colourspace.XYZ_to_RGB_matrix,
np.dot(cat, input_colourspace.RGB_to_XYZ_matrix))

return np.dot(trs_matrix, RGB)
36 changes: 18 additions & 18 deletions colour/models/rgb_colourspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ class RGB_Colourspace(object):
*RGB* Colourspace primaries.
whitepoint : array_like
*RGB* Colourspace whitepoint.
to_XYZ : array_like
RGB_to_XYZ_matrix : array_like
Transformation matrix from colourspace to *CIE XYZ* colourspace.
to_RGB : array_like
XYZ_to_RGB_matrix : array_like
Transformation matrix from *CIE XYZ* colourspace to colourspace.
transfer_function : object
*RGB* Colourspace opto-electronic transfer function from linear to
Expand All @@ -59,8 +59,8 @@ def __init__(self,
name,
primaries,
whitepoint,
to_XYZ=None,
to_RGB=None,
RGB_to_XYZ_matrix=None,
XYZ_to_RGB_matrix=None,
transfer_function=None,
inverse_transfer_function=None):
self.__name = None
Expand All @@ -69,10 +69,10 @@ def __init__(self,
self.primaries = primaries
self.__whitepoint = None
self.whitepoint = whitepoint
self.__to_XYZ = None
self.to_XYZ = to_XYZ
self.__to_RGB = None
self.to_RGB = to_RGB
self.__RGB_to_XYZ_matrix = None
self.RGB_to_XYZ_matrix = RGB_to_XYZ_matrix
self.__XYZ_to_RGB_matrix = None
self.XYZ_to_RGB_matrix = XYZ_to_RGB_matrix
self.__transfer_function = None
self.transfer_function = transfer_function
self.__inverse_transfer_function = None
Expand Down Expand Up @@ -167,7 +167,7 @@ def whitepoint(self, value):
self.__whitepoint = value

@property
def to_XYZ(self):
def RGB_to_XYZ_matrix(self):
"""
Property for **self.__to_XYZ** private attribute.
Expand All @@ -177,10 +177,10 @@ def to_XYZ(self):
self.__to_XYZ.
"""

return self.__to_XYZ
return self.__RGB_to_XYZ_matrix

@to_XYZ.setter
def to_XYZ(self, value):
@RGB_to_XYZ_matrix.setter
def RGB_to_XYZ_matrix(self, value):
"""
Setter for **self.__to_XYZ** private attribute.
Expand All @@ -192,10 +192,10 @@ def to_XYZ(self, value):

if value is not None:
value = to_ndarray(value)
self.__to_XYZ = value
self.__RGB_to_XYZ_matrix = value

@property
def to_RGB(self):
def XYZ_to_RGB_matrix(self):
"""
Property for **self.__to_RGB** private attribute.
Expand All @@ -205,10 +205,10 @@ def to_RGB(self):
self.__to_RGB.
"""

return self.__to_RGB
return self.__XYZ_to_RGB_matrix

@to_RGB.setter
def to_RGB(self, value):
@XYZ_to_RGB_matrix.setter
def XYZ_to_RGB_matrix(self, value):
"""
Setter for **self.__to_RGB** private attribute.
Expand All @@ -220,7 +220,7 @@ def to_RGB(self, value):

if value is not None:
value = to_ndarray(value)
self.__to_RGB = value
self.__XYZ_to_RGB_matrix = value

@property
def transfer_function(self):
Expand Down
4 changes: 2 additions & 2 deletions colour/models/tests/tests_rgb_colourspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def test_required_attributes(self):
required_attributes = ('name',
'primaries',
'whitepoint',
'to_XYZ',
'to_RGB',
'RGB_to_XYZ_matrix',
'XYZ_to_RGB_matrix',
'transfer_function',
'inverse_transfer_function',)

Expand Down

0 comments on commit f151633

Please sign in to comment.