Skip to content

Commit

Permalink
Add "colour.camera_RGB_to_ACES2065_1" definition.
Browse files Browse the repository at this point in the history
  • Loading branch information
KelSolaar committed Mar 17, 2021
1 parent 3cac0f7 commit e603d3a
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 13 deletions.
28 changes: 19 additions & 9 deletions colour/__init__.py
Expand Up @@ -156,9 +156,9 @@
CCS_COLOURCHECKERS, MATRIX_COLOUR_CORRECTION_METHODS,
COLOUR_CORRECTION_METHODS, MSDS_CAMERA_SENSITIVITIES,
MSDS_DISPLAY_PRIMARIES, POLYNOMIAL_EXPANSION_METHODS, SDS_COLOURCHECKERS,
SDS_FILTERS, SDS_LENSES, colour_correction, matrix_colour_correction,
matrix_idt, polynomial_expansion, sd_to_ACES2065_1,
sd_to_aces_relative_exposure_values)
SDS_FILTERS, SDS_LENSES, camera_RGB_to_ACES2065_1, colour_correction,
matrix_colour_correction, matrix_idt, polynomial_expansion,
sd_to_ACES2065_1, sd_to_aces_relative_exposure_values)
from .volume import (
OPTIMAL_COLOUR_STIMULI_ILLUMINANTS, RGB_colourspace_limits,
RGB_colourspace_pointer_gamut_coverage_MonteCarlo,
Expand Down Expand Up @@ -319,12 +319,22 @@ def __getattr__(self, attribute):
'UV_TO_CCT_METHODS', 'XY_TO_CCT_METHODS', 'uv_to_CCT', 'xy_to_CCT'
]
__all__ += [
'CCS_COLOURCHECKERS', 'MATRIX_COLOUR_CORRECTION_METHODS',
'COLOUR_CORRECTION_METHODS', 'MSDS_CAMERA_SENSITIVITIES',
'MSDS_DISPLAY_PRIMARIES', 'POLYNOMIAL_EXPANSION_METHODS',
'SDS_COLOURCHECKERS', 'SDS_FILTERS', 'SDS_LENSES', 'colour_correction',
'matrix_colour_correction', 'matrix_idt', 'polynomial_expansion',
'sd_to_ACES2065_1', 'sd_to_aces_relative_exposure_values'
'CCS_COLOURCHECKERS',
'MATRIX_COLOUR_CORRECTION_METHODS',
'COLOUR_CORRECTION_METHODS',
'MSDS_CAMERA_SENSITIVITIES',
'MSDS_DISPLAY_PRIMARIES',
'POLYNOMIAL_EXPANSION_METHODS',
'SDS_COLOURCHECKERS',
'SDS_FILTERS',
'SDS_LENSES',
'camera_RGB_to_ACES2065_1',
'colour_correction',
'matrix_colour_correction',
'matrix_idt',
'polynomial_expansion',
'sd_to_ACES2065_1',
'sd_to_aces_relative_exposure_values',
]
__all__ += [
'OPTIMAL_COLOUR_STIMULI_ILLUMINANTS', 'RGB_colourspace_limits',
Expand Down
5 changes: 3 additions & 2 deletions colour/characterisation/__init__.py
Expand Up @@ -9,7 +9,8 @@
read_training_data_rawtoaces_v1, generate_illuminants_rawtoaces_v1,
white_balance_multipliers, best_illuminant, normalise_illuminant,
training_data_sds_to_RGB, training_data_sds_to_XYZ,
optimisation_factory_rawtoaces_v1, optimisation_factory_JzAzBz, matrix_idt)
optimisation_factory_rawtoaces_v1, optimisation_factory_JzAzBz, matrix_idt,
camera_RGB_to_ACES2065_1)
from .correction import (
matrix_augmented_Cheung2004, polynomial_expansion_Finlayson2015,
polynomial_expansion_Vandermonde, POLYNOMIAL_EXPANSION_METHODS,
Expand All @@ -29,7 +30,7 @@
'white_balance_multipliers', 'best_illuminant', 'normalise_illuminant',
'training_data_sds_to_RGB', 'training_data_sds_to_XYZ',
'optimisation_factory_rawtoaces_v1', 'optimisation_factory_JzAzBz',
'matrix_idt'
'matrix_idt', 'camera_RGB_to_ACES2065_1'
]
__all__ += [
'matrix_augmented_Cheung2004', 'polynomial_expansion_Finlayson2015',
Expand Down
59 changes: 59 additions & 0 deletions colour/characterisation/aces_it.py
Expand Up @@ -17,6 +17,7 @@
- :func:`colour.characterisation.optimisation_factory_rawtoaces_v1`
- :func:`colour.characterisation.optimisation_factory_JzAzBz`
- :func:`colour.matrix_idt`
- :func:`colour.camera_RGB_to_ACES2065_1`
References
----------
Expand Down Expand Up @@ -853,3 +854,61 @@ def matrix_idt(sensitivities,
return M, RGB_w, XYZ, RGB
else:
return M, RGB_w


def camera_RGB_to_ACES2065_1(RGB, B, b, k=np.ones(3), clip=False):
"""
Converts given camera *RGB* colourspace array to *ACES2065-1* colourspace
using the *Input Device Transform* (IDT) matrix :math:`B`, the white
balance multipliers :math:`b` and the exposure factor :math:`k` according
to *P-2013-001* procedure.
Parameters
----------
RGB : array_like
Camera *RGB* colourspace array.
B : array_like
*Input Device Transform* (IDT) matrix :math:`B`.
b : array_like
White balance multipliers :math:`b`.
k : array_like, optional
Exposure factor :math:`k` that results in a nominally "18% gray" object
in the scene producing ACES values [0.18, 0.18, 0.18].
clip : bool, optional
Whether to clip the white balanced camera *RGB* colourspace array
between :math:`-\\infty` and 1. The intent is to keep sensor saturated
values achromatic after white balancing.
Returns
-------
ndarray
*ACES2065-1* colourspace relative exposure values array.
References
----------
:cite:`TheAcademyofMotionPictureArtsandSciences2015c`
Examples
--------
>>> path = os.path.join(
... RESOURCES_DIRECTORY_RAWTOACES,
... 'CANON_EOS_5DMark_II_RGB_Sensitivities.csv')
>>> sensitivities = sds_and_msds_to_msds(
... read_sds_from_csv_file(path).values())
>>> illuminant = SDS_ILLUMINANTS['D55']
>>> B, b = matrix_idt(sensitivities, illuminant)
>>> camera_RGB_to_ACES2065_1(np.array([0.1, 0.2, 0.3]), B, b)
... # doctest: +ELLIPSIS
array([ 0.2646811..., 0.1528898..., 0.4944335...])
"""

RGB = as_float_array(RGB)
B = as_float_array(B)
b = as_float_array(b)
k = as_float_array(k)

RGB_r = b * RGB / np.min(b)

RGB_r = np.clip(RGB_r, -np.inf, 1) if clip else RGB_r

return k * vector_dot(B, RGB_r)
31 changes: 29 additions & 2 deletions colour/characterisation/tests/test_aces_it.py
Expand Up @@ -13,7 +13,7 @@
generate_illuminants_rawtoaces_v1, white_balance_multipliers,
best_illuminant, normalise_illuminant, training_data_sds_to_RGB,
training_data_sds_to_XYZ, optimisation_factory_rawtoaces_v1,
optimisation_factory_JzAzBz, matrix_idt)
optimisation_factory_JzAzBz, matrix_idt, camera_RGB_to_ACES2065_1)
from colour.characterisation.aces_it import RESOURCES_DIRECTORY_RAWTOACES
from colour.colorimetry import (MSDS_CMFS, SDS_ILLUMINANTS, SpectralShape,
sds_and_msds_to_msds, sd_constant, sd_ones)
Expand All @@ -34,7 +34,8 @@
'TestWhiteBalanceMultipliers', 'TestBestIlluminant',
'TestNormaliseIlluminant', 'TestTrainingDataSdsToRGB',
'TestTrainingDataSdsToXYZ', 'TestOptimizationFactoryRawtoacesV1',
'TestOptimizationFactoryJzAzBz', 'TestMatrixIdt'
'TestOptimizationFactoryJzAzBz', 'TestMatrixIdt',
'TestCamera_RGB_to_ACES2065_1'
]

MSDS_CANON_EOS_5DMARK_II = sds_and_msds_to_msds(
Expand Down Expand Up @@ -941,5 +942,31 @@ def test_matrix_idt(self):
]))


class TestCamera_RGB_to_ACES2065_1(unittest.TestCase):
"""
Defines :func:`colour.characterisation.aces_it.\
camera_RGB_to_ACES2065_1` definition unit tests methods.
"""

def test_camera_RGB_to_ACES2065_1(self):
"""
Tests :func:`colour.characterisation.aces_it.\
camera_RGB_to_ACES2065_1` definition.
"""

B, b = matrix_idt(MSDS_CANON_EOS_5DMARK_II, SDS_ILLUMINANTS['D55'])
np.testing.assert_almost_equal(
camera_RGB_to_ACES2065_1(np.array([0.1, 0.2, 0.3]), B, b),
np.array([0.26468115, 0.15288980, 0.49443355]))

np.testing.assert_almost_equal(
camera_RGB_to_ACES2065_1(np.array([1.5, 1.5, 1.5]), B, b),
np.array([3.30542136, 1.44643555, 2.42192985]))

np.testing.assert_almost_equal(
camera_RGB_to_ACES2065_1(np.array([1.0, 1.0, 1.0]), B, b, True),
np.array([2.20361424, 0.96429036, 1.61461990]))


if __name__ == '__main__':
unittest.main()
1 change: 1 addition & 0 deletions docs/colour.characterisation.rst
Expand Up @@ -38,6 +38,7 @@ ACES Input Transform Computation
:toctree: generated/

matrix_idt
camera_RGB_to_ACES2065_1

**Ancillary Objects**

Expand Down

0 comments on commit e603d3a

Please sign in to comment.