Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Implement support for *OpenEXR Layout for Spectral Images*. #1261

Merged
merged 7 commits into from
May 20, 2024
301 changes: 156 additions & 145 deletions BIBLIOGRAPHY.bib

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,18 @@ Images

(276, 281, 3)

Spectral Images - Fichet et al. (2021)
**************************************

.. code-block:: python

components = colour.read_spectral_image_Fichet2021("Polarised.exr")
list(components.keys())

.. code-block:: text

['S0', 'S1', 'S2', 'S3']

Look Up Table (LUT) Data
************************

Expand Down
6 changes: 6 additions & 0 deletions colour/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@
LUT3x1D,
LUTOperatorMatrix,
LUTSequence,
Specification_Fichet2021,
SpectralDistribution_IESTM2714,
SpectralDistribution_Sekonic,
SpectralDistribution_UPRTek,
Expand All @@ -262,9 +263,11 @@
read_sds_from_csv_file,
read_sds_from_xrite_file,
read_spectral_data_from_csv_file,
read_spectral_image_Fichet2021,
write_image,
write_LUT,
write_sds_to_csv_file,
write_spectral_image_Fichet2021,
)
from .models import (
CCTF_DECODINGS,
Expand Down Expand Up @@ -636,6 +639,7 @@
"LUT3D",
"LUTOperatorMatrix",
"LUTSequence",
"Specification_Fichet2021",
"READ_IMAGE_METHODS",
"SpectralDistribution_IESTM2714",
"WRITE_IMAGE_METHODS",
Expand All @@ -644,11 +648,13 @@
"read_sds_from_csv_file",
"read_sds_from_xrite_file",
"read_spectral_data_from_csv_file",
"read_spectral_image_Fichet2021",
"SpectralDistribution_UPRTek",
"SpectralDistribution_Sekonic",
"write_image",
"write_LUT",
"write_sds_to_csv_file",
"write_spectral_image_Fichet2021",
]
__all__ += [
"CAM02LCD_to_JMh_CIECAM02",
Expand Down
32 changes: 32 additions & 0 deletions colour/examples/io/examples_fichet2021.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
Showcases *Fichet, Pacanowski and Wilkie (2021)*
*OpenEXR Layout for Spectral Images* related examples.
"""

import os
import tempfile

import colour
from colour.utilities import message_box

ROOT_RESOURCES = os.path.join(
os.path.dirname(__file__), "..", "..", "io", "tests", "resources"
)

message_box('"Fichet, Pacanowski and Wilkie (2021)" Spectral Image Reading and Writing')

message_box("Reading a spectral image.")
path = os.path.join(ROOT_RESOURCES, "Ohta1997.exr")
components, specification = colour.read_spectral_image_Fichet2021(
path, additional_data=True
)
print(components)
print(specification)

print("\n")

message_box("Writing a spectral image.")
_descriptor, path = tempfile.mkstemp(suffix=".exr")
colour.write_spectral_image_Fichet2021(components, path) # pyright: ignore
components = colour.read_spectral_image_Fichet2021(path)
print(components)
66 changes: 64 additions & 2 deletions colour/io/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
import sys

from colour.utilities.deprecation import ModuleAPI, build_API_changes
from colour.utilities.documentation import is_documentation_building

from colour.hints import Any

from .luts import * # noqa: F403
from . import luts
from .image import ImageAttribute_Specification, convert_bit_depth
from .image import (
Image_Specification_Attribute,
MAPPING_BIT_DEPTH,
image_specification_OpenImageIO,
convert_bit_depth,
)
from .image import read_image_OpenImageIO, write_image_OpenImageIO
from .image import read_image_Imageio, write_image_Imageio
from .image import READ_IMAGE_METHODS, WRITE_IMAGE_METHODS
from .image import read_image, write_image
from .image import as_3_channels_image
from .fichet2021 import (
ComponentsFichet2021,
sd_to_spectrum_attribute_Fichet2021,
spectrum_attribute_to_sd_Fichet2021,
Specification_Fichet2021,
read_spectral_image_Fichet2021,
write_spectral_image_Fichet2021,
)
from .ctl import (
ctl_render,
process_image_ctl,
Expand All @@ -28,7 +48,9 @@
__all__ = []
__all__ += luts.__all__
__all__ += [
"ImageAttribute_Specification",
"Image_Specification_Attribute",
"MAPPING_BIT_DEPTH",
"image_specification_OpenImageIO",
"convert_bit_depth",
]
__all__ += [
Expand Down Expand Up @@ -56,6 +78,14 @@
__all__ += [
"as_3_channels_image",
]
__all__ += [
"ComponentsFichet2021",
"sd_to_spectrum_attribute_Fichet2021",
"spectrum_attribute_to_sd_Fichet2021",
"Specification_Fichet2021",
"read_spectral_image_Fichet2021",
"write_spectral_image_Fichet2021",
]
__all__ += [
"process_image_OpenColorIO",
]
Expand All @@ -75,3 +105,35 @@
__all__ += [
"read_sds_from_xrite_file",
]


# ----------------------------------------------------------------------------#
# --- API Changes and Deprecation Management ---#
# ----------------------------------------------------------------------------#
class io(ModuleAPI):
"""Define a class acting like the *io* module."""

def __getattr__(self, attribute) -> Any:
"""Return the value from the attribute with given name."""

return super().__getattr__(attribute)


# v0.4.5
API_CHANGES = {
"ObjectRenamed": [
[
"colour.io.ImageAttribute_Specification",
"colour.io.Image_Specification_Attribute",
],
]
}

"""Defines the *colour.io* sub-package API changes."""

if not is_documentation_building():
sys.modules["colour.io"] = io( # pyright: ignore
sys.modules["colour.io"], build_API_changes(API_CHANGES)
)

del ModuleAPI, is_documentation_building, build_API_changes, sys