Skip to content

Commit

Permalink
Merge branch 'feature/v0.2.1' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
KelSolaar committed Oct 14, 2022
2 parents b69bd7e + ad00a22 commit d1d84d2
Show file tree
Hide file tree
Showing 32 changed files with 1,155 additions and 785 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ jobs:
matrix:
os: [macOS-latest, ubuntu-20.04, windows-latest]
python-version: [3.8, 3.9, '3.10']
exclude:
- os: windows-latest
python-version: 3.8
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Colour - HDRI
.. end-badges
A `Python <https://www.python.org/>`__ package implementing various
HDRI / Radiance image processing algorithms.
HDRI processing algorithms.

It is open source and freely available under the
`New BSD License <https://opensource.org/licenses/BSD-3-Clause>`__ terms.
Expand All @@ -39,7 +39,7 @@ Features

The following features are available:

- HDRI / Radiance Image Generation
- HDRI Generation
- Debevec (1997) Camera Response Function Computation
- Grossberg (2003) Histogram Based Image Sampling
- Variance Minimization Light Probe Sampling
Expand Down
12 changes: 8 additions & 4 deletions colour_hdri/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
Colour - HDRI
=============
HDRI - Radiance image processing algorithms for *Python*.
HDRI processing algorithms for *Python*.
Subpackages
-----------
- calibration: Camera calibration computations.
- distortion: Lens vignette characterisation & correction.
- exposure: Exposure computations.
- examples: Examples for the sub-packages.
- generation: HDRI / radiance image generation.
- generation: HDRI Generation.
- models: Colour models conversion.
- plotting: Diagrams, figures, etc...
- process: Image conversion helpers.
Expand Down Expand Up @@ -84,7 +84,7 @@
normal_distribution_function,
hat_function,
weighting_function_Debevec1997,
image_stack_to_radiance_image,
image_stack_to_HDRI,
)
from .calibration import (
absolute_luminance_calibration_Lagarde2016,
Expand Down Expand Up @@ -183,7 +183,7 @@
"normal_distribution_function",
"hat_function",
"weighting_function_Debevec1997",
"image_stack_to_radiance_image",
"image_stack_to_HDRI",
]
__all__ += [
"absolute_luminance_calibration_Lagarde2016",
Expand Down Expand Up @@ -292,6 +292,10 @@ def __getattr__(self, attribute) -> Any:
"colour_hdri.camera_space_to_XYZ_matrix",
"colour_hdri.matrix_camera_space_to_XYZ",
],
[
"colour_hdri.image_stack_to_radiance_image",
"colour_hdri.image_stack_to_HDRI",
],
]
}
"""Defines the *colour_hdri* package API changes."""
Expand Down
6 changes: 3 additions & 3 deletions colour_hdri/calibration/absolute_luminance.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ def upper_hemisphere_illuminance_Lagarde2016(

theta = np.linspace(0, 1, height) * np.pi

theta_cos = np.cos(theta)[..., np.newaxis]
theta_sin = np.sin(theta)[..., np.newaxis]
theta_cos = np.cos(theta)[..., None]
theta_sin = np.sin(theta)[..., None]

E_v = np.sum(np.where(theta_cos > 0, L * theta_cos * theta_sin, 0))

Expand Down Expand Up @@ -135,7 +135,7 @@ def upper_hemisphere_illuminance_weights_Lagarde2016(
w = np.zeros((height, width))

theta = np.linspace(0, 1, height) * np.pi
theta = np.tile(theta[..., np.newaxis], (1, width))
theta = np.tile(theta[..., None], (1, width))

theta_cos = np.cos(theta)
theta_sin = np.sin(theta)
Expand Down
4 changes: 2 additions & 2 deletions colour_hdri/distortion/vignette.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ def apply_radial_gradient(
samples_y += offset_y - 0.5

distance = np.sqrt(
(samples_x**2)[..., np.newaxis] + (samples_y**2)[np.newaxis, ...]
(samples_x**2)[..., None] + (samples_y**2)[None, ...]
)

image *= 1 - distance[..., np.newaxis] * intensity
image *= 1 - distance[..., None] * intensity
image **= bias

image += np.random.random(image.shape) * noise
Expand Down

Large diffs are not rendered by default.

83 changes: 35 additions & 48 deletions colour_hdri/examples/examples_adobe_dng_sdk_colour_processing.ipynb

Large diffs are not rendered by default.

Large diffs are not rendered by default.

80 changes: 41 additions & 39 deletions colour_hdri/examples/examples_global_tonemapping_operators.ipynb

Large diffs are not rendered by default.

103 changes: 40 additions & 63 deletions colour_hdri/examples/examples_merge_from_ldr_files.ipynb

Large diffs are not rendered by default.

124 changes: 56 additions & 68 deletions colour_hdri/examples/examples_merge_from_raw_files.ipynb

Large diffs are not rendered by default.

128 changes: 57 additions & 71 deletions colour_hdri/examples/examples_merge_from_raw_files_using_rawpy.ipynb

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

42 changes: 40 additions & 2 deletions colour_hdri/generation/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
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 .weighting_functions import (
normal_distribution_function,
hat_function,
weighting_function_Debevec1997,
)
from .radiance import image_stack_to_radiance_image
from .hdri import image_stack_to_HDRI

__all__ = []
__all__ += [
Expand All @@ -12,5 +19,36 @@
"weighting_function_Debevec1997",
]
__all__ += [
"image_stack_to_radiance_image",
"image_stack_to_HDRI",
]


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

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

return super().__getattr__(attribute)


# v0.2.1
API_CHANGES = {
"ObjectRenamed": [
[
"colour_hdri.generation.image_stack_to_radiance_image",
"colour_hdri.generation.image_stack_to_HDRI",
],
]
}
"""Defines the *colour_hdri.generation* sub-package API changes."""

if not is_documentation_building():
sys.modules["colour_hdri.generation"] = generation( # type: ignore[assignment]
sys.modules["colour_hdri.generation"], build_API_changes(API_CHANGES)
)

del ModuleAPI, is_documentation_building, build_API_changes, sys
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""
HDRI / Radiance Image Generation
================================
HDRI Generation
===============
Defines the HDRI / radiance image generation objects:
Defines the HDRI generation objects:
- :func:`colour_hdri.image_stack_to_radiance_image`
- :func:`colour_hdri.image_stack_to_HDRI`
See Also
--------
Expand Down Expand Up @@ -39,17 +39,17 @@
__status__ = "Production"

__all__ = [
"image_stack_to_radiance_image",
"image_stack_to_HDRI",
]


def image_stack_to_radiance_image(
def image_stack_to_HDRI(
image_stack: ImageStack,
weighting_function: Callable = weighting_function_Debevec1997,
camera_response_functions: Optional[ArrayLike] = None,
) -> Optional[NDArray]:
"""
Generate a HDRI / radiance image from given image stack.
Generate a HDRI from given image stack.
Parameters
----------
Expand All @@ -66,7 +66,7 @@ def image_stack_to_radiance_image(
Returns
-------
:class:`numpy.ndarray`
Radiance image.
HDRI.
Warnings
--------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from colour.hints import List

from colour_hdri import TESTS_RESOURCES_DIRECTORY
from colour_hdri.generation import image_stack_to_radiance_image
from colour_hdri.generation import image_stack_to_HDRI
from colour_hdri.calibration import camera_response_functions_Debevec1997
from colour_hdri.utilities import ImageStack, filter_files

Expand All @@ -26,7 +26,7 @@
"FROBISHER_001_DIRECTORY",
"GENERATION_DIRECTORY",
"JPG_IMAGES",
"TestRadianceImage",
"TestImageStackToHDRI",
]

FROBISHER_001_DIRECTORY: str = os.path.join(
Expand All @@ -40,16 +40,16 @@
JPG_IMAGES: List[str] = filter_files(FROBISHER_001_DIRECTORY, ("jpg",))


class TestRadianceImage(unittest.TestCase):
class TestImageStackToHDRI(unittest.TestCase):
"""
Define :func:`colour_hdri.generation.radiance.\
image_stack_to_radiance_image` definition unit tests methods.
Define :func:`colour_hdri.generation.radiance.image_stack_to_HDRI`
definition unit tests methods.
"""

def test_radiance_image(self):
def test_image_stack_to_HDRI(self):
"""
Test :func:`colour_hdri.generation.\
radiance.image_stack_to_radiance_image` definition.
Test :func:`colour_hdri.generation.radiance.image_stack_to_HDRI`
definition.
"""

image_stack = ImageStack.from_files(JPG_IMAGES)
Expand All @@ -59,10 +59,10 @@ def test_radiance_image(self):

# Lower precision for unit tests under *travis-ci*.
np.testing.assert_allclose(
image_stack_to_radiance_image(image_stack),
image_stack_to_HDRI(image_stack),
np.load(
os.path.join(
GENERATION_DIRECTORY, "test_radiance_image_linear.npy"
GENERATION_DIRECTORY, "test_image_stack_to_hdri_linear.npy"
)
),
rtol=0.0001,
Expand All @@ -72,15 +72,15 @@ def test_radiance_image(self):
# Lower precision for unit tests under *travis-ci*.
image_stack = ImageStack.from_files(JPG_IMAGES)
np.testing.assert_allclose(
image_stack_to_radiance_image(
image_stack_to_HDRI(
image_stack,
camera_response_functions=(
camera_response_functions_Debevec1997(image_stack)
),
),
np.load(
os.path.join(
GENERATION_DIRECTORY, "test_radiance_image_crfs.npy"
GENERATION_DIRECTORY, "test_image_stack_to_hdri_crfs.npy"
)
),
rtol=0.0001,
Expand Down
2 changes: 1 addition & 1 deletion colour_hdri/generation/weighting_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Weighting Functions
===================
Defines the weighting function objects used when generating radiance images:
Defines the weighting function objects used when generating HDRIs:
- :func:`colour_hdri.normal_distribution_function`
- :func:`colour_hdri.hat_function`
Expand Down
2 changes: 1 addition & 1 deletion colour_hdri/models/rgb.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def camera_space_to_RGB(

M_RGB_camera = matrix_dot(M_XYZ_to_camera_space, matrix_RGB_to_XYZ)

M_RGB_camera /= np.transpose(np.sum(M_RGB_camera, axis=1)[np.newaxis])
M_RGB_camera /= np.transpose(np.sum(M_RGB_camera, axis=1)[None])

RGB_f = vector_dot(np.linalg.inv(M_RGB_camera), RGB)

Expand Down
4 changes: 2 additions & 2 deletions colour_hdri/plotting/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from .radiance import plot_radiance_image_strip
from .hdri import plot_HDRI_strip
from .tonemapping import plot_tonemapping_operator_image

__all__ = []
__all__ += [
"plot_radiance_image_strip",
"plot_HDRI_strip",
]
__all__ += [
"plot_tonemapping_operator_image",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""
HDRI / Radiance Image Plotting
==============================
HDRI Plotting
===================
Defines the HDRI / radiance image plotting objects:
Defines the HDRI plotting objects:
- :func:`colour_hdri.plotting.plot_radiance_image_strip`
- :func:`colour_hdri.plotting.plot_HDRI_strip`
"""

from __future__ import annotations
Expand All @@ -27,25 +27,25 @@
__status__ = "Production"

__all__ = [
"plot_radiance_image_strip",
"plot_HDRI_strip",
]


@override_style()
def plot_radiance_image_strip(
def plot_HDRI_strip(
image: ArrayLike,
count: Integer = 5,
ev_steps: Floating = -2,
cctf_encoding: Callable = CONSTANTS_COLOUR_STYLE.colour.colourspace.cctf_encoding,
**kwargs: Any,
) -> Tuple[plt.Figure, plt.Axes]:
"""
Plot given HDRI / radiance image as strip of images of varying exposure.
Plot given HDRI as strip of images of varying exposure.
Parameters
----------
image
HDRI / radiance image to plot.
HDRI to plot.
count
Strip images count.
ev_steps
Expand Down
2 changes: 1 addition & 1 deletion colour_hdri/recovery/highlights.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def highlights_recovery_blend(
ratio = np.sqrt(s_c / s)
ratio[np.logical_or(np.isnan(ratio), np.isinf(ratio))] = 1

Lab[:, :, 1:3] *= np.rollaxis(ratio[np.newaxis], 0, 3)
Lab[:, :, 1:3] *= np.rollaxis(ratio[None], 0, 3)

RGB_o = vector_dot(np.linalg.inv(M), Lab)

Expand Down
Loading

0 comments on commit d1d84d2

Please sign in to comment.